Skip to content

[NRF5] Bootloader for NRF52_DK @s132 and NRF51_DK @s130 #3376

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

Merged
merged 2 commits into from
Dec 23, 2016
Merged
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
7 changes: 4 additions & 3 deletions features/FEATURE_BLE/ble/services/DFUService.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
* limitations under the License.
*/

#ifdef TARGET_NRF51822 /* DFU only supported on nrf51 platforms */

#ifndef __BLE_DFU_SERVICE_H__
#define __BLE_DFU_SERVICE_H__

#if defined(TARGET_NRF51822) || defined(TARGET_NRF52832) /* DFU only supported on nrf5x platforms */

#include "ble/BLE.h"
#include "ble/UUID.h"
Expand Down Expand Up @@ -142,5 +142,6 @@ class DFUService {
static ResetPrepare_t handoverCallback; /**< Application-specific handover callback. */
};

#endif /* #ifdef TARGET_NRF51822 or TARGET_NRF52832 */

#endif /* #ifndef __BLE_DFU_SERVICE_H__*/
#endif /* #ifdef TARGET_NRF51822 */
4 changes: 2 additions & 2 deletions features/FEATURE_BLE/source/services/DFUService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

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

#include "ble/services/DFUService.h"

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

DFUService::ResetPrepare_t DFUService::handoverCallback = NULL;

#endif /* #ifdef TARGET_NRF51822 */
#endif /* #ifdef TARGET_NRF51822 or TARGET_NRF52832 */

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

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

MRS R1, CONTROL ; Get CONTROL register value
MOVS R2, #0x02 ; load 2 to r2
BICS R1, R2 ; clear value of CONTROL->SPSEL - > make sure MSP will be used
MSR CONTROL, R1 ; set the stack pointer to MSP

MOV LR, R4 ; Clear the link register and set to ones to ensure no return, R4 = 0xFFFFFFFF.
BX R0 ; Branch to reset handler of bootloader.

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

"mrs r1, control\t\n" // Get CONTROL register value
"movs r2, #0x02\t\n" // load 2 to r2
"bic r1, r2\t\n" // clear value of CONTROL->SPSEL - > make sure MSP will be used
"msr control, r1\t\n" // set the stack pointer to MSP

"mov lr, r4\t\n" // Clear the link register and set to ones to ensure no return.
"bx r0\t\n" // Branch to reset handler of bootloader.

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

"mrs r1, control\n" // Get CONTROL register value
"movs r2, #0x02\n" // load 2 to r2
"bics r1, r2\n" // clear value of CONTROL->SPSEL - > make sure MSP will be used
"msr control, r1\n" // set the stack pointer to MSP

"mov lr, r4\n" // Clear the link register and set to ones to ensure no return.
"bx r0\n" // Branch to reset handler of bootloader.

Expand Down Expand Up @@ -173,7 +188,14 @@ static inline void bootloader_util_reset(uint32_t start_addr)
#endif


#include "nrf.h"

