Skip to content

Commit b8544f5

Browse files
committed
feat: add SD S340 support for nRF52840 and nRF52833
1 parent a48e944 commit b8544f5

File tree

7 files changed

+82
-18
lines changed

7 files changed

+82
-18
lines changed

.github/workflows/githubci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
id: set-matrix
2222
working-directory: src/boards
2323
run: |
24-
MATRIX_JSON=$(ls -d */ | sed 's/\/$//' | jq -R -s -c 'split("\n")[:-1]')
24+
MATRIX_JSON=$(ls -d */ | sed 's/\/$//' | grep -vE '_s340$' | jq -R -s -c 'split("\n")[:-1]')
2525
echo "matrix=$MATRIX_JSON"
2626
echo "matrix=$MATRIX_JSON" >> $GITHUB_OUTPUT
2727

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,7 @@ TAGS
6565

6666
.DS_Store
6767
Makefile.user
68+
69+
# Exclude all SoftDevice S340 files
70+
lib/softdevice/s340*
71+

CMakeLists.txt

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -227,22 +227,37 @@ if (MCU_VARIANT STREQUAL "nrf52")
227227
S132
228228
)
229229
elseif (MCU_VARIANT STREQUAL "nrf52833")
230-
set(SD_NAME s140)
231230
set(DFU_DEV_REV 52833)
232231
set(DFU_APP_DATA_RESERVED 7*4096)
233-
target_compile_definitions(bootloader PUBLIC
234-
NRF52833_XXAA
235-
S140
236-
)
232+
if (SD_NAME STREQUAL "s340")
233+
target_compile_definitions(bootloader PUBLIC
234+
NRF52833_XXAA
235+
S340
236+
)
237+
else ()
238+
set(SD_NAME s140)
239+
target_compile_definitions(bootloader PUBLIC
240+
NRF52833_XXAA
241+
S140
242+
)
243+
endif ()
237244
elseif (MCU_VARIANT STREQUAL "nrf52840")
238-
set(SD_NAME s140)
239245
set(DFU_DEV_REV 52840)
240246
# App reserved 40KB (8+32) to match circuitpython for 840
241247
set(DFU_APP_DATA_RESERVED 10*4096)
242-
target_compile_definitions(bootloader PUBLIC
243-
NRF52840_XXAA
244-
S140
245-
)
248+
if (SD_NAME STREQUAL "s340")
249+
target_compile_definitions(bootloader PUBLIC
250+
NRF52840_XXAA
251+
S340
252+
)
253+
else ()
254+
set(SD_NAME s140)
255+
target_compile_definitions(bootloader PUBLIC
256+
NRF52840_XXAA
257+
S140
258+
)
259+
endif ()
260+
246261
else ()
247262
message(FATAL_ERROR "MCU_VARIANT ${MCU_VARIANT} is unknown")
248263
endif ()

