Skip to content

Commit 15d1944

Browse files
authored
Merge pull request #3376 from nvlsianpu/nrf5_dfu_s13x_v2
[NRF5] Bootloader for NRF52_DK @s132 and NRF51_DK @s130
2 parents eb3dc2d + 8e641c3 commit 15d1944

File tree

9 files changed

+1875
-17
lines changed

9 files changed

+1875
-17
lines changed

Diff for: features/FEATURE_BLE/ble/services/DFUService.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
* limitations under the License.
1515
*/
1616

17-
#ifdef TARGET_NRF51822 /* DFU only supported on nrf51 platforms */
18-
1917
#ifndef __BLE_DFU_SERVICE_H__
2018
#define __BLE_DFU_SERVICE_H__
19+
20+
#if defined(TARGET_NRF51822) || defined(TARGET_NRF52832) /* DFU only supported on nrf5x platforms */
2121

2222
#include "ble/BLE.h"
2323
#include "ble/UUID.h"
@@ -142,5 +142,6 @@ class DFUService {
142142
static ResetPrepare_t handoverCallback; /**< Application-specific handover callback. */
143143
};
144144

145+
#endif /* #ifdef TARGET_NRF51822 or TARGET_NRF52832 */
146+
145147
#endif /* #ifndef __BLE_DFU_SERVICE_H__*/
146-
#endif /* #ifdef TARGET_NRF51822 */

Diff for: features/FEATURE_BLE/source/services/DFUService.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
#ifdef TARGET_NRF51822 /* DFU only supported on nrf51 platforms */
17+
#if defined(TARGET_NRF51822) || defined(TARGET_NRF52832) /* DFU only supported on nrf5x platforms */
1818

1919
#include "ble/services/DFUService.h"
2020

