Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

max32630-fthr-mbed: developing bstack mbed support #76

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions port/max32630-fthr-mbed/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.swp
.*.sw[op]
*~
*.o
*.a
*.xml
*.d
*.map
*.elf
build/
GPATH
GRTAGS
GTAGS
tags
*.txt
*.log
core
520 changes: 520 additions & 0 deletions port/max32630-fthr-mbed/Makefile

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions port/max32630-fthr-mbed/Makefile.old
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.phony: examples
all: examples

examples:
scripts/create_examples.py

clean:
scripts/delete_examples.py
@rm -rf example/Makefile
@echo "Deleting CC2564B Init Script in src folder"
@rm -rf src/cc256x* bluetooth_init*
75 changes: 75 additions & 0 deletions port/max32630-fthr-mbed/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# BTStack Max32630 MBED notes

Please note that the development is not completed yet. MBED related initializetion fails.

Makefile is autogenerated and then included max32630fthr-mbed.mk file to in order to do minimal changes in the generated Makefile.

Download library source code from mbed repository
$ mbed deploy

Build the source code
$ make

Build mbed code withing the folder. Please note that the following command does build source code in max32630-fthr-mbed directory only, does not build btstack.
$ mbed compile -m MAX32630FTHR -t GCC_ARM


-----------------------------------------------------------------------------

# BTstack Port for the Maxim MAX32630FTHR ARM Cortex-M4F

