diff options
| author | Ulf Lilleengen <[email protected]> | 2025-05-27 05:53:07 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-05-27 05:53:07 +0000 |
| commit | 1c9de3491d97fca1dd6760c2e5ede824c1fd9564 (patch) | |
| tree | 055ff40ea73cd4e8e9dc093e579929d00f469a74 | |
| parent | e447795f76276d5f2db30430bf39b812b0f054d1 (diff) | |
| parent | b9f7478ada241731c52a58cab8c4caa295354467 (diff) | |
Merge pull request #4255 from kpfleming/improve-stm32-crc-hal
stm32: Improvements to CRC HAL.
| -rw-r--r-- | embassy-stm32/src/crc/v1.rs | 16 | ||||
| -rw-r--r-- | embassy-stm32/src/crc/v2v3.rs | 39 |
2 files changed, 25 insertions, 30 deletions
diff --git a/embassy-stm32/src/crc/v1.rs b/embassy-stm32/src/crc/v1.rs index a78b3c2b7..13e5263de 100644 --- a/embassy-stm32/src/crc/v1.rs +++ b/embassy-stm32/src/crc/v1.rs | |||
| @@ -23,22 +23,16 @@ impl<'d> Crc<'d> { | |||
| 23 | PAC_CRC.cr().write(|w| w.set_reset(true)); | 23 | PAC_CRC.cr().write(|w| w.set_reset(true)); |
| 24 | } | 24 | } |
| 25 | 25 | ||
| 26 | /// Feeds a word to the peripheral and returns the current CRC value | 26 | /// Feeds a word into the CRC peripheral. Returns the computed CRC. |
| 27 | pub fn feed_word(&mut self, word: u32) -> u32 { | 27 | pub fn feed_word(&mut self, word: u32) -> u32 { |
| 28 | // write a single byte to the device, and return the result | 28 | // write a single byte to the device, and return the result |
| 29 | #[cfg(not(crc_v1))] | ||
| 30 | PAC_CRC.dr32().write_value(word); | ||
| 31 | #[cfg(crc_v1)] | ||
| 32 | PAC_CRC.dr().write_value(word); | 29 | PAC_CRC.dr().write_value(word); |
| 33 | self.read() | 30 | self.read() |
| 34 | } | 31 | } |
| 35 | 32 | ||
| 36 | /// Feed a slice of words to the peripheral and return the result. | 33 | /// Feeds a slice of words into the CRC peripheral. Returns the computed CRC. |
| 37 | pub fn feed_words(&mut self, words: &[u32]) -> u32 { | 34 | pub fn feed_words(&mut self, words: &[u32]) -> u32 { |
| 38 | for word in words { | 35 | for word in words { |
| 39 | #[cfg(not(crc_v1))] | ||
| 40 | PAC_CRC.dr32().write_value(*word); | ||
| 41 | #[cfg(crc_v1)] | ||
| 42 | PAC_CRC.dr().write_value(*word); | 36 | PAC_CRC.dr().write_value(*word); |
| 43 | } | 37 | } |
| 44 | 38 | ||
| @@ -46,12 +40,6 @@ impl<'d> Crc<'d> { | |||
| 46 | } | 40 | } |
| 47 | 41 | ||
| 48 | /// Read the CRC result value. | 42 | /// Read the CRC result value. |
| 49 | #[cfg(not(crc_v1))] | ||
| 50 | pub fn read(&self) -> u32 { | ||
| 51 | PAC_CRC.dr32().read() | ||
| 52 | } | ||
| 53 | /// Read the CRC result value. | ||
| 54 | #[cfg(crc_v1)] | ||
| 55 | pub fn read(&self) -> u32 { | 43 | pub fn read(&self) -> u32 { |
| 56 | PAC_CRC.dr().read() | 44 | PAC_CRC.dr().read() |
| 57 | } | 45 | } |
diff --git a/embassy-stm32/src/crc/v2v3.rs b/embassy-stm32/src/crc/v2v3.rs index c94c9f380..d834d0971 100644 --- a/embassy-stm32/src/crc/v2v3.rs +++ b/embassy-stm32/src/crc/v2v3.rs | |||
| @@ -9,7 +9,7 @@ pub struct Crc<'d> { | |||
| 9 | _config: Config, | 9 | _config: Config, |
| 10 | } | 10 | } |
| 11 | 11 | ||
| 12 | /// CRC configuration errlr | 12 | /// CRC configuration error |
| 13 | #[derive(Debug)] | 13 | #[derive(Debug)] |
| 14 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | 14 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] |
| 15 | pub enum ConfigError { | 15 | pub enum ConfigError { |
| @@ -34,9 +34,9 @@ pub enum InputReverseConfig { | |||
| 34 | None, | 34 | None, |
| 35 | /// Reverse bytes | 35 | /// Reverse bytes |
| 36 | Byte, | 36 | Byte, |
| 37 | /// Reverse 16-bit halfwords. | 37 | /// Reverse 16-bit halfwords |
| 38 | Halfword, | 38 | Halfword, |
| 39 | /// Reverse 32-bit words. | 39 | /// Reverse 32-bit words |
| 40 | Word, | 40 | Word, |
| 41 | } | 41 | } |
| 42 | 42 | ||
| @@ -127,45 +127,52 @@ impl<'d> Crc<'d> { | |||
| 127 | PolySize::Width32 => vals::Polysize::POLYSIZE32, | 127 | PolySize::Width32 => vals::Polysize::POLYSIZE32, |
| 128 | }); | 128 | }); |
| 129 | }); | 129 | }); |
| 130 | } | ||
| 130 | 131 | ||
| 131 | self.reset(); | 132 | /// Read the CRC result value. |
| 133 | pub fn read(&self) -> u32 { | ||
| 134 | PAC_CRC.dr32().read() | ||
| 132 | } | 135 | } |
| 133 | 136 | ||
| 134 | /// Feeds a byte into the CRC peripheral. Returns the computed checksum. | 137 | /// Feeds a byte into the CRC peripheral. Returns the computed CRC. |
| 135 | pub fn feed_byte(&mut self, byte: u8) -> u32 { | 138 | pub fn feed_byte(&mut self, byte: u8) -> u32 { |
| 136 | PAC_CRC.dr8().write_value(byte); | 139 | PAC_CRC.dr8().write_value(byte); |
| 137 | PAC_CRC.dr32().read() | 140 | self.read() |
| 138 | } | 141 | } |
| 139 | 142 | ||
| 140 | /// Feeds an slice of bytes into the CRC peripheral. Returns the computed checksum. | 143 | /// Feeds a slice of bytes into the CRC peripheral. Returns the computed CRC. |
| 141 | pub fn feed_bytes(&mut self, bytes: &[u8]) -> u32 { | 144 | pub fn feed_bytes(&mut self, bytes: &[u8]) -> u32 { |
| 142 | for byte in bytes { | 145 | for byte in bytes { |
| 143 | PAC_CRC.dr8().write_value(*byte); | 146 | PAC_CRC.dr8().write_value(*byte); |
| 144 | } | 147 | } |
| 145 | PAC_CRC.dr32().read() | 148 | self.read() |
| 146 | } | 149 | } |
| 147 | /// Feeds a halfword into the CRC peripheral. Returns the computed checksum. | 150 | |
| 151 | /// Feeds a halfword into the CRC peripheral. Returns the computed CRC. | ||
| 148 | pub fn feed_halfword(&mut self, halfword: u16) -> u32 { | 152 | pub fn feed_halfword(&mut self, halfword: u16) -> u32 { |
| 149 | PAC_CRC.dr16().write_value(halfword); | 153 | PAC_CRC.dr16().write_value(halfword); |
| 150 | PAC_CRC.dr32().read() | 154 | self.read() |
| 151 | } | 155 | } |
| 152 | /// Feeds an slice of halfwords into the CRC peripheral. Returns the computed checksum. | 156 | |
| 157 | /// Feeds a slice of halfwords into the CRC peripheral. Returns the computed CRC. | ||
| 153 | pub fn feed_halfwords(&mut self, halfwords: &[u16]) -> u32 { | 158 | pub fn feed_halfwords(&mut self, halfwords: &[u16]) -> u32 { |
| 154 | for halfword in halfwords { | 159 | for halfword in halfwords { |
| 155 | PAC_CRC.dr16().write_value(*halfword); | 160 | PAC_CRC.dr16().write_value(*halfword); |
| 156 | } | 161 | } |
| 157 | PAC_CRC.dr32().read() | 162 | self.read() |
| 158 | } | 163 | } |
| 159 | /// Feeds a words into the CRC peripheral. Returns the computed checksum. | 164 | |
| 165 | /// Feeds a word into the CRC peripheral. Returns the computed CRC. | ||
| 160 | pub fn feed_word(&mut self, word: u32) -> u32 { | 166 | pub fn feed_word(&mut self, word: u32) -> u32 { |
| 161 | PAC_CRC.dr32().write_value(word as u32); | 167 | PAC_CRC.dr32().write_value(word as u32); |
| 162 | PAC_CRC.dr32().read() | 168 | self.read() |
| 163 | } | 169 | } |
| 164 | /// Feeds an slice of words into the CRC peripheral. Returns the computed checksum. | 170 | |
| 171 | /// Feeds a slice of words into the CRC peripheral. Returns the computed CRC. | ||
| 165 | pub fn feed_words(&mut self, words: &[u32]) -> u32 { | 172 | pub fn feed_words(&mut self, words: &[u32]) -> u32 { |
| 166 | for word in words { | 173 | for word in words { |
| 167 | PAC_CRC.dr32().write_value(*word as u32); | 174 | PAC_CRC.dr32().write_value(*word as u32); |
| 168 | } | 175 | } |
| 169 | PAC_CRC.dr32().read() | 176 | self.read() |
| 170 | } | 177 | } |
| 171 | } | 178 | } |
