Skip to content
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

Set UF2 boot value without SD #9618

Merged
merged 1 commit into from
Sep 12, 2024
Merged
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
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