diff --git a/.cargo/config.toml b/.cargo/config.toml index 57084de..d2012bd 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,8 +1,9 @@ [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", + "-C", "link-arg=-Tdefmt.x", ] [build] diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 235cddf..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 + 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 }} diff --git a/Cargo.toml b/Cargo.toml index 65fea4b..24c3e0c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -61,13 +61,14 @@ 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} [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 _; 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..ee7a7e2 100644 --- a/src/rcc/pll.rs +++ b/src/rcc/pll.rs @@ -61,6 +61,7 @@ const VCO_RANGE_WIDE: VcoRange = VcoRange { }; #[derive(Debug)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] struct PllOutput { ck: u32, div: u32,