Skip to content

Commit

Permalink
Set UF2 boot value without SD
Browse files Browse the repository at this point in the history
Fallback to setting GPREGRET without SD if it isn't active. This
fixes resetting into UF2 when BLE isn't active. Fixes micropython#9423
  • Loading branch information
tannewt committed Sep 12, 2024
1 parent 4d88d73 commit 8bd5ce5
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions ports/nordic/common-hal/microcontroller/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "supervisor/shared/safe_mode.h"
#include "nrfx_glue.h"
#include "nrf_nvic.h"
#include "nrf_power.h"

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

void common_hal_mcu_on_next_reset(mcu_runmode_t runmode) {
enum { DFU_MAGIC_UF2_RESET = 0x57 };
uint8_t new_value = 0;
if (runmode == RUNMODE_BOOTLOADER || runmode == RUNMODE_UF2) {
sd_power_gpregret_set(0, DFU_MAGIC_UF2_RESET);
} else {
sd_power_gpregret_set(0, 0);
new_value = DFU_MAGIC_UF2_RESET;
}
int err_code = sd_power_gpregret_set(0, DFU_MAGIC_UF2_RESET);
if (err_code != NRF_SUCCESS) {
// Set it without the soft device if the SD failed. (It may be off.)
nrf_power_gpregret_set(NRF_POWER, new_value);
}
if (runmode == RUNMODE_SAFE_MODE) {
safe_mode_on_next_reset(SAFE_MODE_PROGRAMMATIC);
Expand Down

0 comments on commit 8bd5ce5

Please sign in to comment.