From 28c4b3f5b1842882ea89262b7dc88c0e1b2af49a Mon Sep 17 00:00:00 2001 From: Hudson Date: Sat, 18 Jul 2020 21:45:35 -0600 Subject: [PATCH 1/6] Add makefile switch for dual and BLE softdevices --- Makefile | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Makefile b/Makefile index 89e65140..2eeb9345 100644 --- a/Makefile +++ b/Makefile @@ -71,6 +71,25 @@ ifeq ($(filter $(BOARD),$(BOARD_LIST)),) $(error Invalid BOARD specified) endif +#--------------------------------- +# Select the supported protocols +#--------------------------------- +ifeq ($(PROTOCOL),BOTH) + $(info Build specified supporting both ANT and BLE) + $(warning Ensure you download a dualstack softdevice from thisisant.com) + $(warning Make sure to compile against the dualstack softdevice headers) +else ifeq ($(PROTOCOL),BLE) + $(info Build specified supporting only BLE) + $(warning Make sure to compile against the BLE softdevice headers) +else + $(error Invalid protocol supported. Supported protocols are: BLE BOTH) + $(info BLE: Select for S1xx softdevices. You will need to compile against the S1xx headers) + $(info BOTH: Select for S3xx softdevices. You will need to compile against the S3xx headers) +endif + +# Append the selected protocol to the compile flags +CFLAGS += -D$(PROTOCOL) + # Build directory BUILD = _build/build-$(BOARD) From c9dab78269b3ae6fb70c34334e4fee870d44bfd1 Mon Sep 17 00:00:00 2001 From: Hudson Date: Sat, 18 Jul 2020 21:49:41 -0600 Subject: [PATCH 2/6] Add dualstack softdevice support - Allows dualstack softdevices to use the bootloader properly (OTA updates, serial updates) - Users must obtain softdevice headers from the appropriate package at thisisant.com and must build against those headers --- src/main.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main.c b/src/main.c index cf05c1af..18c9b8ca 100644 --- a/src/main.c +++ b/src/main.c @@ -328,7 +328,13 @@ static uint32_t softdev_init(bool init_softdevice) .accuracy = NRF_CLOCK_LF_ACCURACY_250_PPM }; +#ifdef BLE APP_ERROR_CHECK( sd_softdevice_enable(&clock_cfg, app_error_fault_handler) ); +#elif defined(BOTH) + APP_ERROR_CHECK( sd_softdevice_enable(&clock_cfg, app_error_fault_handler, ANT_LICENSE_KEY ) ); +#else + #error "No valid protocol was selected" +#endif // BLE sd_nvic_EnableIRQ(SD_EVT_IRQn); /*------------- Configure BLE params -------------*/ From 82fbf551bfa2909a6223689b555aa150873a33dd Mon Sep 17 00:00:00 2001 From: Hudson Date: Sat, 18 Jul 2020 21:53:03 -0600 Subject: [PATCH 3/6] Automatically select the correct softdevice name Select the correct softdevice name for each protocol for each SoC --- Makefile | 30 +++++++++++++++++----- lib/softdevice/s332_nrf52_6.1.1/README.txt | 1 + lib/softdevice/s340_nrf52_6.1.1/README.txt | 1 + 3 files changed, 26 insertions(+), 6 deletions(-) create mode 100644 lib/softdevice/s332_nrf52_6.1.1/README.txt create mode 100644 lib/softdevice/s340_nrf52_6.1.1/README.txt diff --git a/Makefile b/Makefile index 2eeb9345..7f0e7b9f 100644 --- a/Makefile +++ b/Makefile @@ -98,17 +98,35 @@ BUILD = _build/build-$(BOARD) # MCU_SUB_VARIANT can be nrf52 (nrf52832), nrf52833, nrf52840 ifeq ($(MCU_SUB_VARIANT),nrf52) - SD_NAME = s132 + ifeq ($(PROTOCOL),BLE) + SD_NAME = s132 + CFLAGS += -DS132 + else + SD_NAME = s332 + CFLAGS += -DS332 + endif DFU_DEV_REV = 0xADAF - CFLAGS += -DNRF52 -DNRF52832_XXAA -DS132 + CFLAGS += -DNRF52 -DNRF52832_XXAA else ifeq ($(MCU_SUB_VARIANT),nrf52833) - SD_NAME = s140 + ifeq ($(PROTOCOL),BLE) + SD_NAME = s140 + CFLAGS += -DS140 + else + SD_NAME = s340 + CFLAGS += -DS340 + endif DFU_DEV_REV = 52840 - CFLAGS += -DNRF52833_XXAA -DS140 + CFLAGS += -DNRF52833_XXAA else ifeq ($(MCU_SUB_VARIANT),nrf52840) - SD_NAME = s140 + ifeq ($(PROTOCOL),BLE) + SD_NAME = s140 + CFLAGS += -DS140 + else + SD_NAME = s340 + CFLAGS += -DS340 + endif DFU_DEV_REV = 52840 - CFLAGS += -DNRF52840_XXAA -DS140 + CFLAGS += -DNRF52840_XXAA else $(error Sub Variant $(MCU_SUB_VARIANT) is unknown) endif diff --git a/lib/softdevice/s332_nrf52_6.1.1/README.txt b/lib/softdevice/s332_nrf52_6.1.1/README.txt new file mode 100644 index 00000000..bb4bec19 --- /dev/null +++ b/lib/softdevice/s332_nrf52_6.1.1/README.txt @@ -0,0 +1 @@ +Obtain the 6.1.1 s332 softdevice from thisisant.com and place the API folder and softdevice hex here. \ No newline at end of file diff --git a/lib/softdevice/s340_nrf52_6.1.1/README.txt b/lib/softdevice/s340_nrf52_6.1.1/README.txt new file mode 100644 index 00000000..fb0f5a0a --- /dev/null +++ b/lib/softdevice/s340_nrf52_6.1.1/README.txt @@ -0,0 +1 @@ +Obtain the 6.1.1 s340 softdevice from thisisant.com and place the API folder and softdevice hex here. \ No newline at end of file From 57c4848919cad181fe961198d8d19d1954741e26 Mon Sep 17 00:00:00 2001 From: Hudson Date: Sat, 18 Jul 2020 21:55:07 -0600 Subject: [PATCH 4/6] Update README for dualstack softdevices --- README.md | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 0a86a9d3..5d1a0352 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ For other boards, please check the board definition for details. ### Making your own UF2 -To create your own UF2 DFU update image, simply use the [Python conversion script](https://github.com/Microsoft/uf2/blob/master/utils/uf2conv.py) on a .bin file or .hex file, specifying the family as **0xADA52840**. If using a .bin file with the conversion script you must specify application address with the -b switch, this address depend on the SoftDevice size/version e.g S140 v6 is 0x26000 +To create your own UF2 DFU update image, simply use the [Python conversion script](https://github.com/Microsoft/uf2/blob/master/utils/uf2conv.py) on a .bin file or .hex file, specifying the family as **0xADA52840**. If using a .bin file with the conversion script you must specify application address with the -b switch, this address depend on the SoftDevice size/version e.g S140 v6 is 0x26000 To create a UF2 image from a .bin file: ``` @@ -109,25 +109,25 @@ Prerequisites To build: ``` -make BOARD=feather_nrf52840_express all +make BOARD=feather_nrf52840_express PROTOCOL=BLE all ``` To flash the bootloader with JLink: ``` -make BOARD=feather_nrf52840_express flash +make BOARD=feather_nrf52840_express PROTOCOL=BLE flash ``` To upgrade the bootloader using DFU Serial via port /dev/ttyACM0 ``` -make BOARD=feather_nrf52840_express SERIAL=/dev/ttyACM0 dfu-flash +make BOARD=feather_nrf52840_express SERIAL=/dev/ttyACM0 PROTOCOL=BLE dfu-flash ``` To flash SoftDevice (and chip erase): ``` -make BOARD=feather_nrf52840_express sd +make BOARD=feather_nrf52840_express PROTOCOL=BLE sd ``` For the list of supported boards, run `make` without `BOARD=` : @@ -139,6 +139,26 @@ Supported boards are: feather_nrf52840_express feather_nrf52840_express pca10056 Makefile:90: *** BOARD not defined. Stop ``` +The supported protocols are currently BLE and BOTH (ANT + BLE). + +### Building with an ANT softdevice + +Currently, the bootloader can be built against the dualstack softdevice headers for +use of both ANT and BLE simultaneously. To do this: + +1. Download either s332 or s340 from thisisant.com. Note that this softdevice is + freely available for evaluation use only. Garmin Canada must be contacted to obtain + ANT licenses for commercial use. +2. Place the contents of the softdevice package in the appropriate lib/softdevice folder. +3. Rename the API folder to _nrf52_6.1.1_API. +4. Rename the softdevice hex to _nrf52_6.1.1_softdevice.hex. +5. When building make sure to set PROTOCOL=BOTH + +All bootloader features available in the single-stack BLE softdevice are also available in the +dualstack softdevice, including OTA-DFU updates using BLE. + +Note that single stack ANT softdevices are not currently supported (s2xx series softdevices). + ### Common makefile problems #### 1. `arm-none-eabi-gcc`: No such file or directory @@ -146,7 +166,7 @@ Makefile:90: *** BOARD not defined. Stop If you get the following error ... ``` -$ make BOARD=feather_nrf52840_express all +$ make BOARD=feather_nrf52840_express all Compiling file: main.c /bin/sh: /usr/bin/arm-none-eabi-gcc: No such file or directory make: *** [_build/main.o] Error 127 From 7b597a7e05a761e6bf86ff1a27209da199cf5974 Mon Sep 17 00:00:00 2001 From: Hudson Date: Sat, 18 Jul 2020 21:55:48 -0600 Subject: [PATCH 5/6] Fix printf typo --- src/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index 18c9b8ca..a1ee2407 100644 --- a/src/main.c +++ b/src/main.c @@ -155,7 +155,7 @@ void softdev_mbr_init(void) //--------------------------------------------------------------------+ int main(void) { - PRINTF("Bootlaoder Start\r\n"); + PRINTF("Bootloader Start\r\n"); // Populate Boot Address and MBR Param into MBR if not already // MBR_BOOTLOADER_ADDR/MBR_PARAM_PAGE_ADDR are used if available, else UICR registers are used From 0c95fd1927878fe0e07da01084feb5a28ed36983 Mon Sep 17 00:00:00 2001 From: Hudson Date: Fri, 24 Jul 2020 13:15:32 -0600 Subject: [PATCH 6/6] Update to use SD= instead of PROTOCOL= in makefile --- Makefile | 109 ++++++++++++++++++++++++++++++------------------------ README.md | 10 ++--- 2 files changed, 66 insertions(+), 53 deletions(-) diff --git a/Makefile b/Makefile index 7f0e7b9f..72e8807a 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ # CONFIGURE # - SDK_PATH : path to SDK directory # -# - SD_NAME : e.g s132, s140 +# - SD : e.g s132, s140 # - SD_VERSION : SoftDevice version e.g 6.0.0 # - SD_HEX : to bootloader hex binary #------------------------------------------------------------------------------ @@ -14,7 +14,7 @@ NRFX_PATH = lib/nrfx SD_PATH = lib/softdevice/$(SD_FILENAME) SD_VERSION = 6.1.1 -SD_FILENAME = $(SD_NAME)_nrf52_$(SD_VERSION) +SD_FILENAME = $(SD)_nrf52_$(SD_VERSION) SD_HEX = $(SD_PATH)/$(SD_FILENAME)_softdevice.hex MBR_HEX = lib/softdevice/mbr/hex/mbr_nrf52_2.4.1_mbr.hex @@ -29,7 +29,7 @@ GIT_SUBMODULE_VERSIONS != git submodule status | cut -d" " -f3,4 | paste -s -d" OUT_FILE = $(BOARD)_bootloader-$(GIT_VERSION) # merged file = compiled + sd -MERGED_FILE = $(OUT_FILE)_$(SD_NAME)_$(SD_VERSION) +MERGED_FILE = $(OUT_FILE)_$(SD)_$(SD_VERSION) #------------------------------------------------------------------------------ # Tool configure @@ -71,64 +71,77 @@ ifeq ($(filter $(BOARD),$(BOARD_LIST)),) $(error Invalid BOARD specified) endif -#--------------------------------- -# Select the supported protocols -#--------------------------------- -ifeq ($(PROTOCOL),BOTH) - $(info Build specified supporting both ANT and BLE) - $(warning Ensure you download a dualstack softdevice from thisisant.com) - $(warning Make sure to compile against the dualstack softdevice headers) -else ifeq ($(PROTOCOL),BLE) - $(info Build specified supporting only BLE) - $(warning Make sure to compile against the BLE softdevice headers) -else - $(error Invalid protocol supported. Supported protocols are: BLE BOTH) - $(info BLE: Select for S1xx softdevices. You will need to compile against the S1xx headers) - $(info BOTH: Select for S3xx softdevices. You will need to compile against the S3xx headers) -endif - -# Append the selected protocol to the compile flags -CFLAGS += -D$(PROTOCOL) - # Build directory BUILD = _build/build-$(BOARD) # Board specific -include src/boards/$(BOARD)/board.mk -# MCU_SUB_VARIANT can be nrf52 (nrf52832), nrf52833, nrf52840 -ifeq ($(MCU_SUB_VARIANT),nrf52) - ifeq ($(PROTOCOL),BLE) - SD_NAME = s132 - CFLAGS += -DS132 +#--------------------------------- +# Select the softdevice to build for +#--------------------------------- +ifeq ($(SD),s140) + CFLAGS += -DS140 -DBLE + DFU_DEV_REV = 52840 + ifeq ($(MCU_SUB_VARIANT),nrf52833) + CFLAGS += -DNRF52833_XXAA + else ifeq ($(MCU_SUB_VARIANT),nrf52840) + CFLAGS += -DNRF52840_XXAA else - SD_NAME = s332 - CFLAGS += -DS332 + $(error Sub Variant $(MCU_SUB_VARIANT) is invalid for softdevice $(SD)) endif +else ifeq ($(SD),s340) + $(info Build specified supporting both ANT and BLE) + $(warning Ensure you download a dualstack softdevice from thisisant.com) + $(warning Make sure to compile against the dualstack softdevice headers) + CFLAGS += -DS340 -DBOTH + DFU_DEV_REV = 52840 + ifeq ($(MCU_SUB_VARIANT),nrf52833) + CFLAGS += -DNRF52833_XXAA + else ifeq ($(MCU_SUB_VARIANT),nrf52840) + CFLAGS += -DNRF52840_XXAA + else + $(error Sub Variant $(MCU_SUB_VARIANT) is invalid for softdevice $(SD)) + endif +else ifeq ($(SD),s132) + CFLAGS += -DS132 -DBLE DFU_DEV_REV = 0xADAF - CFLAGS += -DNRF52 -DNRF52832_XXAA -else ifeq ($(MCU_SUB_VARIANT),nrf52833) - ifeq ($(PROTOCOL),BLE) - SD_NAME = s140 - CFLAGS += -DS140 + ifeq ($(MCU_SUB_VARIANT),nrf52) + CFLAGS += -DNRF52832_XXAA else - SD_NAME = s340 - CFLAGS += -DS340 + $(error Sub Variant $(MCU_SUB_VARIANT) is invalid for softdevice $(SD)) endif - DFU_DEV_REV = 52840 - CFLAGS += -DNRF52833_XXAA -else ifeq ($(MCU_SUB_VARIANT),nrf52840) - ifeq ($(PROTOCOL),BLE) - SD_NAME = s140 - CFLAGS += -DS140 +else ifeq ($SD, s332) + $(info Build specified supporting both ANT and BLE) + $(warning Ensure you download a dualstack softdevice from thisisant.com) + $(warning Make sure to compile against the dualstack softdevice headers) + CFLAGS += -DS332 -DBOTH + DFU_DEV_REV = 0xADAF + ifeq ($(MCU_SUB_VARIANT),nrf52) + CFLAGS += -DNRF52832_XXAA else - SD_NAME = s340 - CFLAGS += -DS340 + $(error Sub Variant $(MCU_SUB_VARIANT) is invalid for softdevice $(SD)) + endif +else ifeq ($SD,) + # SD not specified, default to BLE SDs + ifeq ($(MCU_SUB_VARIANT),nrf52) + SD = s132 + DFU_DEV_REV = 0xADAF + CFLAGS += -DNRF52 -DNRF52832_XXAA -DS132 -DBLE + else ifeq ($(MCU_SUB_VARIANT),nrf52833) + SD = s140 + DFU_DEV_REV = 52840 + CFLAGS += -DNRF52833_XXAA -DS140 -DBLE + else ifeq ($(MCU_SUB_VARIANT),nrf52840) + SD = s140 + DFU_DEV_REV = 52840 + CFLAGS += -DNRF52840_XXAA -DS140 -DBLE + else + $(error Sub Variant $(MCU_SUB_VARIANT) is unknown) endif - DFU_DEV_REV = 52840 - CFLAGS += -DNRF52840_XXAA else - $(error Sub Variant $(MCU_SUB_VARIANT) is unknown) + # Invalid SD was specified + $(error softdevice $(SD) is unknown) endif #------------------------------------------------------------------------------ @@ -298,7 +311,7 @@ CFLAGS += -DSOFTDEVICE_PRESENT CFLAGS += -DDFU_APP_DATA_RESERVED=7*4096 CFLAGS += -DUF2_VERSION='"$(GIT_VERSION) $(GIT_SUBMODULE_VERSIONS)"' -CFLAGS += -DBLEDIS_FW_VERSION='"$(GIT_VERSION) $(SD_NAME) $(SD_VERSION)"' +CFLAGS += -DBLEDIS_FW_VERSION='"$(GIT_VERSION) $(SD) $(SD_VERSION)"' _VER = $(subst ., ,$(word 1, $(subst -, ,$(GIT_VERSION)))) CFLAGS += -DMK_BOOTLOADER_VERSION='($(word 1,$(_VER)) << 16) + ($(word 2,$(_VER)) << 8) + $(word 3,$(_VER))' diff --git a/README.md b/README.md index 5d1a0352..dd06e641 100644 --- a/README.md +++ b/README.md @@ -109,25 +109,25 @@ Prerequisites To build: ``` -make BOARD=feather_nrf52840_express PROTOCOL=BLE all +make BOARD=feather_nrf52840_express SD=s140 all ``` To flash the bootloader with JLink: ``` -make BOARD=feather_nrf52840_express PROTOCOL=BLE flash +make BOARD=feather_nrf52840_express SD=s140 flash ``` To upgrade the bootloader using DFU Serial via port /dev/ttyACM0 ``` -make BOARD=feather_nrf52840_express SERIAL=/dev/ttyACM0 PROTOCOL=BLE dfu-flash +make BOARD=feather_nrf52840_express SERIAL=/dev/ttyACM0 SD=s140 dfu-flash ``` To flash SoftDevice (and chip erase): ``` -make BOARD=feather_nrf52840_express PROTOCOL=BLE sd +make BOARD=feather_nrf52840_express SD=s140 sd ``` For the list of supported boards, run `make` without `BOARD=` : @@ -152,7 +152,7 @@ use of both ANT and BLE simultaneously. To do this: 2. Place the contents of the softdevice package in the appropriate lib/softdevice folder. 3. Rename the API folder to _nrf52_6.1.1_API. 4. Rename the softdevice hex to _nrf52_6.1.1_softdevice.hex. -5. When building make sure to set PROTOCOL=BOTH +5. When building make sure to set SD=s340 or SD=s332 All bootloader features available in the single-stack BLE softdevice are also available in the dualstack softdevice, including OTA-DFU updates using BLE.