From 2ef1ea584e282d71f55938646567180a12bd09de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Sn=C3=B6man?= Date: Wed, 29 Jan 2025 10:10:53 +0100 Subject: [PATCH 1/6] Probe-rs --- .cargo/config.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index 57084de..589d328 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,5 +1,5 @@ [target.thumbv8m.main-none-eabihf] -runner = 'arm-none-eabi-gdb' +runner = 'probe-rs run --connect-under-reset' rustflags = [ # LLD (shipped with the Rust toolchain) is used as the default linker "-C", "link-arg=-Tlink.x", From ebf2bc9a053e78eef666316954b0633f1b90596e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Sn=C3=B6man?= Date: Wed, 29 Jan 2025 10:13:27 +0100 Subject: [PATCH 2/6] Add defmt --- .cargo/config.toml | 1 + Cargo.toml | 3 ++- examples/blinky.rs | 5 +++-- examples/utilities/logger.rs | 22 ++++++++++++++++++++++ 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index 589d328..d2012bd 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -3,6 +3,7 @@ runner = 'probe-rs run --connect-under-reset' rustflags = [ # LLD (shipped with the Rust toolchain) is used as the default linker "-C", "link-arg=-Tlink.x", + "-C", "link-arg=-Tdefmt.x", ] [build] diff --git a/Cargo.toml b/Cargo.toml index 65fea4b..db1328d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -68,6 +68,7 @@ log = { version = "0.4.20", optional = true} [dev-dependencies] log = { version = "0.4.20"} cortex-m-rt = "0.7.3" +defmt-rtt = { version = "0.4.0" } panic-halt = "0.2.0" panic-rtt-target = { version = "0.1.0", features = ["cortex-m"] } cfg-if = "1.0.0" @@ -76,6 +77,7 @@ lazy_static = { version = "1.4.0", features = ["spin_no_std"] } cortex-m-log = { version = "0.8.0", features = ["itm", "semihosting", "log-integration"] } cortex-m-semihosting = "0.5.0" panic-itm = { version = "~0.4.1" } +panic-probe = "0.3.2" panic-semihosting = "0.6" [profile.release] @@ -86,7 +88,6 @@ opt-level = "s" # optimize for binary size [[example]] name = "blinky" -required-features = ["stm32h503"] [[example]] name = "i2c" diff --git a/examples/blinky.rs b/examples/blinky.rs index 142f462..c1cab03 100644 --- a/examples/blinky.rs +++ b/examples/blinky.rs @@ -8,6 +8,7 @@ use cortex_m_rt::entry; use embedded_hal::delay::DelayNs; use fugit::SecsDurationU32; use stm32h5xx_hal::{delay::Delay, pac, prelude::*}; +use utilities::logger::info; #[entry] fn main() -> ! { @@ -31,10 +32,10 @@ fn main() -> ! { loop { led.set_low(); - log::info!("Off"); + info!("Off"); delay.delay_ms(duration); led.set_high(); - log::info!("On"); + info!("On"); delay.delay_ms(duration); } } diff --git a/examples/utilities/logger.rs b/examples/utilities/logger.rs index 400a9b3..e47f78b 100644 --- a/examples/utilities/logger.rs +++ b/examples/utilities/logger.rs @@ -1,5 +1,16 @@ #![cfg_attr(feature = "log-itm", allow(unsafe_code))] +cfg_if::cfg_if! { + if #[cfg(feature = "defmt")] { + #[allow(unused_imports)] + pub use defmt::{info, trace, warn, debug, error}; + + } else { + #[allow(unused_imports)] + pub use log::{info, trace, warn, debug, error}; + } +} + cfg_if::cfg_if! { if #[cfg(any(feature = "log-itm"))] { use panic_itm as _; @@ -32,6 +43,17 @@ cfg_if::cfg_if! { } } + else if #[cfg(feature = "defmt")] { + use defmt_rtt as _; // global logger + use panic_probe as _; + #[allow(unused_imports)] + pub use defmt::Logger; + #[allow(unused_imports)] + pub use defmt::println; + + #[allow(dead_code)] + pub fn init() {} + } else if #[cfg(any(feature = "log-rtt"))] { use panic_rtt_target as _; From 7ebc457e5f82512afda33a80415a09b264b78158 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Sn=C3=B6man?= Date: Tue, 27 May 2025 11:20:02 +0200 Subject: [PATCH 3/6] Added debugging attributes --- src/gpio/dynamic.rs | 1 + src/rcc/pll.rs | 3 +++ src/rcc/reset_reason.rs | 1 + 3 files changed, 5 insertions(+) diff --git a/src/gpio/dynamic.rs b/src/gpio/dynamic.rs index 968a2f3..247a972 100644 --- a/src/gpio/dynamic.rs +++ b/src/gpio/dynamic.rs @@ -25,6 +25,7 @@ pub enum Dynamic { /// Error for [DynamicPin] #[derive(Debug, PartialEq, Eq)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum PinModeError { /// For operations unsupported in current mode IncorrectMode, diff --git a/src/rcc/pll.rs b/src/rcc/pll.rs index 1c67be4..c4bef08 100644 --- a/src/rcc/pll.rs +++ b/src/rcc/pll.rs @@ -43,6 +43,7 @@ impl Default for PllConfig { } #[derive(Debug)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] struct VcoRange { output_range: RangeInclusive, input_range: RangeInclusive, @@ -61,12 +62,14 @@ const VCO_RANGE_WIDE: VcoRange = VcoRange { }; #[derive(Debug)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] struct PllOutput { ck: u32, div: u32, } #[derive(Debug)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] struct PllSetup { vco_range: VcoRange, vco_out_target: u32, diff --git a/src/rcc/reset_reason.rs b/src/rcc/reset_reason.rs index d8b66ba..6e2ccc3 100644 --- a/src/rcc/reset_reason.rs +++ b/src/rcc/reset_reason.rs @@ -54,6 +54,7 @@ pub fn get_reset_reason(rcc: &mut crate::stm32::RCC) -> ResetReason { /// Gives the reason why the mcu was reset #[derive(Debug, Copy, Clone)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum ResetReason { /// The mcu went from not having power to having power and resetting PowerOnReset, From 13d14e20e4126bfd239eb99615f1c96e30c1644c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Sn=C3=B6man?= Date: Tue, 27 May 2025 11:49:13 +0200 Subject: [PATCH 4/6] Added defmt to ci --- .github/workflows/ci.yml | 2 +- src/rcc/pll.rs | 2 -- src/rcc/reset_reason.rs | 1 - 3 files changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 235cddf..b32b9aa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,7 +21,7 @@ jobs: - stm32h563 - stm32h573 env: # Peripheral Feature flags - FLAGS: rt,log + FLAGS: rt,log,defmt steps: - uses: actions/checkout@v4 diff --git a/src/rcc/pll.rs b/src/rcc/pll.rs index c4bef08..ee7a7e2 100644 --- a/src/rcc/pll.rs +++ b/src/rcc/pll.rs @@ -43,7 +43,6 @@ impl Default for PllConfig { } #[derive(Debug)] -#[cfg_attr(feature = "defmt", derive(defmt::Format))] struct VcoRange { output_range: RangeInclusive, input_range: RangeInclusive, @@ -69,7 +68,6 @@ struct PllOutput { } #[derive(Debug)] -#[cfg_attr(feature = "defmt", derive(defmt::Format))] struct PllSetup { vco_range: VcoRange, vco_out_target: u32, diff --git a/src/rcc/reset_reason.rs b/src/rcc/reset_reason.rs index 6e2ccc3..d8b66ba 100644 --- a/src/rcc/reset_reason.rs +++ b/src/rcc/reset_reason.rs @@ -54,7 +54,6 @@ pub fn get_reset_reason(rcc: &mut crate::stm32::RCC) -> ResetReason { /// Gives the reason why the mcu was reset #[derive(Debug, Copy, Clone)] -#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum ResetReason { /// The mcu went from not having power to having power and resetting PowerOnReset, From 84c149e246aff54fb86eac640715fd70f67383d1 Mon Sep 17 00:00:00 2001 From: Albin Hedman Date: Wed, 28 May 2025 21:56:26 +0200 Subject: [PATCH 5/6] Update CI --- .github/workflows/ci.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b32b9aa..a615547 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,8 +20,11 @@ jobs: - stm32h562 - stm32h563 - stm32h573 + logger: + - log + - defmt env: # Peripheral Feature flags - FLAGS: rt,log,defmt + FLAGS: rt steps: - uses: actions/checkout@v4 @@ -42,6 +45,6 @@ jobs: - name: Install thumbv8m rust target run: rustup target add thumbv8m.main-none-eabihf - name: Build - run: cargo build --verbose --release --examples --target thumbv8m.main-none-eabihf --features ${{ matrix.mcu }},${{ env.FLAGS }} + run: cargo build --verbose --release --examples --target thumbv8m.main-none-eabihf --features ${{ matrix.mcu }},${{ matrix.logger }},${{ env.FLAGS }} - name: Test - run: cargo test --lib --target x86_64-unknown-linux-gnu --features ${{ matrix.mcu }},${{ env.FLAGS }} + run: cargo test --lib --target x86_64-unknown-linux-gnu --features ${{ matrix.mcu }},${{ matrix.logger }},${{ env.FLAGS }} From e8ac5283e07969df002e3f01aa0b159004320a0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Sn=C3=B6man?= Date: Mon, 2 Jun 2025 09:24:04 +0200 Subject: [PATCH 6/6] Updated defmt to 1.0.0 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index db1328d..24c3e0c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -61,7 +61,7 @@ cortex-m = { version = "^0.7.7", features = ["critical-section-single-core"] } stm32h5 = { package = "stm32h5", version = "0.16.0" } fugit = "0.3.7" embedded-hal = "1.0.0" -defmt = { version = "0.3.8", optional = true } +defmt = { version = "1.0.0", optional = true } paste = "1.0.15" log = { version = "0.4.20", optional = true}