Skip to content

Add dualstack softdevice support #151

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

Open
wants to merge 8 commits into
base: master
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
76 changes: 63 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -99,21 +99,71 @@ BIN = _bin/$(BOARD)
# Board specific
-include src/boards/$(BOARD)/board.mk

# MCU_SUB_VARIANT can be nrf52 (nrf52832), nrf52833, nrf52840
ifeq ($(MCU_SUB_VARIANT),nrf52)
SD_NAME = s132
DFU_DEV_REV = 0xADAF
CFLAGS += -DNRF52 -DNRF52832_XXAA -DS132
else ifeq ($(MCU_SUB_VARIANT),nrf52833)
SD_NAME = s140
#---------------------------------
# Select the softdevice to build for
#---------------------------------
ifeq ($(SD),s140)
CFLAGS += -DS140 -DBLE
DFU_DEV_REV = 52840
CFLAGS += -DNRF52833_XXAA -DS140
else ifeq ($(MCU_SUB_VARIANT),nrf52840)
SD_NAME = s140
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),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
CFLAGS += -DNRF52840_XXAA -DS140
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
ifeq ($(MCU_SUB_VARIANT),nrf52)
CFLAGS += -DNRF52832_XXAA
else
$(error Sub Variant $(MCU_SUB_VARIANT) is invalid for softdevice $(SD))
endif
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
$(error Sub Variant $(MCU_SUB_VARIANT) is invalid for softdevice $(SD))
endif
else ifeq ($SD,)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too many duplication here, this should be checked before the whole if, and SD should get the default only to S132/S140 only. Then the ifeq() sequence take care of all the CFLAGS.

# 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
else
$(error Sub Variant $(MCU_SUB_VARIANT) is unknown)
# Invalid SD was specified
$(error softdevice $(SD) is unknown)
endif

#------------------------------------------------------------------------------
Expand Down Expand Up @@ -289,7 +339,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))'
Expand Down
32 changes: 26 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,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:
```
Expand Down Expand Up @@ -111,25 +111,25 @@ Prerequisites
To build:

```
make BOARD=feather_nrf52840_express all
make BOARD=feather_nrf52840_express SD=s140 all
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove those SD=s140, you can add an additional build command to demonstrate using your ANT stack e.g

By default, the BLE stack S132/S140 is used, to build with a different softdevice stack, 

make SD=.... 

```

To flash the bootloader with JLink:

```
make BOARD=feather_nrf52840_express 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 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 sd
make BOARD=feather_nrf52840_express SD=s140 sd
```

For the list of supported boards, run `make` without `BOARD=` :
Expand All @@ -141,14 +141,34 @@ 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 <SD name>_nrf52_6.1.1_API.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you tell me what is the default name of the s332 and s340 name, I would prefer to have the makefile to use their default name from the extracted instead.

4. Rename the softdevice hex to <SD name>_nrf52_6.1.1_softdevice.hex.
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.

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

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
Expand Down
1 change: 1 addition & 0 deletions lib/softdevice/s332_nrf52_6.1.1/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Obtain the 6.1.1 s332 softdevice from thisisant.com and place the API folder and softdevice hex here.
1 change: 1 addition & 0 deletions lib/softdevice/s340_nrf52_6.1.1/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Obtain the 6.1.1 s340 softdevice from thisisant.com and place the API folder and softdevice hex here.
8 changes: 7 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -328,7 +328,13 @@ static uint32_t softdev_init(bool init_softdevice)
.accuracy = NRF_CLOCK_LF_ACCURACY_250_PPM
};

#ifdef BLE
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like to have an extra macro for this, please use the ANT_LICENSE_KEY for this as well. These macro should be removed from the makefile as well.

ifndef ANT_LICENSE_KEY

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 -------------*/
Expand Down