This port uses the [MAX32630FTHR ARM Cortex M4F Board](https://www.maximintegrated.com/en/products/digital/microcontrollers/MAX32630FTHR.html) with the onboard TI CC2564B Bluetooth controller. It usually comes with the [DAPLINK Programming Adapter](https://developer.mbed.org/teams/MaximIntegrated/wiki/MAXREFDES100HDK).
The DAPLINK allows to upload firmware via a virtual mass storage device (like mbed), provides a virtual COM port for a console, and enables debugging via the SWD interface via OpenOCD.

The port uses non-blocking polling UART communication with hardware flow control for Bluetooth controller. It was tested and achieved up to 1.8 Mbps bandwidth between two Max32630FTHR boards.

## Software

The [Maxim ARM Toolchain](https://www.maximintegrated.com/en/products/digital/microcontrollers/MAX32630.html/tb_tab2) is free software that provides peripheral libraries, linker files, initial code and some board files. It also provides Eclipse Neon and Maxim modified OpenOCD to program the microcontroller together with various examples for Maxim Cortex M4F ARM processors.

For debugging, OpenOCD can be used. The regular OpenOCD does not support Maxim ARM microcontrollers yet, but a modified OpenOCD for use with Maxim devices can be found in the Maxim ARM Toolchain.

## Toolchain Setup

In the Maxim Toolchain installation directory, there is a setenv.sh file that sets the MAXIM_PATH. MAXIM_PATH needs to point to the root directory where the tool chain installed. If you're lucky and have a compatible ARM GCC Toolchain in your PATH, it might work without calling setenv.sh script.

## Usage

The examples can be compiled using GNU ARM Toolchain. A firmware binary can be flashed either by copying the .bin file to the DAPLINK mass storage drive, or by using OpenOCD on the command line, or from Eclipse CDT.

## Build

Checkt that MAXIM_PATH points to the root directory where the tool chain installed.
Then, go to the port/max32630-fthr folder and run "make" command in terminal to generate example projects in the example folder.

In each example folder, e.g. port/max323630-fthr/example/spp_and_le_streamer, you can run "make" again to build an .elf file in the build folder which is convenient for debugging using Eclipse or GDB.

For flashing via the virtual USB drive, the "make release" command will generate .bin file in the build folder.

## Eclipse

Toolchain and Eclipse guide can be found in README.pdf file where the Maxim Toolchain is installed. Please note that this port was done using Makefiles.

## Flashing Max32630 ARM Processor

There are two ways to program the board. The simplest way is drag and drop the generated .bin file to the DAPLINK mass storage drive. Once the file is copied to the mass storage device, the DAPLINK should program and then run the new firmware.

Alternatively, OpenOCD can be used to flash and debug the device. A suitable programming script can be found in the scripts folder.

## Debugging

OpenOCD can also be used for developing and especially for debugging. Eclipse or GDB via OpenOCD could be used for step by step debugging.

## Debug output

printf messages are redirected to UART2. UART2 is accessible via the DAPLINK Programming Adapter as a virtual COM port at 115200 baud with no flow control. If this doesn't work for you, you can connect P3_1 (UART TX) of the MAX32630FTHR board to a USB-to-UART adapter.

Additional debug information can be enabled by uncommenting ENABLE_LOG_INFO in the src/btstack_config.h header file and a clean rebuild.

## TODOs
- Support for BTSTACK_STDIN
- Add flash-openocd to Makefile template
- Implement BTstack Flash interface to support link key storage in flash memory.
- Add Eclipse CDT projects for max32630fthr
- Implement hal_led.h to control LED on board

1 change: 1 addition & 0 deletions port/max32630-fthr-mbed/USBDevice.lib
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://developer.mbed.org/teams/MaximIntegrated/code/USBDevice/#c5e178adb138
88 changes: 88 additions & 0 deletions port/max32630-fthr-mbed/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*******************************************************************************
* Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
* Author: Ismail H. Kose <[email protected]>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Maxim Integrated
* Products, Inc. shall not be used except as stated in the Maxim Integrated
* Products, Inc. Branding Policy.
*
* The mere transfer of this software does not imply any licenses
* of trade secrets, proprietary technology, copyrights, patents,
* trademarks, maskwork rights, or any other form of intellectual
* property whatsoever. Maxim Integrated Products, Inc. retains all
* ownership rights.
*
******************************************************************************/

/**
* @file main.c
* @brief Max32630 CC2564B btstack Example
*/

#include "mbed.h"
#include "max32630fthr.h"
#include "USBSerial.h"
#include "btstack_config.h"
#include "btstack_port.h"
#include "btstack.h"

MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3);

// Hardware serial port over DAPLink
//Serial daplink(P2_1, P2_0, 115200);

// Virtual serial port over USB
//USBSerial microUSB;

DigitalOut rLED(LED1);
DigitalOut gLED(LED2);
DigitalOut bLED(LED3);

// main() runs in its own thread in the OS
// (note the calls to Thread::wait below for delays)
int main()
{
int c;

printf("max32630fthr btstack example\r\n");
// daplink.printf("max32630fthr btstack - daplink serial port\r\n");
//microUSB.printf("max32630fthr btstack example on micro USB serial port\r\n");
rLED = LED_ON;
gLED = LED_ON;
bLED = LED_OFF;

rLED = LED_OFF;
printf("%s:%d - \r\n", __func__, __LINE__);
bluetooth_main();

printf("###### %s:%d - \r\n", __func__, __LINE__);
while(1);

while(1) {
// c = microUSB.getc();
// microUSB.putc(c);
//daplink.putc(c);
//bLED = c & 1;
hal_btstack_run_loop_execute_once();
printf("%s:%d - \r\n", __func__, __LINE__);
}
}

68 changes: 68 additions & 0 deletions port/max32630-fthr-mbed/max32630fthr-mbed.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
BTSTACK_ROOT = ./

VPATH += .
VPATH += $(abspath ../../../../btstack)

BTSTACK_CORE_OBJ = \
$(BTSTACK_ROOT)/src/ad_parser.o \
$(BTSTACK_ROOT)/src/btstack_linked_list.o \
$(BTSTACK_ROOT)/src/btstack_memory.o \
$(BTSTACK_ROOT)/src/btstack_memory_pool.o \
$(BTSTACK_ROOT)/src/btstack_run_loop.o \
$(BTSTACK_ROOT)/src/btstack_util.o \
$(BTSTACK_ROOT)/src/l2cap.o \
$(BTSTACK_ROOT)/src/hci_transport_h4.o \
$(BTSTACK_ROOT)/src/l2cap_signaling.o \
$(BTSTACK_ROOT)/platform/embedded/btstack_run_loop_embedded.o \
src/initscripts-TIInit_6.7.16_bt_spec_4.1.o \
src/btstack_port.o \
src/hal_tick.o \
src/spp_counter.o

BTSTACK_COMMON_OBJ = \
$(BTSTACK_ROOT)/chipset/cc256x/btstack_chipset_cc256x.o \
$(BTSTACK_ROOT)/src/hci.o \
$(BTSTACK_ROOT)/src/hci_cmd.o \
$(BTSTACK_ROOT)/src/hci_dump.o \
$(BTSTACK_ROOT)/platform/embedded/btstack_uart_block_embedded.o

BTSTACK_CLASSIC_OBJ = \
$(BTSTACK_ROOT)/src/classic/rfcomm.o \
$(BTSTACK_ROOT)/src/classic/sdp_util.o \
$(BTSTACK_ROOT)/src/classic/spp_server.o \
$(BTSTACK_ROOT)/src/classic/sdp_server.o \
$(BTSTACK_ROOT)/src/classic/sdp_client.o \
$(BTSTACK_ROOT)/src/classic/sdp_client_rfcomm.o

BTSTACK_BLE_OBJ = \
$(BTSTACK_ROOT)/src/ble/att_db.o \
$(BTSTACK_ROOT)/src/ble/att_server.o \
$(BTSTACK_ROOT)/src/ble/le_device_db_memory.o \
$(BTSTACK_ROOT)/src/ble/att_dispatch.o \
$(BTSTACK_ROOT)/src/ble/sm.o


BTSTACK_OBJ = $(BTSTACK_CORE_OBJ)
BTSTACK_OBJ += $(BTSTACK_COMMON_OBJ)
BTSTACK_OBJ += $(BTSTACK_CLASSIC_OBJ)
BTSTACK_OBJ += $(BTSTACK_BLE_OBJ)

OBJECTS += $(BTSTACK_OBJ)

BTSTACK_INC_ROOT = ../../..

INCLUDE_PATHS += $(BTSTACK_INC)
INCLUDE_PATHS += \
-I$(BTSTACK_INC_ROOT)/src \
-I$(BTSTACK_INC_ROOT)/src/ble \
-I$(BTSTACK_INC_ROOT)/src/classic \
-I$(BTSTACK_INC_ROOT)/chipset/cc256x \
-I$(BTSTACK_INC_ROOT)/platform/embedded \
-I${BTSTACK_INC_ROOT}/src/ble/gatt-service/ \
-I${BTSTACK_INC_ROOT}/port/max32630-fthr-mbed/ \
-I${BTSTACK_INC_ROOT}/port/max32630-fthr-mbed/src

C_FLAGS += -g3 -ggdb -DDEBUG
C_FLAGS += -g3 -ggdb -D__STACK_SIZE=0X30000
CXX_FLAGS += -g3 -ggdb -DDEBUG

1 change: 1 addition & 0 deletions port/max32630-fthr-mbed/max32630fthr.lib
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
http://developer.mbed.org/teams/MaximIntegrated/code/max32630fthr/#60997adf01a2
1 change: 1 addition & 0 deletions port/max32630-fthr-mbed/mbed-os.lib
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/ARMmbed/mbed-os/#269f58d75b752a4e67a6a2d8c5c698635ffd6752
18 changes: 18 additions & 0 deletions port/max32630-fthr-mbed/mbed_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Automatically generated configuration file.
// DO NOT EDIT, content will be overwritten.

#ifndef __MBED_CONFIG_DATA__
#define __MBED_CONFIG_DATA__

// Configuration parameters
#define MBED_CONF_EVENTS_PRESENT 1 // set by library:events
#define MBED_CONF_RTOS_PRESENT 1 // set by library:rtos
#define MBED_CONF_PLATFORM_STDIO_BAUD_RATE 115200 // set by library:platform
#define MBED_CONF_NSAPI_PRESENT 1 // set by library:nsapi
#define MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE 115200 // set by library:platform
#define MBED_CONF_PLATFORM_STDIO_FLUSH_AT_EXIT 1 // set by library:platform
#define MBED_CONF_PLATFORM_STDIO_CONVERT_NEWLINES 1 // set by library:platform
// Macros
#define UNITY_INCLUDE_CONFIG_H // defined by library:utest

#endif
101 changes: 101 additions & 0 deletions port/max32630-fthr-mbed/scripts/create_examples.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#!/usr/bin/env python
#
# Create project files for all BTstack embedded examples in WICED/apps/btstack

import os
import re
import shutil
import subprocess
import sys

# build all template
build_all = '''
SUBDIRS = \\
%s

all:
\techo Building all examples
\tfor dir in $(SUBDIRS); do \\
\t$(MAKE) -C $$dir || exit 1; \\
\tdone

clean:
\techo Cleaning all ports
\tfor dir in $(SUBDIRS); do \\
\t$(MAKE) -C $$dir clean; \\
\tdone
'''

# get script path
script_path = os.path.abspath(os.path.dirname(sys.argv[0])) + '/../'

# get btstack root
btstack_root = script_path + '../../'

## pick correct init script based on your hardware
# - init script for CC2564B
cc256x_init_script = 'bluetooth_init_cc2564B_1.6_BT_Spec_4.1.c'

subprocess.call("make -f ../Makefile -C src " + cc256x_init_script, shell=True)

# fetch init script
# print("Creating init script %s" % cc256x_init_script)
# make_template = 'make -f {BTSTACK_ROOT}chipset/cc256x/Makefile.inc -C {SCRIPT_PATH}src/ {INIT_SCRIPT} BTSTACK_ROOT={BTSTACK_ROOT}'
# make_command = make_template.format(BTSTACK_ROOT=btstack_root, SCRIPT_PATH=script_path, INIT_SCRIPT=cc256x_init_script)
# print(make_command)
# subprocess.call(make_command)

# path to examples
examples_embedded = btstack_root + 'example/'

# path to generated example projects
projects_path = script_path + "example/"

# path to template
template_path = script_path + 'example/template/Makefile'

print("Creating example projects:")

# iterate over btstack examples
example_files = os.listdir(examples_embedded)

examples = []

for file in example_files:
if not file.endswith(".c"):
continue
if file in ['panu_demo.c', 'sco_demo_util.c']:
continue
example = file[:-2]
examples.append(example)

# create folder
project_folder = projects_path + example + "/"
if not os.path.exists(project_folder):
os.makedirs(project_folder)

# check if .gatt file is present
gatt_path = examples_embedded + example + ".gatt"
gatt_h = ""
if os.path.exists(gatt_path):
gatt_h = example+'.h'

# create makefile
with open(project_folder + 'Makefile', 'wt') as fout:
with open(template_path, 'rt') as fin:
for line in fin:
if 'PROJECT=spp_and_le_streamer' in line:
fout.write('PROJECT=%s\n' % example)
continue
if 'all: spp_and_le_streamer.h' in line:
if len(gatt_h):
fout.write("all: %s\n" % gatt_h)
continue
fout.write(line)

print("- %s" % example)

with open(projects_path+'Makefile', 'wt') as fout:
fout.write(build_all % ' \\\n'.join(examples))

print("Projects are ready for compile in example folder. See README for details.")
Loading