Makefile

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,22 @@ ifeq ($(MCU_SUB_VARIANT),nrf52)
109109
CFLAGS += -DNRF52 -DNRF52832_XXAA -DS132
110110
DFU_APP_DATA_RESERVED=7*4096
111111
else ifeq ($(MCU_SUB_VARIANT),nrf52833)
112-
SD_NAME = s140
112+
ifeq ($(SD_NAME),s340)
113+
CFLAGS += -DNRF52833_XXAA -DS340
114+
else
115+
SD_NAME = s140
116+
CFLAGS += -DNRF52833_XXAA -DS140
117+
endif
113118
DFU_DEV_REV = 52833
114-
CFLAGS += -DNRF52833_XXAA -DS140
115119
DFU_APP_DATA_RESERVED=7*4096
116120
else ifeq ($(MCU_SUB_VARIANT),nrf52840)
117-
SD_NAME = s140
121+
ifeq ($(SD_NAME),s340)
122+
CFLAGS += -DNRF52840_XXAA -DS340
123+
else
124+
SD_NAME = s140
125+
CFLAGS += -DNRF52840_XXAA -DS140
126+
endif
118127
DFU_DEV_REV = 52840
119-
CFLAGS += -DNRF52840_XXAA -DS140
120128
# App reserved 40KB (8+32) to match circuitpython for 840
121129
DFU_APP_DATA_RESERVED=10*4096
122130
else

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,25 @@ Supported boards are: feather_nrf52840_express feather_nrf52840_express pca10056
137137
Makefile:90: *** BOARD not defined. Stop
138138
```
139139
140+
#### Working with SoftDevice S340:
141+
The SoftDevice S340 is closed-source, not publicly available and is only distributed by Garmin Canada Inc.
142+
143+
In order to be able to download the required ANT+ capable SoftDevice, you need to register an 'ANT+ Adopter' account at [thisisant.com](https://www.thisisant.com/register/). After around one business day you will receive access to the resources there. Then do the following steps:
144+
- Download the SoftDevice S340 v7.0.1 [(here)](https://www.thisisant.com/developer/components/nrf52832#tab_protocol_stacks_tab) and extract its contents
145+
- Under `lib/softdevice` in this repository there is a folder called `s340_nrf52_7.0.1`
146+
- Copy the API folder `ANT_s340_nrf52_7.0.1.API`, the license agreement `License_Agreement_ANT_Softdevice_rev3_3.pdf` and the hex file `ANT_s340_nrf52_7.0.1.hex` from the extracted contents to it.
147+
- Rename the API folder to `s340_nrf52_7.0.1_API`
148+
- Rename the hex file to `s340_nrf52_7.0.1_softdevice.hex`
149+
- Modify `lib/softdevice/s340_nrf52_7.0.1_API/include/nrf_sdm.h` on line 191 and remove the two slashes at the beginning of `//#define...` to use the *evaluation key* for the ANT SoftDevice.
150+
- **VERY IMPORTANT:** You MUST obtain a valid commercial license key BEFORE releasing a product to market that uses the ANT SoftDevice!
151+
152+
To add or modify a board with an ANT+ capable SoftDevice S340 the `SD_VERSION` and `SD_NAME` parameters in the corresponding `board.mk` file have to be set:
153+
```
154+
SD_VERSION = 7.0.1
155+
SD_NAME = s340
156+
```
157+
**Important:** When adding a new board you must add the suffix `_s340` to the folder name to exclude it from automatic builds.
158+
140159
### Flash
141160
142161
To flash the bootloader (without softdevice/mbr) using JLink:
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Place SoftDevice S340 v7.0.1 files here

src/main.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,14 @@ static void mbr_init_sd(void) {
157157
sd_mbr_command(&com);
158158
}
159159

160+
// Helper function to check if SoftDevice is already enabled.
161+
// Especially SoftDevice S340 locks up when calling sd_softdevice_disable() and it's not enabled.
162+
static bool is_sd_enabled(void) {
163+
uint8_t sd_enabled = 0;
164+
sd_softdevice_is_enabled(&sd_enabled);
165+
return (sd_enabled == 1);
166+
}
167+
160168
//--------------------------------------------------------------------+
161169
//
162170
//--------------------------------------------------------------------+
@@ -206,13 +214,16 @@ int main(void) {
206214
if (!_sd_inited) mbr_init_sd();
207215

208216
// Make sure SD is disabled
209-
sd_softdevice_disable();
217+
if (is_sd_enabled()) {
218+
sd_softdevice_disable();
219+
}
210220
}
211221

212222
// clear in case we kept DFU_DBL_RESET_APP there
213223
(*dbl_reset_mem) = 0;
214224

215225
// start application
226+
PRINTF("Starting app...\r\n");
216227
bootloader_app_start();
217228
}
218229

@@ -306,7 +317,9 @@ static void check_dfu_mode(void) {
306317
}
307318

308319
if (_ota_dfu) {
309-
sd_softdevice_disable();
320+
if (is_sd_enabled()) {
321+
sd_softdevice_disable();
322+
}
310323
} else {
311324
usb_teardown();
312325
}
@@ -326,7 +339,11 @@ static uint32_t ble_stack_init(void) {
326339
.rc_temp_ctiv = 2,
327340
.accuracy = NRF_CLOCK_LF_ACCURACY_250_PPM
328341
};
329-
sd_softdevice_enable(&clock_cfg, app_error_fault_handler);
342+
#ifndef ANT_LICENSE_KEY
343+
sd_softdevice_enable(&clock_cfg, app_error_fault_handler);
344+
#else
345+
sd_softdevice_enable(&clock_cfg, app_error_fault_handler, ANT_LICENSE_KEY);
346+
#endif
330347
sd_nvic_EnableIRQ(SD_EVT_IRQn);
331348

332349
/*------------- Configure BLE params -------------*/

0 commit comments

Comments
 (0)