some cleaning

This commit is contained in:
Robin Müller 2025-05-13 12:36:01 +02:00
parent 172e319720
commit 37ec9114b3
Signed by: muellerr
GPG Key ID: A649FB78196E3849
2 changed files with 18 additions and 13 deletions

View File

@ -4,6 +4,7 @@ version = "0.1.0"
edition = "2021" edition = "2021"
[dependencies] [dependencies]
cortex-m = "0.7"
cortex-m-rt = "0.7" cortex-m-rt = "0.7"
cfg-if = "1" cfg-if = "1"
embedded-io = "0.6" embedded-io = "0.6"

View File

@ -58,29 +58,31 @@ async fn main(_spawner: Spawner) {
// Base channel which has dedicated mask. // Base channel which has dedicated mask.
let mut rx_base = CanRx::new(channels.take(14).unwrap()); let mut rx_base = CanRx::new(channels.take(14).unwrap());
let standard_id = can::StandardId::new(0x42).unwrap(); let standard_id = can::StandardId::new(0x42).unwrap();
let send_frame = CanFrame::Normal( let send_data = &[1, 2, 3, 4];
CanFrameNormal::new(can::Id::Standard(standard_id), &[1, 2, 3, 4]).unwrap(), let send_frame =
); CanFrame::Normal(CanFrameNormal::new(can::Id::Standard(standard_id), send_data).unwrap());
rx_dedicated rx_dedicated
.configure_for_reception_with_standard_id(standard_id, false) .configure_for_reception_with_standard_id(standard_id, false)
.unwrap(); .unwrap();
rx_base.configure_for_reception(); 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(); tx.transmit_frame(send_frame).unwrap();
let frame = nb::block!(rx_dedicated.receive(true)).expect("invalid CAN rx state"); let frame = nb::block!(rx_dedicated.receive(true)).expect("invalid CAN rx state");
let err_counter = can.read_error_counters(); let err_counter = can.read_error_counters();
defmt::info!( if err_counter.transmit() > 0 || err_counter.receive() > 0 {
defmt::warn!(
"error count tx {}, error count rx {}", "error count tx {}, error count rx {}",
err_counter.transmit(), err_counter.transmit(),
err_counter.receive() err_counter.receive()
); );
let diag = can.read_error_diagnostics(); let diag = can.read_error_diagnostics();
defmt::info!("EFID: {}, EBID: {}", diag.efid(), diag.ebid()); defmt::warn!("EFID: {}, EBID: {}", diag.efid(), diag.ebid());
}
match frame { match frame {
CanFrame::Normal(can_frame_normal) => match can_frame_normal.id() { CanFrame::Normal(can_frame_normal) => match can_frame_normal.id() {
can::Id::Standard(standard_id) => { can::Id::Standard(standard_id) => {
defmt::info!( defmt::info!(
"received CAN frame with ID {} and data {}", "received CAN frame with ID {:#X} and data {}",
standard_id.as_raw(), standard_id.as_raw(),
can_frame_normal.data() can_frame_normal.data()
); );
@ -91,7 +93,9 @@ async fn main(_spawner: Spawner) {
defmt::error!("received unexpected CAN remote frame"); defmt::error!("received unexpected CAN remote frame");
} }
} }
loop {} loop {
cortex_m::asm::nop();
}
} }
#[interrupt] #[interrupt]