diff options
| author | Jomer.Dev <[email protected]> | 2025-11-27 23:17:47 +0100 |
|---|---|---|
| committer | Jomer.Dev <[email protected]> | 2025-11-27 23:17:47 +0100 |
| commit | 39e9e80150d937d48e287ef913e1b0673cba91b1 (patch) | |
| tree | d423480423d82e604e7e799a7fddd43c05c42ebf | |
| parent | e34c43d72b77e78cb971a73c59efa3e746db331f (diff) | |
Fmt files, add changelog entry
| -rw-r--r-- | embassy-stm32/CHANGELOG.md | 1 | ||||
| -rw-r--r-- | embassy-stm32/src/can/enums.rs | 28 | ||||
| -rw-r--r-- | embassy-stm32/src/can/util.rs | 10 |
3 files changed, 23 insertions, 16 deletions
diff --git a/embassy-stm32/CHANGELOG.md b/embassy-stm32/CHANGELOG.md index 4c38b0add..2b273482c 100644 --- a/embassy-stm32/CHANGELOG.md +++ b/embassy-stm32/CHANGELOG.md | |||
| @@ -84,6 +84,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 | |||
| 84 | - removal: ExtiInput no longer accepts AnyPin/AnyChannel; AnyChannel removed entirely | 84 | - removal: ExtiInput no longer accepts AnyPin/AnyChannel; AnyChannel removed entirely |
| 85 | - fix: build script ensures EXTI2_TSC is listed as the IRQ of EXTI2 even if the PAC doesn't | 85 | - fix: build script ensures EXTI2_TSC is listed as the IRQ of EXTI2 even if the PAC doesn't |
| 86 | - feat: stm32/lcd: added implementation | 86 | - feat: stm32/lcd: added implementation |
| 87 | - change: add error messages to can timing calculations ([#4961](https://github.com/embassy-rs/embassy/pull/4961)) | ||
| 87 | 88 | ||
| 88 | ## 0.4.0 - 2025-08-26 | 89 | ## 0.4.0 - 2025-08-26 |
| 89 | 90 | ||
diff --git a/embassy-stm32/src/can/enums.rs b/embassy-stm32/src/can/enums.rs index 0b2fd9901..c5900cadc 100644 --- a/embassy-stm32/src/can/enums.rs +++ b/embassy-stm32/src/can/enums.rs | |||
| @@ -88,33 +88,33 @@ pub enum RefCountOp { | |||
| 88 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | 88 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] |
| 89 | pub enum TimingCalcError { | 89 | pub enum TimingCalcError { |
| 90 | /// Bitrate is lower than 1000 | 90 | /// Bitrate is lower than 1000 |
| 91 | BitrateTooLow { | 91 | BitrateTooLow { |
| 92 | /// The set bitrate | 92 | /// The set bitrate |
| 93 | bitrate: u32 | 93 | bitrate: u32, |
| 94 | }, | 94 | }, |
| 95 | /// No solution possible | 95 | /// No solution possible |
| 96 | NoSolution { | 96 | NoSolution { |
| 97 | /// The sum of BS1 and BS2 | 97 | /// The sum of BS1 and BS2 |
| 98 | bs1_bs2_sum: u8 | 98 | bs1_bs2_sum: u8, |
| 99 | }, | 99 | }, |
| 100 | /// Prescaler is not 1 < prescaler < 1024 | 100 | /// Prescaler is not 1 < prescaler < 1024 |
| 101 | InvalidPrescaler { | 101 | InvalidPrescaler { |
| 102 | /// The calculated prescaler value | 102 | /// The calculated prescaler value |
| 103 | prescaler: u32 | 103 | prescaler: u32, |
| 104 | }, | 104 | }, |
| 105 | /// BS1 or BS2 are not in the range 0 < BSx < BSx_MAX | 105 | /// BS1 or BS2 are not in the range 0 < BSx < BSx_MAX |
| 106 | BSNotInRange { | 106 | BSNotInRange { |
| 107 | /// The value of BS1 | 107 | /// The value of BS1 |
| 108 | bs1: u8, | 108 | bs1: u8, |
| 109 | /// The value of BS2 | 109 | /// The value of BS2 |
| 110 | bs2: u8 | 110 | bs2: u8, |
| 111 | }, | 111 | }, |
| 112 | /// Final bitrate doesn't match the requested bitrate | 112 | /// Final bitrate doesn't match the requested bitrate |
| 113 | NoMatch { | 113 | NoMatch { |
| 114 | /// The requested bitrate | 114 | /// The requested bitrate |
| 115 | requested: u32, | 115 | requested: u32, |
| 116 | /// The calculated bitrate | 116 | /// The calculated bitrate |
| 117 | final_calculated: u32 | 117 | final_calculated: u32, |
| 118 | }, | 118 | }, |
| 119 | /// core::num::NonZeroUxx::new error | 119 | /// core::num::NonZeroUxx::new error |
| 120 | CoreNumNew, | 120 | CoreNumNew, |
diff --git a/embassy-stm32/src/can/util.rs b/embassy-stm32/src/can/util.rs index e93fe607d..beca4c34e 100644 --- a/embassy-stm32/src/can/util.rs +++ b/embassy-stm32/src/can/util.rs | |||
| @@ -19,7 +19,10 @@ pub struct NominalBitTiming { | |||
| 19 | } | 19 | } |
| 20 | 20 | ||
| 21 | /// Calculate nominal CAN bit timing based on CAN bitrate and periphial clock frequency | 21 | /// Calculate nominal CAN bit timing based on CAN bitrate and periphial clock frequency |
| 22 | pub fn calc_can_timings(periph_clock: crate::time::Hertz, can_bitrate: u32) -> Result<NominalBitTiming, TimingCalcError> { | 22 | pub fn calc_can_timings( |
| 23 | periph_clock: crate::time::Hertz, | ||
| 24 | can_bitrate: u32, | ||
| 25 | ) -> Result<NominalBitTiming, TimingCalcError> { | ||
| 23 | const BS1_MAX: u8 = 16; | 26 | const BS1_MAX: u8 = 16; |
| 24 | const BS2_MAX: u8 = 8; | 27 | const BS2_MAX: u8 = 8; |
| 25 | const MAX_SAMPLE_POINT_PERMILL: u16 = 900; | 28 | const MAX_SAMPLE_POINT_PERMILL: u16 = 900; |
| @@ -101,7 +104,10 @@ pub fn calc_can_timings(periph_clock: crate::time::Hertz, can_bitrate: u32) -> R | |||
| 101 | let calculated = periph_clock / (prescaler * (1 + bs1 + bs2) as u32); | 104 | let calculated = periph_clock / (prescaler * (1 + bs1 + bs2) as u32); |
| 102 | // Check if final bitrate matches the requested | 105 | // Check if final bitrate matches the requested |
| 103 | if can_bitrate != calculated { | 106 | if can_bitrate != calculated { |
| 104 | return Err(TimingCalcError::NoMatch { requested: can_bitrate, final_calculated: calculated }); | 107 | return Err(TimingCalcError::NoMatch { |
| 108 | requested: can_bitrate, | ||
| 109 | final_calculated: calculated, | ||
| 110 | }); | ||
| 105 | } | 111 | } |
| 106 | 112 | ||
| 107 | // One is recommended by DS-015, CANOpen, and DeviceNet | 113 | // One is recommended by DS-015, CANOpen, and DeviceNet |
