Skip to content

Commit

Permalink
Use defmt
Browse files Browse the repository at this point in the history
  • Loading branch information
gdobato committed May 16, 2024
1 parent d5ab2e3 commit 1747fea
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 43 deletions.
11 changes: 9 additions & 2 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ usb_echo-bin = "oe usb_echo --release -- -O binary target/thumbv7em-none-eabihf/
target = "thumbv7em-none-eabihf" # Cortex-M4F and Cortex-M7F (with FPU)

rustflags = [
# Use LLD as the default linker
"-C", "link-arg=-Tlink.x",
"-C",
"link-arg=-Tlink.x",
"-C",
"link-arg=--nmagic",
"-C",
"link-arg=-Tdefmt.x",
]

[env]
DEFMT_LOG = "debug"
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ stm32h7xx-hal = { version = "0.16.0", features = [
"rt",
"usb_hs",
] }
rtt-target = { version = "0.4.0" }
defmt = "=0.3.7"
defmt-rtt = "0.4.1"
panic-probe = { version = "0.3", features = ["print-defmt"] }

[dev-dependencies]
rtic = { version = "2.1.1", features = ["thumbv7-backend"] }
Expand Down
4 changes: 3 additions & 1 deletion Embed.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ enabled = true
halt_afterwards = false

[default.rtt]
enabled = true
enabled = true

channels = [{ up = 0, down = 0, format = "Defmt" }]
15 changes: 4 additions & 11 deletions examples/blinky.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
#![no_std]
#![no_main]

#[allow(unused_imports)]
use defmt::info;
use portenta_h7::{
board::{self, Board},
led, log, log_init,
led,
};
use rtic::app;
use rtic_monotonics::systick::*;
Expand All @@ -30,8 +30,7 @@ mod app {

#[init]
fn init(cx: init::Context) -> (Shared, Local) {
log_init!();

info!("Init");
let systick_mono_token = rtic_monotonics::create_systick_token!();
Systick::start(
cx.core.SYST,
Expand All @@ -48,7 +47,7 @@ mod app {
} = Board::take();

#[cfg(debug_assertions)]
log!("spawning tasks");
info!("spawning tasks");
let _ = blink_led_red::spawn();
let _ = blink_led_green::spawn();
let _ = blink_led_blue::spawn();
Expand All @@ -66,8 +65,6 @@ mod app {
#[task(local = [led_red])]
async fn blink_led_red(cx: blink_led_red::Context) {
loop {
#[cfg(debug_assertions)]
log!("toggling {:?}", cx.local.led_red);
cx.local.led_red.toggle();
Systick::delay(500.millis()).await;
}
Expand All @@ -76,8 +73,6 @@ mod app {
#[task(local = [led_green])]
async fn blink_led_green(cx: blink_led_green::Context) {
loop {
#[cfg(debug_assertions)]
log!("toggling {:?}", cx.local.led_green);
cx.local.led_green.toggle();
Systick::delay(1000.millis()).await;
}
Expand All @@ -86,8 +81,6 @@ mod app {
#[task(local = [led_blue])]
async fn blink_led_blue(cx: blink_led_blue::Context) {
loop {
#[cfg(debug_assertions)]
log!("toggling {:?}", cx.local.led_blue);
cx.local.led_blue.toggle();
Systick::delay(1000.millis()).await;
}
Expand Down
13 changes: 6 additions & 7 deletions examples/usb_echo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
#![no_std]
#![no_main]

use defmt::{error, info};
use portenta_h7::{
board::{self, Board, UsbBus, USB},
led::{self, Led},
log, log_init,
};
use rtic::app;
use rtic_monotonics::systick::*;
Expand Down Expand Up @@ -39,7 +39,7 @@ mod app {

#[init]
fn init(cx: init::Context) -> (Shared, Local) {
log_init!();
info!("Init");

let systick_mono_token = rtic_monotonics::create_systick_token!();

Expand Down Expand Up @@ -92,8 +92,7 @@ mod app {
// Read from reception fifo
match usb_serial_port.read_packet(&mut app_buff) {
Ok(cnt) if cnt > 0 => {
#[cfg(debug_assertions)]
log!(
info!(
"Received {} bytes: {}",
cnt,
core::str::from_utf8(&app_buff[..cnt]).unwrap_or("not valid")
Expand All @@ -102,7 +101,7 @@ mod app {
match usb_serial_port.write_packet(&app_buff[..cnt]) {
Ok(_) => (),
Err(err) => {
log!("Error in transmission: {:?}", err)
error!("Error in transmission: {:?}", err as u8)
}
}
}
Expand All @@ -114,14 +113,14 @@ mod app {
match usb_dev.state() {
// Transition to enumeration
UsbDeviceState::Configured if previous_state == UsbDeviceState::Addressed => {
log!("Enumeration completed");
info!("Enumeration completed");
cx.local.led_blue.on();
}
// Already enumerated
UsbDeviceState::Configured => {}
// Enumeration lost
_ if previous_state == UsbDeviceState::Configured => {
log!("Enumeration lost");
info!("Enumeration lost");
cx.local.led_blue.off();
}
_ => (),
Expand Down
5 changes: 0 additions & 5 deletions src/board.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//! board

#[allow(unused)]
use crate::log;
use crate::{hal, led, sys};
use core::sync::atomic::{AtomicBool, Ordering};
pub use hal::usb_hs::{UsbBus, USB1_ULPI as USB};
Expand All @@ -24,9 +22,6 @@ impl Board {
}

fn setup() -> Self {
#[cfg(debug_assertions)]
log!("Board init");

// Reset previous configuration and enable external oscillator as HSE source (25 MHz)
sys::Clk::new().reset().enable_ext_clock();
let dp = pac::Peripherals::take().unwrap();
Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
pub mod board;
pub mod interrupt;
pub mod led;
pub mod panic;
mod sys;
pub use cortex_m_rt::entry;
#[allow(unused_imports)]
pub use rtt_target::{rprintln as log, rtt_init_print as log_init};
#[allow(unused)]
use defmt_rtt as _;
use panic_probe as _;
pub use stm32h7xx_hal as hal;
13 changes: 0 additions & 13 deletions src/panic.rs

This file was deleted.

0 comments on commit 1747fea

Please sign in to comment.