diff --git a/firmware/rust1/build.rs b/firmware/rust1/build.rs index f64efb047c65e617427034a33c13fde873da7437..52730bc0d2e83371ac5472879a23132a77e7b29b 100644 --- a/firmware/rust1/build.rs +++ b/firmware/rust1/build.rs @@ -21,6 +21,10 @@ fn main() { .unwrap() .write_all(include_bytes!("memory.x")) .unwrap(); + File::create(out.join("clear-bootloader-state.x")) + .unwrap() + .write_all(include_bytes!("clear-bootloader-state.x")) + .unwrap(); println!("cargo:rustc-link-search={}", out.display()); // By default, Cargo will re-run a build script whenever @@ -28,9 +32,11 @@ fn main() { // here, we ensure the build script is only re-run when // `memory.x` is changed. println!("cargo:rerun-if-changed=memory.x"); + println!("cargo:rerun-if-changed=clear-bootloader-state.x"); println!("cargo:rustc-link-arg-bins=--nmagic"); println!("cargo:rustc-link-arg-bins=-Tlink.x"); //println!("cargo:rustc-link-arg-bins=-Tlink-rp.x"); // This is for boot2 but the bootloader handles that for us. println!("cargo:rustc-link-arg-bins=-Tdefmt.x"); + println!("cargo:rustc-link-arg-bins=-Tclear-bootloader-state.x"); } diff --git a/firmware/rust1/clear-bootloader-state.x b/firmware/rust1/clear-bootloader-state.x new file mode 100644 index 0000000000000000000000000000000000000000..c798754852d1c7322976e90fb4bcb5e1bd0f956c --- /dev/null +++ b/firmware/rust1/clear-bootloader-state.x @@ -0,0 +1,7 @@ +SECTIONS +{ + .clear_bootloader_state : + { + KEEP(*(.clear_bootloader_state .clear_bootloader_state.*)) + } > BOOTLOADER_STATE =0xff +} diff --git a/firmware/rust1/src/bin/blinky.rs b/firmware/rust1/src/bin/blinky.rs index e97dca98f141e326a7037a1bf0f4220890c2dbb1..cda87ec47b3c365ffadf209a3331bbdf7b161f71 100644 --- a/firmware/rust1/src/bin/blinky.rs +++ b/firmware/rust1/src/bin/blinky.rs @@ -8,6 +8,7 @@ use embassy_rp::gpio; use embassy_time::{Duration, Timer}; use gpio::{Level, Output}; use {defmt_rtt as _, panic_probe as _}; +use heizung as _; // for clear_bootloader_state #[embassy_executor::main] async fn main(_spawner: Spawner) { diff --git a/firmware/rust1/src/clear_bootloader_state.rs b/firmware/rust1/src/clear_bootloader_state.rs new file mode 100644 index 0000000000000000000000000000000000000000..61895f0c00de69c1cb40df2dc132c7db92eec1ba --- /dev/null +++ b/firmware/rust1/src/clear_bootloader_state.rs @@ -0,0 +1,6 @@ + +// Clear bootloader state partition when we download this program +// via some other way (e.g. UF2 or pico-probe-rs). +#[used] +#[link_section = ".clear_bootloader_state"] +pub static CLEAR_BOOTLOADER_STATE: [u8; 4096] = [0xff; 4096]; diff --git a/firmware/rust1/src/lib.rs b/firmware/rust1/src/lib.rs index 0af20935b1863590f05e2b03507c8255dfa011ff..a22b737df5f1fb8762bbac534870b6ee386b69e9 100644 --- a/firmware/rust1/src/lib.rs +++ b/firmware/rust1/src/lib.rs @@ -4,3 +4,4 @@ pub mod dont_abort; pub mod i2c_scan; pub mod rs485; pub mod modbus_server; +pub mod clear_bootloader_state;