diff --git a/examples/embassy/Cargo.toml b/examples/embassy/Cargo.toml index 300a7d7..b37dc51 100644 --- a/examples/embassy/Cargo.toml +++ b/examples/embassy/Cargo.toml @@ -4,6 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] +cortex-m = "0.7" cortex-m-rt = "0.7" cfg-if = "1" embedded-io = "0.6" diff --git a/examples/embassy/src/bin/can.rs b/examples/embassy/src/bin/can.rs index 588d5a0..4234931 100644 --- a/examples/embassy/src/bin/can.rs +++ b/examples/embassy/src/bin/can.rs @@ -58,29 +58,31 @@ async fn main(_spawner: Spawner) { // Base channel which has dedicated mask. let mut rx_base = CanRx::new(channels.take(14).unwrap()); let standard_id = can::StandardId::new(0x42).unwrap(); - let send_frame = CanFrame::Normal( - CanFrameNormal::new(can::Id::Standard(standard_id), &[1, 2, 3, 4]).unwrap(), - ); + let send_data = &[1, 2, 3, 4]; + let send_frame = + CanFrame::Normal(CanFrameNormal::new(can::Id::Standard(standard_id), send_data).unwrap()); rx_dedicated .configure_for_reception_with_standard_id(standard_id, false) .unwrap(); rx_base.configure_for_reception(); - defmt::info!("sending CAN frame"); + defmt::info!("sending CAN frame with ID 0x42 and data {}", send_data); tx.transmit_frame(send_frame).unwrap(); let frame = nb::block!(rx_dedicated.receive(true)).expect("invalid CAN rx state"); let err_counter = can.read_error_counters(); - defmt::info!( - "error count tx {}, error count rx {}", - err_counter.transmit(), - err_counter.receive() - ); - let diag = can.read_error_diagnostics(); - defmt::info!("EFID: {}, EBID: {}", diag.efid(), diag.ebid()); + if err_counter.transmit() > 0 || err_counter.receive() > 0 { + defmt::warn!( + "error count tx {}, error count rx {}", + err_counter.transmit(), + err_counter.receive() + ); + let diag = can.read_error_diagnostics(); + defmt::warn!("EFID: {}, EBID: {}", diag.efid(), diag.ebid()); + } match frame { CanFrame::Normal(can_frame_normal) => match can_frame_normal.id() { can::Id::Standard(standard_id) => { defmt::info!( - "received CAN frame with ID {} and data {}", + "received CAN frame with ID {:#X} and data {}", standard_id.as_raw(), can_frame_normal.data() ); @@ -91,7 +93,9 @@ async fn main(_spawner: Spawner) { defmt::error!("received unexpected CAN remote frame"); } } - loop {} + loop { + cortex_m::asm::nop(); + } } #[interrupt]