Skip to content

Commit

Permalink
Merge pull request #613 from jannic/issue-564
Browse files Browse the repository at this point in the history
Implement reset() and halt() functions
  • Loading branch information
jannic authored Sep 8, 2023
2 parents 6756d35 + 1aec0cb commit 2eb3d6f
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions rp2040-hal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,42 @@ pub use i2c::I2C;
/// of `main`. As spinlocks are not automatically unlocked on software resets,
/// this can prevent unexpected deadlocks when running from a debugger.
pub use rp2040_hal_macros::entry;
use sio::CoreId;
pub use sio::Sio;
pub use spi::Spi;
pub use timer::Timer;
pub use watchdog::Watchdog;

/// Trigger full reset of the RP2040.
///
/// Uses the watchdog and the power-on state machine (PSM) to reset all on-chip components.
pub fn reset() -> ! {
unsafe {
cortex_m::interrupt::disable();
(*pac::PSM::PTR).wdsel.write(|w| w.bits(0x0001ffff));
(*pac::WATCHDOG::PTR).ctrl.write(|w| w.trigger().set_bit());
#[allow(clippy::empty_loop)]
loop {}
}
}

/// Halt the RP2040.
///
/// Completely disables the other core, and parks the current core in an
/// infinite loop with interrupts disabled.
///
/// Doesn't stop other subsystems, like the DMA controller.
pub fn halt() -> ! {
unsafe {
cortex_m::interrupt::disable();
// Stop other core
match crate::Sio::core() {
CoreId::Core0 => (*pac::PSM::PTR).frce_off.write(|w| w.proc1().set_bit()),
CoreId::Core1 => (*pac::PSM::PTR).frce_off.write(|w| w.proc0().set_bit()),
}
// Keep current core running, so debugging stays possible
loop {
cortex_m::asm::wfe()
}
}
}

0 comments on commit 2eb3d6f

Please sign in to comment.