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

Add dualstack softdevice support #151

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 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
49 changes: 43 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -79,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
Expand Down
32 changes: 26 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
```
Expand Down Expand Up @@ -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=` :
Expand All @@ -139,14 +139,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 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

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