From 1b42953f032db9a9ec674dd3b4fa1b478e8bb505 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Mon, 28 Apr 2025 01:18:41 +0200 Subject: [PATCH] Revert "Stm32 can data len" --- embassy-stm32/src/can/bxcan/registers.rs | 4 ++-- embassy-stm32/src/can/fd/peripheral.rs | 4 ++-- embassy-stm32/src/can/frame.rs | 23 ++++++++++------------- embassy-stm32/src/opamp.rs | 6 ++---- 4 files changed, 16 insertions(+), 21 deletions(-) diff --git a/embassy-stm32/src/can/bxcan/registers.rs b/embassy-stm32/src/can/bxcan/registers.rs index c295b0f50..c5467dfe8 100644 --- a/embassy-stm32/src/can/bxcan/registers.rs +++ b/embassy-stm32/src/can/bxcan/registers.rs @@ -299,9 +299,9 @@ impl Registers { mb.tdtr().write(|w| w.set_dlc(frame.header().len() as u8)); mb.tdlr() - .write(|w| w.0 = u32::from_ne_bytes(unwrap!(frame.raw_data()[0..4].try_into()))); + .write(|w| w.0 = u32::from_ne_bytes(unwrap!(frame.data()[0..4].try_into()))); mb.tdhr() - .write(|w| w.0 = u32::from_ne_bytes(unwrap!(frame.raw_data()[4..8].try_into()))); + .write(|w| w.0 = u32::from_ne_bytes(unwrap!(frame.data()[4..8].try_into()))); let id: IdReg = frame.id().into(); mb.tir().write(|w| { w.0 = id.0; diff --git a/embassy-stm32/src/can/fd/peripheral.rs b/embassy-stm32/src/can/fd/peripheral.rs index 4873ee444..39c4112ad 100644 --- a/embassy-stm32/src/can/fd/peripheral.rs +++ b/embassy-stm32/src/can/fd/peripheral.rs @@ -75,7 +75,7 @@ impl Registers { let mailbox = self.tx_buffer_element(bufidx); mailbox.reset(); put_tx_header(mailbox, header); - put_tx_data(mailbox, buffer); + put_tx_data(mailbox, &buffer[..header.len() as usize]); // Set as ready to transmit self.regs.txbar().modify(|w| w.set_ar(bufidx, true)); @@ -190,7 +190,7 @@ impl Registers { DataLength::Fdcan(len) => len, DataLength::Classic(len) => len, }; - if len as usize > 8 { + if len as usize > ClassicData::MAX_DATA_LEN { return None; } diff --git a/embassy-stm32/src/can/frame.rs b/embassy-stm32/src/can/frame.rs index 0fbab053b..f621b8bd5 100644 --- a/embassy-stm32/src/can/frame.rs +++ b/embassy-stm32/src/can/frame.rs @@ -104,13 +104,15 @@ pub trait CanHeader: Sized { #[derive(Debug, Copy, Clone)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] pub struct ClassicData { - pub(crate) bytes: [u8; 8], + pub(crate) bytes: [u8; Self::MAX_DATA_LEN], } impl ClassicData { + pub(crate) const MAX_DATA_LEN: usize = 8; /// Creates a data payload from a raw byte slice. /// - /// Returns `FrameCreateError` if `data` is more than 8 bytes (which is the maximum). + /// Returns `None` if `data` is more than 64 bytes (which is the maximum) or + /// cannot be represented with an FDCAN DLC. pub fn new(data: &[u8]) -> Result { if data.len() > 8 { return Err(FrameCreateError::InvalidDataLength); @@ -209,17 +211,12 @@ impl Frame { /// Get reference to data pub fn data(&self) -> &[u8] { - &self.data.raw()[..self.can_header.len as usize] - } - - /// Get reference to underlying 8-byte raw data buffer, some bytes on the tail might be undefined. - pub fn raw_data(&self) -> &[u8] { - self.data.raw() + &self.data.raw() } /// Get mutable reference to data pub fn data_mut(&mut self) -> &mut [u8] { - &mut self.data.raw_mut()[..self.can_header.len as usize] + self.data.raw_mut() } /// Get priority of frame @@ -263,7 +260,7 @@ impl embedded_can::Frame for Frame { self.can_header.len as usize } fn data(&self) -> &[u8] { - &self.data() + &self.data.raw() } } @@ -408,12 +405,12 @@ impl FdFrame { /// Get reference to data pub fn data(&self) -> &[u8] { - &self.data.raw()[..self.can_header.len as usize] + &self.data.raw() } /// Get mutable reference to data pub fn data_mut(&mut self) -> &mut [u8] { - &mut self.data.raw_mut()[..self.can_header.len as usize] + self.data.raw_mut() } } @@ -451,7 +448,7 @@ impl embedded_can::Frame for FdFrame { self.can_header.len as usize } fn data(&self) -> &[u8] { - &self.data() + &self.data.raw() } } diff --git a/embassy-stm32/src/opamp.rs b/embassy-stm32/src/opamp.rs index b368df6c3..a76389495 100644 --- a/embassy-stm32/src/opamp.rs +++ b/embassy-stm32/src/opamp.rs @@ -422,13 +422,11 @@ impl<'d, T: Instance> OpAmp<'d, T> { T::regs().csr().modify(|w| match pair { OpAmpDifferentialPair::P => { - #[cfg(feature = "defmt")] - defmt::debug!("opamp p calibration. offset: {}", mid); + defmt::info!("p calibration. offset: {}", mid); w.set_trimoffsetp(mid); } OpAmpDifferentialPair::N => { - #[cfg(feature = "defmt")] - defmt::debug!("opamp n calibration. offset: {}", mid); + defmt::info!("n calibration. offset: {}", mid); w.set_trimoffsetn(mid); } });