aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embassy-stm32/CHANGELOG.md1
-rw-r--r--embassy-stm32/src/adc/adc4.rs3
-rw-r--r--embassy-stm32/src/adc/c0.rs3
-rw-r--r--embassy-stm32/src/adc/g4.rs3
-rw-r--r--embassy-stm32/src/adc/v2.rs3
-rw-r--r--embassy-stm32/src/adc/v4.rs3
6 files changed, 11 insertions, 5 deletions
diff --git a/embassy-stm32/CHANGELOG.md b/embassy-stm32/CHANGELOG.md
index a6ee5c4b8..716c169e1 100644
--- a/embassy-stm32/CHANGELOG.md
+++ b/embassy-stm32/CHANGELOG.md
@@ -31,6 +31,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
31- feat: stm32/usart: add `eager_reads` option to control if buffered readers return as soon as possible or after more data is available ([#4668](https://github.com/embassy-rs/embassy/pull/4668)) 31- feat: stm32/usart: add `eager_reads` option to control if buffered readers return as soon as possible or after more data is available ([#4668](https://github.com/embassy-rs/embassy/pull/4668))
32- feat: stm32/usart: add `de_assertion_time` and `de_deassertion_time` config options 32- feat: stm32/usart: add `de_assertion_time` and `de_deassertion_time` config options
33- change: stm32/uart: BufferedUartRx now returns all available bytes from the internal buffer 33- change: stm32/uart: BufferedUartRx now returns all available bytes from the internal buffer
34- fix: stm32/adc: Calculate the ADC prescaler in a way that it allows for the max frequency to be reached
34 35
35## 0.4.0 - 2025-08-26 36## 0.4.0 - 2025-08-26
36 37
diff --git a/embassy-stm32/src/adc/adc4.rs b/embassy-stm32/src/adc/adc4.rs
index 255dc7956..1302dffb8 100644
--- a/embassy-stm32/src/adc/adc4.rs
+++ b/embassy-stm32/src/adc/adc4.rs
@@ -128,7 +128,8 @@ enum Prescaler {
128 128
129impl Prescaler { 129impl Prescaler {
130 fn from_ker_ck(frequency: Hertz) -> Self { 130 fn from_ker_ck(frequency: Hertz) -> Self {
131 let raw_prescaler = frequency.0 / MAX_ADC_CLK_FREQ.0; 131 // Calculate prescaler in a way where the clock can hit MAX CLK
132 let raw_prescaler = frequency.0.saturating_sub(1) / MAX_ADC_CLK_FREQ.0;
132 match raw_prescaler { 133 match raw_prescaler {
133 0 => Self::NotDivided, 134 0 => Self::NotDivided,
134 1 => Self::DividedBy2, 135 1 => Self::DividedBy2,
diff --git a/embassy-stm32/src/adc/c0.rs b/embassy-stm32/src/adc/c0.rs
index f2837a8f1..bd9a3e2c6 100644
--- a/embassy-stm32/src/adc/c0.rs
+++ b/embassy-stm32/src/adc/c0.rs
@@ -66,7 +66,8 @@ pub enum Prescaler {
66 66
67impl Prescaler { 67impl Prescaler {
68 fn from_ker_ck(frequency: Hertz) -> Self { 68 fn from_ker_ck(frequency: Hertz) -> Self {
69 let raw_prescaler = frequency.0 / MAX_ADC_CLK_FREQ.0; 69 // Calculate prescaler in a way where the clock can hit MAX CLK
70 let raw_prescaler = frequency.0.saturating_sub(1) / MAX_ADC_CLK_FREQ.0;
70 match raw_prescaler { 71 match raw_prescaler {
71 0 => Self::NotDivided, 72 0 => Self::NotDivided,
72 1 => Self::DividedBy2, 73 1 => Self::DividedBy2,
diff --git a/embassy-stm32/src/adc/g4.rs b/embassy-stm32/src/adc/g4.rs
index 43498966f..ac0a6196f 100644
--- a/embassy-stm32/src/adc/g4.rs
+++ b/embassy-stm32/src/adc/g4.rs
@@ -72,7 +72,8 @@ enum Prescaler {
72 72
73impl Prescaler { 73impl Prescaler {
74 fn from_ker_ck(frequency: Hertz) -> Self { 74 fn from_ker_ck(frequency: Hertz) -> Self {
75 let raw_prescaler = frequency.0 / MAX_ADC_CLK_FREQ.0; 75 // Calculate prescaler in a way where the clock can hit MAX CLK
76 let raw_prescaler = frequency.0.saturating_sub(1) / MAX_ADC_CLK_FREQ.0;
76 match raw_prescaler { 77 match raw_prescaler {
77 0 => Self::NotDivided, 78 0 => Self::NotDivided,
78 1 => Self::DividedBy2, 79 1 => Self::DividedBy2,
diff --git a/embassy-stm32/src/adc/v2.rs b/embassy-stm32/src/adc/v2.rs
index e94a25b24..57f252e13 100644
--- a/embassy-stm32/src/adc/v2.rs
+++ b/embassy-stm32/src/adc/v2.rs
@@ -71,7 +71,8 @@ impl Prescaler {
71 // Datasheet for both F4 and F7 specifies min frequency 0.6 MHz, typ freq. 30 MHz and max 36 MHz. 71 // Datasheet for both F4 and F7 specifies min frequency 0.6 MHz, typ freq. 30 MHz and max 36 MHz.
72 #[cfg(not(stm32f2))] 72 #[cfg(not(stm32f2))]
73 const MAX_FREQUENCY: Hertz = Hertz(36_000_000); 73 const MAX_FREQUENCY: Hertz = Hertz(36_000_000);
74 let raw_div = freq.0 / MAX_FREQUENCY.0; 74 // Calculate prescaler divider including MAX_FREQ
75 let raw_div = freq.0.saturating_sub(1) / MAX_FREQUENCY.0;
75 match raw_div { 76 match raw_div {
76 0..=1 => Self::Div2, 77 0..=1 => Self::Div2,
77 2..=3 => Self::Div4, 78 2..=3 => Self::Div4,
diff --git a/embassy-stm32/src/adc/v4.rs b/embassy-stm32/src/adc/v4.rs
index b66437e6e..c68684cb2 100644
--- a/embassy-stm32/src/adc/v4.rs
+++ b/embassy-stm32/src/adc/v4.rs
@@ -93,7 +93,8 @@ enum Prescaler {
93 93
94impl Prescaler { 94impl Prescaler {
95 fn from_ker_ck(frequency: Hertz) -> Self { 95 fn from_ker_ck(frequency: Hertz) -> Self {
96 let raw_prescaler = frequency.0 / MAX_ADC_CLK_FREQ.0; 96 // Calculate prescaler in a way where the clock can hit MAX CLK
97 let raw_prescaler = frequency.0.saturating_sub(1) / MAX_ADC_CLK_FREQ.0;
97 match raw_prescaler { 98 match raw_prescaler {
98 0 => Self::NotDivided, 99 0 => Self::NotDivided,
99 1 => Self::DividedBy2, 100 1 => Self::DividedBy2,