void bootloader_util_app_start(uint32_t start_addr)
{
#ifdef TARGET_MCU_NRF52
// kill systick
SysTick->CTRL = 0;
#endif

bootloader_util_reset(start_addr);
}
41 changes: 35 additions & 6 deletions targets/targets.json
Original file line number Diff line number Diff line change
Expand Up @@ -1617,13 +1617,13 @@
"inherits": ["MCU_NRF51_32K"],
"extra_labels_add": ["NRF51_DK"]
},
"NRF51_DK_BOOT": {
"NRF51_DK_LEGACY_BOOT": {
"supported_form_factors": ["ARDUINO"],
"inherits": ["MCU_NRF51_32K_BOOT"],
"extra_labels_add": ["NRF51_DK"],
"macros_add": ["TARGET_NRF51_DK"]
},
"NRF51_DK_OTA": {
"NRF51_DK_LEGACY_OTA": {
"supported_form_factors": ["ARDUINO"],
"inherits": ["MCU_NRF51_32K_OTA"],
"extra_labels_add": ["NRF51_DK"],
Expand Down Expand Up @@ -2387,11 +2387,12 @@
"MERGE_SOFT_DEVICE": true,
"EXPECTED_SOFTDEVICES_WITH_OFFSETS": [
{
"boot": "",
"boot": ["s130_nrf51_2.0.0_db_bootloader.hex", "s130_nrf51_2.0.0_sb_bootloader.hex"],
"name": "s130_nrf51_2.0.0_softdevice.hex",
"offset": 110592
}
],
"bootloader_select_index": 0,
"detect_code": ["1070"],
"post_binary_hook": {
"function": "MCU_NRF51Code.binary_hook",
Expand Down Expand Up @@ -2425,6 +2426,19 @@
"release_versions": ["2", "5"],
"device_name": "nRF51822_xxAA"
},
"NRF51_DK_BOOT": {
"inherits": ["NRF51_DK"],
"MERGE_BOOTLOADER": true,
"macros_add": ["TARGET_OTA_ENABLED"],
"extra_labels_add": ["NRF51_DK"]
},
"NRF51_DK_OTA": {
"inherits": ["NRF51_DK"],
"MERGE_BOOTLOADER": false,
"MERGE_SOFT_DEVICE": false,
"macros_add": ["TARGET_OTA_ENABLED"],
"extra_labels_add": ["NRF51_DK"]
},
"NRF51_DONGLE": {
"inherits": ["MCU_NRF51_32K_UNIFIED"],
"progen": {"target": "nrf51-dongle"},
Expand All @@ -2434,6 +2448,9 @@
"MCU_NRF52": {
"inherits": ["Target"],
"core": "Cortex-M4F",
"MERGE_SOFT_DEVICE": true,
"MERGE_BOOTLOADER": false,
"OVERRIDE_BOOTLOADER_FILENAME": "nrf52832_bootloader.hex",
"macros": ["NRF52", "TARGET_NRF52832", "BLE_STACK_SUPPORT_REQD", "SOFTDEVICE_PRESENT", "S132"],
"extra_labels": ["NORDIC", "MCU_NRF52", "MCU_NRF52832", "NRF5"],
"OUTPUT_EXT": "hex",
Expand All @@ -2442,19 +2459,18 @@
"public": false,
"detect_code": ["1101"],
"program_cycle_s": 6,
"MERGE_SOFT_DEVICE": true,
"EXPECTED_SOFTDEVICES_WITH_OFFSETS": [
{
"boot": "",
"boot": ["s132_nrf52_2.0.0_db_bootloader.hex", "s132_nrf52_2.0.0_sb_bootloader.hex"],
Copy link
Member

Choose a reason for hiding this comment

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

There is a typo in the dual bank bootloader name: s132_nrf52_2.0.0_db_bootloadre.hex instead of s132_nrf52_2.0.0_db_bootloader.hex

Copy link
Contributor Author

Choose a reason for hiding this comment

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

bug

"name": "s132_nrf52_2.0.0_softdevice.hex",
"offset": 114688
}
],
"bootloader_select_index": 0,
"post_binary_hook": {
"function": "MCU_NRF51Code.binary_hook",
"toolchains": ["ARM_STD", "GCC_ARM", "IAR"]
},
"MERGE_BOOTLOADER": false,
"features": ["BLE"],
"config": {
"lf_clock_src": {
Expand Down Expand Up @@ -2484,6 +2500,19 @@
"overrides": {"uart_hwfc": 0},
"device_name": "nRF52832_xxAA"
},
"NRF52_DK_BOOT": {
"inherits": ["NRF52_DK"],
"release_versions": ["2", "5"],
"extra_labels_add": ["NRF52_DK"],
"MERGE_BOOTLOADER": true
},
"NRF52_DK_OTA": {
"inherits": ["NRF52_DK"],
"release_versions": ["2", "5"],
"extra_labels_add": ["NRF52_DK"],
"MERGE_BOOTLOADER": false,
"MERGE_SOFT_DEVICE": false
},
"DELTA_DFBM_NQ620": {
"supported_form_factors": ["ARDUINO"],
"inherits": ["MCU_NRF52"],
Expand Down
20 changes: 14 additions & 6 deletions tools/targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,12 +462,20 @@ def binary_hook(t_self, resources, _, binf):
% t_self.target.OVERRIDE_BOOTLOADER_FILENAME)
blf = hexf
break
elif hexf.find(softdevice_and_offset_entry['boot']) != -1:
t_self.debug("Bootloader file found %s."
% softdevice_and_offset_entry['boot'])
blf = hexf
break

else:
try:
boot_num = t_self.target.bootloader_select_index
except AttributeError:
boot_num = 0

expected_bootloader_name = softdevice_and_offset_entry['boot'][boot_num]

if hexf.find(expected_bootloader_name) != -1:
t_self.debug("Bootloader file found %s."
% softdevice_and_offset_entry['boot'])
blf = hexf
break

# Merge user code with softdevice
from intelhex import IntelHex
binh = IntelHex()
Expand Down