Skip to content

Commit

Permalink
Use GPIO instead of memory poking for SP reset
Browse files Browse the repository at this point in the history
  • Loading branch information
mkeeter committed Apr 5, 2024
1 parent e544709 commit e5380fb
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
1 change: 1 addition & 0 deletions app/oxide-rot-1/app-dev.toml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ pins = [
# SCK
{ pin = { port = 0, pin = 7 }, alt = 3 },
{ name = "SP_TO_ROT_JTAG_DETECT_L", pin = { port = 0, pin = 20 }, alt = 0, direction = "input" },
{ name = "ROT_TO_SP_RESET_L", pin = { port = 0, pin = 13 }, alt = 0, value = true, direction = "output" },
]
spi_num = 5

Expand Down
1 change: 1 addition & 0 deletions app/oxide-rot-1/app.toml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ pins = [
# SCK
{ pin = { port = 0, pin = 7 }, alt = 3 },
{ name = "SP_TO_ROT_JTAG_DETECT_L", pin = { port = 0, pin = 20 }, alt = 0, direction = "input" },
{ name = "ROT_TO_SP_RESET_L", pin = { port = 0, pin = 13 }, alt = 0, value = true, direction = "output" },
]
spi_num = 5

Expand Down
17 changes: 17 additions & 0 deletions build/lpc55pins/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ pub struct PinConfig {
digimode: Option<String>,
opendrain: Option<String>,
direction: Option<String>,
value: Option<bool>,
name: Option<String>,
}

Expand Down Expand Up @@ -135,6 +136,22 @@ pub fn codegen(pins: Vec<PinConfig>) -> Result<()> {
writeln!(&mut file, "iocon.iocon_configure(")?;
writeln!(&mut file, "{}", p.to_token_stream())?;
writeln!(&mut file, ");")?;

// Output pins can specify their value, which is set before configuring
// their output mode (to avoid glitching).
if let Some(v) = p.value {
assert!(
matches!(p.direction.as_deref(), Some("output")),
"can only set value for output pins"
);
writeln!(&mut file, "iocon.set_val(")?;
writeln!(&mut file, "{}", p.pin.to_token_stream())?;
writeln!(
&mut file,
"{});",
if v { "Value::One" } else { "Value::Zero" }
)?;
}
match p.direction {
None => (),
Some(d) => {
Expand Down
13 changes: 5 additions & 8 deletions drv/lpc55-swd/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1064,14 +1064,11 @@ impl ServerImpl {
}

// Reset the STM32, causing it to reboot into the newly-set slot
// Details from PM0253, Section 4.3.5
const AIRCR: u32 = 0xE000ED0C;
const AIRCR_VECTKEY: u32 = 0x5FA << 16;
const AIRCR_SYSRESETREQ: u32 = 1 << 2;
self.write_single_target_addr(
AIRCR,
AIRCR_VECTKEY | AIRCR_SYSRESETREQ,
)?;
use drv_lpc55_gpio_api::{Pins, Value};
let gpio = Pins::from(self.gpio);
gpio.set_val(ROT_TO_SP_RESET_L, Value::Zero);
hl::sleep_for(10);
gpio.set_val(ROT_TO_SP_RESET_L, Value::One);

Ok(())
}
Expand Down

0 comments on commit e5380fb

Please sign in to comment.