Skip to content

Commit 8a2c301

Browse files
Reset SPI on power off.
Host might be mid tx.
1 parent f86047c commit 8a2c301

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

neotron-bmc-pico/src/main.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ mod app {
421421
.state_dc_power_enabled
422422
.lock(|r| *r = DcPowerState::Off);
423423
// Stop any SPI stuff that's currently going on (the host is about to be powered off)
424-
ctx.shared.spi.lock(|s| s.stop());
424+
ctx.shared.spi.lock(|s| s.reset(&mut rcc));
425425
// Put the host into reset
426426
ctx.shared.pin_sys_reset.lock(|pin| pin.set_low().unwrap());
427427
// Shut off the 5V power
@@ -469,8 +469,11 @@ mod app {
469469
// Is the board powered on? Don't do a reset if it's powered off.
470470
if ctx.shared.state_dc_power_enabled.lock(|r| *r) == DcPowerState::On {
471471
defmt::info!("Reset!");
472-
ctx.shared.pin_sys_reset.lock(|pin| pin.set_low().unwrap());
472+
// Step 1 - Stop any SPI stuff that's currently going on (the host is about to be reset)
473473
ctx.shared.spi.lock(|s| s.reset(&mut rcc));
474+
// Step 2 - Hold reset line (active) low
475+
ctx.shared.pin_sys_reset.lock(|pin| pin.set_low().unwrap());
476+
// Step 3 - Take it out of reset in a short while
474477
// Returns an error if it's already scheduled (but we don't care)
475478
let _ = exit_reset::spawn_after(RESET_DURATION_MS.millis());
476479
}

0 commit comments

Comments
 (0)