Skip to content

Commit 8bd5ce5

Browse files
committed
Set UF2 boot value without SD
Fallback to setting GPREGRET without SD if it isn't active. This fixes resetting into UF2 when BLE isn't active. Fixes #9423
1 parent 4d88d73 commit 8bd5ce5

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

ports/nordic/common-hal/microcontroller/__init__.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "supervisor/shared/safe_mode.h"
2222
#include "nrfx_glue.h"
2323
#include "nrf_nvic.h"
24+
#include "nrf_power.h"
2425

2526
// This routine should work even when interrupts are disabled. Used by OneWire
2627
// for precise timing.
@@ -61,10 +62,14 @@ void common_hal_mcu_enable_interrupts() {
6162

6263
void common_hal_mcu_on_next_reset(mcu_runmode_t runmode) {
6364
enum { DFU_MAGIC_UF2_RESET = 0x57 };
65+
uint8_t new_value = 0;
6466
if (runmode == RUNMODE_BOOTLOADER || runmode == RUNMODE_UF2) {
65-
sd_power_gpregret_set(0, DFU_MAGIC_UF2_RESET);
66-
} else {
67-
sd_power_gpregret_set(0, 0);
67+
new_value = DFU_MAGIC_UF2_RESET;
68+
}
69+
int err_code = sd_power_gpregret_set(0, DFU_MAGIC_UF2_RESET);
70+
if (err_code != NRF_SUCCESS) {
71+
// Set it without the soft device if the SD failed. (It may be off.)
72+
nrf_power_gpregret_set(NRF_POWER, new_value);
6873
}
6974
if (runmode == RUNMODE_SAFE_MODE) {
7075
safe_mode_on_next_reset(SAFE_MODE_PROGRAMMATIC);

0 commit comments

Comments
 (0)