diff --git a/Cargo.toml b/Cargo.toml index 5acfd9d..d55a6df 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,4 +41,4 @@ lto = true [profile.dev] debug = true -lto = true +lto = false diff --git a/Makefile b/Makefile index 7341207..8ef9ad2 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,13 @@ debug: build arm-none-eabi-gdb target/thumbv7m-none-eabi/release/anne-key bloat: - $(XARGO) bloat --release --target thumbv7m-none-eabi $(BLOAT_ARGS) + $(XARGO) bloat --target thumbv7m-none-eabi $(BLOAT_ARGS) -n 50 + +fmt: + cargo fmt + +clippy: + $(XARGO) clippy --target thumbv7m-none-eabi clean: $(XARGO) clean diff --git a/build.rs b/build.rs index 88f7fef..539bce0 100644 --- a/build.rs +++ b/build.rs @@ -6,12 +6,18 @@ use std::path::PathBuf; fn main() { // Put the linker script somewhere the linker can find it let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); + let memory_x: &[u8] = if &env::var("PROFILE").unwrap()[..] == "debug" { + include_bytes!("memory-debug.x") + } else { + include_bytes!("memory-release.x") + }; File::create(out.join("memory.x")) .unwrap() - .write_all(include_bytes!("memory.x")) + .write_all(memory_x) .unwrap(); println!("cargo:rustc-link-search={}", out.display()); println!("cargo:rerun-if-changed=build.rs"); println!("cargo:rerun-if-changed=memory.x"); + println!("cargo:rerun-if-changed=memory-debug.x"); } diff --git a/memory-debug.x b/memory-debug.x new file mode 100644 index 0000000..7ee373f --- /dev/null +++ b/memory-debug.x @@ -0,0 +1,9 @@ +/* fake larger flash so debug builds succeed + can't actually use these on the stm32, but they + allow cargo bloat and clippy to run cleanly */ + +MEMORY +{ + FLASH : ORIGIN = 0x08004000, LENGTH = 4M + RAM : ORIGIN = 0x20000000, LENGTH = 4M +} diff --git a/memory.x b/memory-release.x similarity index 100% rename from memory.x rename to memory-release.x diff --git a/src/main.rs b/src/main.rs index d959735..63bcd56 100644 --- a/src/main.rs +++ b/src/main.rs @@ -216,3 +216,15 @@ fn exti9_5(_t: &mut Threshold, r: EXTI9_5::Resources) { // maybe only clear set bits? or ones from 9-5? unsafe { r.EXTI.pr.write(|w| w.bits(0xffff)) }; } + +// Need this when building in debug mode without LTO, otherwise we get linker +// errors. This isn't ever actually used. +#[cfg(debug_assertions)] +#[no_mangle] +pub unsafe extern "C" fn rust_begin_unwind( + _args: ::core::fmt::Arguments, + _file: &'static str, + _line: u32, +) -> ! { + loop {} +}