@@ -41,4 +41,4 @@ const uint8_t DFUServicePacketCharacteristicUUID[] = {
4141

4242
DFUService::ResetPrepare_t DFUService::handoverCallback = NULL;
4343

44-
#endif /* #ifdef TARGET_NRF51822 */
44+
#endif /* #ifdef TARGET_NRF51822 or TARGET_NRF52832 */

Diff for: targets/TARGET_NORDIC/TARGET_NRF5/TARGET_MCU_NRF51822_UNIFIED/device/bootloader/s130_nrf51_2.0.0_db_bootloader.hex

+436
Large diffs are not rendered by default.

Diff for: targets/TARGET_NORDIC/TARGET_NRF5/TARGET_MCU_NRF51822_UNIFIED/device/bootloader/s130_nrf51_2.0.0_sb_bootloader.hex

+430
Large diffs are not rendered by default.

Diff for: targets/TARGET_NORDIC/TARGET_NRF5/TARGET_MCU_NRF52832/device/bootloader/s132_nrf52_2.0.0_db_bootloader.hex

+469
Large diffs are not rendered by default.

Diff for: targets/TARGET_NORDIC/TARGET_NRF5/TARGET_MCU_NRF52832/device/bootloader/s132_nrf52_2.0.0_sb_bootloader.hex

+463
Large diffs are not rendered by default.

Diff for: targets/TARGET_NORDIC/TARGET_NRF5/sdk/libraries/bootloader_dfu/bootloader_util.c

+22
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ __asm static void bootloader_util_reset(uint32_t start_addr)
6969
CMP R5, #0x00 ; Compare, if 0 then we are in thread mode and can continue to reset handler of bootloader.
7070
BNE isr_abort ; If not zero we need to exit current ISR and jump to reset handler of bootloader.
7171

72+
MRS R1, CONTROL ; Get CONTROL register value
73+
MOVS R2, #0x02 ; load 2 to r2
74+
BICS R1, R2 ; clear value of CONTROL->SPSEL - > make sure MSP will be used
75+
MSR CONTROL, R1 ; set the stack pointer to MSP
76+
7277
MOV LR, R4 ; Clear the link register and set to ones to ensure no return, R4 = 0xFFFFFFFF.
7378
BX R0 ; Branch to reset handler of bootloader.
7479

@@ -106,6 +111,11 @@ static inline void bootloader_util_reset(uint32_t start_addr)
106111
"cmp r5, #0x00\t\n" // Compare, if 0 then we are in thread mode and can continue to reset handler of bootloader.
107112
"bne isr_abort\t\n" // If not zero we need to exit current ISR and jump to reset handler of bootloader.
108113

114+
"mrs r1, control\t\n" // Get CONTROL register value
115+
"movs r2, #0x02\t\n" // load 2 to r2
116+
"bic r1, r2\t\n" // clear value of CONTROL->SPSEL - > make sure MSP will be used
117+
"msr control, r1\t\n" // set the stack pointer to MSP
118+
109119
"mov lr, r4\t\n" // Clear the link register and set to ones to ensure no return.
110120
"bx r0\t\n" // Branch to reset handler of bootloader.
111121

@@ -145,6 +155,11 @@ static inline void bootloader_util_reset(uint32_t start_addr)
145155
"cmp r5, #0x00\n" // Compare, if 0 then we are in thread mode and can continue to reset handler of bootloader.
146156
"bne.n isr_abort\n" // If not zero we need to exit current ISR and jump to reset handler of bootloader.
147157

158+
"mrs r1, control\n" // Get CONTROL register value
159+
"movs r2, #0x02\n" // load 2 to r2
160+
"bics r1, r2\n" // clear value of CONTROL->SPSEL - > make sure MSP will be used
161+
"msr control, r1\n" // set the stack pointer to MSP
162+
148163
"mov lr, r4\n" // Clear the link register and set to ones to ensure no return.
149164
"bx r0\n" // Branch to reset handler of bootloader.
150165

@@ -173,7 +188,14 @@ static inline void bootloader_util_reset(uint32_t start_addr)
173188
#endif
174189

175190

191+
#include "nrf.h"
192+
176193
void bootloader_util_app_start(uint32_t start_addr)
177194
{
195+
#ifdef TARGET_MCU_NRF52
196+
// kill systick
197+
SysTick->CTRL = 0;
198+
#endif
199+
178200
bootloader_util_reset(start_addr);
179201
}

Diff for: targets/targets.json

+35-6
Original file line numberDiff line numberDiff line change
@@ -1631,13 +1631,13 @@
16311631
"inherits": ["MCU_NRF51_32K"],
16321632
"extra_labels_add": ["NRF51_DK"]
16331633
},
1634-
"NRF51_DK_BOOT": {
1634+
"NRF51_DK_LEGACY_BOOT": {
16351635
"supported_form_factors": ["ARDUINO"],
16361636
"inherits": ["MCU_NRF51_32K_BOOT"],
16371637
"extra_labels_add": ["NRF51_DK"],
16381638
"macros_add": ["TARGET_NRF51_DK"]
16391639
},
1640-
"NRF51_DK_OTA": {
1640+
"NRF51_DK_LEGACY_OTA": {
16411641
"supported_form_factors": ["ARDUINO"],
16421642
"inherits": ["MCU_NRF51_32K_OTA"],
16431643
"extra_labels_add": ["NRF51_DK"],
@@ -2401,11 +2401,12 @@
24012401
"MERGE_SOFT_DEVICE": true,
24022402
"EXPECTED_SOFTDEVICES_WITH_OFFSETS": [
24032403
{
2404-
"boot": "",
2404+
"boot": ["s130_nrf51_2.0.0_db_bootloader.hex", "s130_nrf51_2.0.0_sb_bootloader.hex"],
24052405
"name": "s130_nrf51_2.0.0_softdevice.hex",
24062406
"offset": 110592
24072407
}
24082408
],
2409+
"bootloader_select_index": 0,
24092410
"detect_code": ["1070"],
24102411
"post_binary_hook": {
24112412
"function": "MCU_NRF51Code.binary_hook",
@@ -2439,6 +2440,19 @@
24392440
"release_versions": ["2", "5"],
24402441
"device_name": "nRF51822_xxAA"
24412442
},
2443+
"NRF51_DK_BOOT": {
2444+
"inherits": ["NRF51_DK"],
2445+
"MERGE_BOOTLOADER": true,
2446+
"macros_add": ["TARGET_OTA_ENABLED"],
2447+
"extra_labels_add": ["NRF51_DK"]
2448+
},
2449+
"NRF51_DK_OTA": {
2450+
"inherits": ["NRF51_DK"],
2451+
"MERGE_BOOTLOADER": false,
2452+
"MERGE_SOFT_DEVICE": false,
2453+
"macros_add": ["TARGET_OTA_ENABLED"],
2454+
"extra_labels_add": ["NRF51_DK"]
2455+
},
24422456
"NRF51_DONGLE": {
24432457
"inherits": ["MCU_NRF51_32K_UNIFIED"],
24442458
"progen": {"target": "nrf51-dongle"},
@@ -2448,6 +2462,9 @@
24482462
"MCU_NRF52": {
24492463
"inherits": ["Target"],
24502464
"core": "Cortex-M4F",
2465+
"MERGE_SOFT_DEVICE": true,
2466+
"MERGE_BOOTLOADER": false,
2467+
"OVERRIDE_BOOTLOADER_FILENAME": "nrf52832_bootloader.hex",
24512468
"macros": ["NRF52", "TARGET_NRF52832", "BLE_STACK_SUPPORT_REQD", "SOFTDEVICE_PRESENT", "S132"],
24522469
"extra_labels": ["NORDIC", "MCU_NRF52", "MCU_NRF52832", "NRF5"],
24532470
"OUTPUT_EXT": "hex",
@@ -2456,19 +2473,18 @@
24562473
"public": false,
24572474
"detect_code": ["1101"],
24582475
"program_cycle_s": 6,
2459-
"MERGE_SOFT_DEVICE": true,
24602476
"EXPECTED_SOFTDEVICES_WITH_OFFSETS": [
24612477
{
2462-
"boot": "",
2478+
"boot": ["s132_nrf52_2.0.0_db_bootloader.hex", "s132_nrf52_2.0.0_sb_bootloader.hex"],
24632479
"name": "s132_nrf52_2.0.0_softdevice.hex",
24642480
"offset": 114688
24652481
}
24662482
],
2483+
"bootloader_select_index": 0,
24672484
"post_binary_hook": {
24682485
"function": "MCU_NRF51Code.binary_hook",
24692486
"toolchains": ["ARM_STD", "GCC_ARM", "IAR"]
24702487
},
2471-
"MERGE_BOOTLOADER": false,
24722488
"features": ["BLE"],
24732489
"config": {
24742490
"lf_clock_src": {
@@ -2506,6 +2522,19 @@
25062522
"release_versions": ["2", "5"],
25072523
"device_name": "nRF52832_xxAA"
25082524
},
2525+
"NRF52_DK_BOOT": {
2526+
"inherits": ["NRF52_DK"],
2527+
"release_versions": ["2", "5"],
2528+
"extra_labels_add": ["NRF52_DK"],
2529+
"MERGE_BOOTLOADER": true
2530+
},
2531+
"NRF52_DK_OTA": {
2532+
"inherits": ["NRF52_DK"],
2533+
"release_versions": ["2", "5"],
2534+
"extra_labels_add": ["NRF52_DK"],
2535+
"MERGE_BOOTLOADER": false,
2536+
"MERGE_SOFT_DEVICE": false
2537+
},
25092538
"DELTA_DFBM_NQ620": {
25102539
"supported_form_factors": ["ARDUINO"],
25112540
"inherits": ["MCU_NRF52"],

Diff for: tools/targets.py

+14-6
Original file line numberDiff line numberDiff line change
@@ -462,12 +462,20 @@ def binary_hook(t_self, resources, _, binf):
462462
% t_self.target.OVERRIDE_BOOTLOADER_FILENAME)
463463
blf = hexf
464464
break
465-
elif hexf.find(softdevice_and_offset_entry['boot']) != -1:
466-
t_self.debug("Bootloader file found %s."
467-
% softdevice_and_offset_entry['boot'])
468-
blf = hexf
469-
break
470-
465+
else:
466+
try:
467+
boot_num = t_self.target.bootloader_select_index
468+
except AttributeError:
469+
boot_num = 0
470+
471+
expected_bootloader_name = softdevice_and_offset_entry['boot'][boot_num]
472+
473+
if hexf.find(expected_bootloader_name) != -1:
474+
t_self.debug("Bootloader file found %s."
475+
% softdevice_and_offset_entry['boot'])
476+
blf = hexf
477+
break
478+
471479
# Merge user code with softdevice
472480
from intelhex import IntelHex
473481
binh = IntelHex()

0 commit comments

Comments
 (0)