Skip to content

Commit 2581deb

Browse files
authored
Merge pull request #9618 from tannewt/fix_nrf_uf2_reset
Set UF2 boot value without SD
2 parents e680f66 + 8bd5ce5 commit 2581deb

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)