From 843173f29d5421791339df2ae8672bcc0a55d637 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20J=C3=B6rdens?= Date: Wed, 3 Mar 2021 16:36:10 +0100 Subject: [PATCH 1/4] panic: always turn on red leds, and halt --- Cargo.lock | 7 ------- Cargo.toml | 1 - src/hardware/mod.rs | 22 +++++++--------------- 3 files changed, 7 insertions(+), 23 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2ee26be..02b326a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -520,12 +520,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "panic-halt" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de96540e0ebde571dc55c73d60ef407c653844e6f9a1e2fdbd40c07b9252d812" - [[package]] name = "panic-semihosting" version = "0.5.6" @@ -729,7 +723,6 @@ dependencies = [ "mcp23017", "miniconf", "nb 1.0.0", - "panic-halt", "panic-semihosting", "paste", "serde", diff --git a/Cargo.toml b/Cargo.toml index 3411b48..fa6622c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,7 +33,6 @@ cortex-m-rt = { version = "0.6", features = ["device"] } cortex-m-log = { version = "0.7", features = ["log-integration"] } log = "0.4" panic-semihosting = { version = "0.5", optional = true } -panic-halt = "0.2" serde = { version = "1.0", features = ["derive"], default-features = false } heapless = { version = "0.5", features = ["serde"] } cortex-m-rtic = "0.5.5" diff --git a/src/hardware/mod.rs b/src/hardware/mod.rs index 0fa6d65..9fcfdf0 100644 --- a/src/hardware/mod.rs +++ b/src/hardware/mod.rs @@ -4,9 +4,6 @@ use stm32h7xx_hal as hal; #[cfg(feature = "semihosting")] use panic_semihosting as _; -#[cfg(not(any(feature = "nightly", feature = "semihosting")))] -use panic_halt as _; - mod adc; mod afe; mod configuration; @@ -47,15 +44,15 @@ pub use configuration::{setup, PounderDevices, StabilizerDevices}; #[inline(never)] #[panic_handler] -#[cfg(all(feature = "nightly", not(feature = "semihosting")))] +#[cfg(all(not(feature = "semihosting")))] fn panic(_info: &core::panic::PanicInfo) -> ! { let gpiod = unsafe { &*hal::stm32::GPIOD::ptr() }; - gpiod.odr.modify(|_, w| w.odr6().high().odr12().high()); // FP_LED_1, FP_LED_3 - #[cfg(feature = "nightly")] - core::intrinsics::abort(); - #[cfg(not(feature = "nightly"))] - unsafe { - core::intrinsics::abort(); + // Turn on both red LEDs, FP_LED_1, FP_LED_3 + gpiod.odr.modify(|_, w| w.odr6().high().odr12().high()); + loop { // Halt + core::sync::atomic::compiler_fence( + core::sync::atomic::Ordering::SeqCst, + ); } } @@ -63,8 +60,3 @@ fn panic(_info: &core::panic::PanicInfo) -> ! { fn HardFault(ef: &cortex_m_rt::ExceptionFrame) -> ! { panic!("HardFault at {:#?}", ef); } - -#[cortex_m_rt::exception] -fn DefaultHandler(irqn: i16) { - panic!("Unhandled exception (IRQn = {})", irqn); -} From 475f2b3dd23ce469384de1c8ae03a74068ecda94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20J=C3=B6rdens?= Date: Wed, 3 Mar 2021 17:00:29 +0100 Subject: [PATCH 2/4] panic: fmt --- src/hardware/mod.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/hardware/mod.rs b/src/hardware/mod.rs index 9fcfdf0..b8aa73d 100644 --- a/src/hardware/mod.rs +++ b/src/hardware/mod.rs @@ -49,7 +49,8 @@ fn panic(_info: &core::panic::PanicInfo) -> ! { let gpiod = unsafe { &*hal::stm32::GPIOD::ptr() }; // Turn on both red LEDs, FP_LED_1, FP_LED_3 gpiod.odr.modify(|_, w| w.odr6().high().odr12().high()); - loop { // Halt + loop { + // Halt core::sync::atomic::compiler_fence( core::sync::atomic::Ordering::SeqCst, ); From 059d4faf9f5d69bf27b13d22c174530e919210eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20J=C3=B6rdens?= Date: Wed, 3 Mar 2021 17:05:22 +0100 Subject: [PATCH 3/4] re-add DefaultHandler --- src/hardware/mod.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/hardware/mod.rs b/src/hardware/mod.rs index b8aa73d..cc7a34a 100644 --- a/src/hardware/mod.rs +++ b/src/hardware/mod.rs @@ -61,3 +61,8 @@ fn panic(_info: &core::panic::PanicInfo) -> ! { fn HardFault(ef: &cortex_m_rt::ExceptionFrame) -> ! { panic!("HardFault at {:#?}", ef); } + +#[cortex_m_rt::exception] +fn DefaultHandler(irqn: i16) { + panic!("Unhandled exception (IRQn = {})", irqn); +} From 148a3c8281f829ae02964af35fe96d260ecfaf92 Mon Sep 17 00:00:00 2001 From: David Nadlinger Date: Fri, 5 Mar 2021 17:58:41 +0000 Subject: [PATCH 4/4] hardware: Enable DEMCR TRCENA on boot for cycle counter Previously, the cycle counter would only work correctly when running in the debugger (which would also enable tracing). GitHub: Fixes #299. --- src/hardware/configuration.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/hardware/configuration.rs b/src/hardware/configuration.rs index d3d10fe..e8f3029 100644 --- a/src/hardware/configuration.rs +++ b/src/hardware/configuration.rs @@ -825,6 +825,14 @@ pub fn setup( None }; + let cycle_counter = { + // Set TRCENA bit, which is required for DWT counter to tick. (This is also + // set automatically when running in the debugger, and only cleared on power + // reset, not on soft reset.) + core.DCB.enable_trace(); + CycleCounter::new(core.DWT, ccdr.clocks.c_ck()) + }; + let stabilizer = StabilizerDevices { afes, adcs, @@ -833,7 +841,7 @@ pub fn setup( net: network_devices, adc_dac_timer: sampling_timer, timestamp_timer, - cycle_counter: CycleCounter::new(core.DWT, ccdr.clocks.c_ck()), + cycle_counter, }; // info!("Version {} {}", build_info::PKG_VERSION, build_info::GIT_VERSION.unwrap());