aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32/src
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2024-04-29 20:52:27 +0200
committerDario Nieuwenhuis <[email protected]>2024-04-29 20:52:27 +0200
commit6f44d7a9dfbb1dfe503c978e2277cfc5b1b6d486 (patch)
tree0850613ec1eef6397d853c8b04a1ae86c12f9d8a /embassy-stm32/src
parent679160a1c573709ccf2c54755e69ea9e1b5a209e (diff)
stm32: update metapac. Adds U5 LPDMA, fixes ADC_COMMONs.
Diffstat (limited to 'embassy-stm32/src')
-rw-r--r--embassy-stm32/src/adc/v1.rs14
-rw-r--r--embassy-stm32/src/dac/mod.rs2
-rw-r--r--embassy-stm32/src/dma/gpdma.rs6
-rw-r--r--embassy-stm32/src/eth/v2/mod.rs4
-rw-r--r--embassy-stm32/src/rcc/f013.rs84
5 files changed, 59 insertions, 51 deletions
diff --git a/embassy-stm32/src/adc/v1.rs b/embassy-stm32/src/adc/v1.rs
index 1dda28cf2..f17522076 100644
--- a/embassy-stm32/src/adc/v1.rs
+++ b/embassy-stm32/src/adc/v1.rs
@@ -9,7 +9,7 @@ use stm32_metapac::adc::vals::Ckmode;
9use super::blocking_delay_us; 9use super::blocking_delay_us;
10use crate::adc::{Adc, AdcPin, Instance, Resolution, SampleTime}; 10use crate::adc::{Adc, AdcPin, Instance, Resolution, SampleTime};
11use crate::interrupt::typelevel::Interrupt; 11use crate::interrupt::typelevel::Interrupt;
12use crate::peripherals::ADC; 12use crate::peripherals::ADC1;
13use crate::{interrupt, Peripheral}; 13use crate::{interrupt, Peripheral};
14 14
15pub const VDDA_CALIB_MV: u32 = 3300; 15pub const VDDA_CALIB_MV: u32 = 3300;
@@ -36,26 +36,26 @@ impl<T: Instance> interrupt::typelevel::Handler<T::Interrupt> for InterruptHandl
36pub struct Vbat; 36pub struct Vbat;
37 37
38#[cfg(not(adc_l0))] 38#[cfg(not(adc_l0))]
39impl AdcPin<ADC> for Vbat {} 39impl AdcPin<ADC1> for Vbat {}
40 40
41#[cfg(not(adc_l0))] 41#[cfg(not(adc_l0))]
42impl super::SealedAdcPin<ADC> for Vbat { 42impl super::SealedAdcPin<ADC1> for Vbat {
43 fn channel(&self) -> u8 { 43 fn channel(&self) -> u8 {
44 18 44 18
45 } 45 }
46} 46}
47 47
48pub struct Vref; 48pub struct Vref;
49impl AdcPin<ADC> for Vref {} 49impl AdcPin<ADC1> for Vref {}
50impl super::SealedAdcPin<ADC> for Vref { 50impl super::SealedAdcPin<ADC1> for Vref {
51 fn channel(&self) -> u8 { 51 fn channel(&self) -> u8 {
52 17 52 17
53 } 53 }
54} 54}
55 55
56pub struct Temperature; 56pub struct Temperature;
57impl AdcPin<ADC> for Temperature {} 57impl AdcPin<ADC1> for Temperature {}
58impl super::SealedAdcPin<ADC> for Temperature { 58impl super::SealedAdcPin<ADC1> for Temperature {
59 fn channel(&self) -> u8 { 59 fn channel(&self) -> u8 {
60 16 60 16
61 } 61 }
diff --git a/embassy-stm32/src/dac/mod.rs b/embassy-stm32/src/dac/mod.rs
index 26298a08b..8a748ad72 100644
--- a/embassy-stm32/src/dac/mod.rs
+++ b/embassy-stm32/src/dac/mod.rs
@@ -368,7 +368,7 @@ impl<'d, T: Instance, const N: u8, DMA> Drop for DacChannel<'d, T, N, DMA> {
368/// 368///
369/// ```ignore 369/// ```ignore
370/// // Pins may need to be changed for your specific device. 370/// // Pins may need to be changed for your specific device.
371/// let (dac_ch1, dac_ch2) = embassy_stm32::dac::Dac::new(p.DAC, NoDma, NoDma, p.PA4, p.PA5).split(); 371/// let (dac_ch1, dac_ch2) = embassy_stm32::dac::Dac::new(p.DAC1, NoDma, NoDma, p.PA4, p.PA5).split();
372/// ``` 372/// ```
373pub struct Dac<'d, T: Instance, DMACh1 = NoDma, DMACh2 = NoDma> { 373pub struct Dac<'d, T: Instance, DMACh1 = NoDma, DMACh2 = NoDma> {
374 ch1: DacChannel<'d, T, 1, DMACh1>, 374 ch1: DacChannel<'d, T, 1, DMACh1>,
diff --git a/embassy-stm32/src/dma/gpdma.rs b/embassy-stm32/src/dma/gpdma.rs
index ef03970ef..a3717e67b 100644
--- a/embassy-stm32/src/dma/gpdma.rs
+++ b/embassy-stm32/src/dma/gpdma.rs
@@ -32,7 +32,7 @@ impl Default for TransferOptions {
32 } 32 }
33} 33}
34 34
35impl From<WordSize> for vals::ChTr1Dw { 35impl From<WordSize> for vals::Dw {
36 fn from(raw: WordSize) -> Self { 36 fn from(raw: WordSize) -> Self {
37 match raw { 37 match raw {
38 WordSize::OneByte => Self::BYTE, 38 WordSize::OneByte => Self::BYTE,
@@ -235,8 +235,8 @@ impl<'a> Transfer<'a> {
235 }); 235 });
236 ch.tr2().write(|w| { 236 ch.tr2().write(|w| {
237 w.set_dreq(match dir { 237 w.set_dreq(match dir {
238 Dir::MemoryToPeripheral => vals::ChTr2Dreq::DESTINATIONPERIPHERAL, 238 Dir::MemoryToPeripheral => vals::Dreq::DESTINATIONPERIPHERAL,
239 Dir::PeripheralToMemory => vals::ChTr2Dreq::SOURCEPERIPHERAL, 239 Dir::PeripheralToMemory => vals::Dreq::SOURCEPERIPHERAL,
240 }); 240 });
241 w.set_reqsel(request); 241 w.set_reqsel(request);
242 }); 242 });
diff --git a/embassy-stm32/src/eth/v2/mod.rs b/embassy-stm32/src/eth/v2/mod.rs
index c6e015022..37f460574 100644
--- a/embassy-stm32/src/eth/v2/mod.rs
+++ b/embassy-stm32/src/eth/v2/mod.rs
@@ -94,8 +94,6 @@ impl<'d, T: Instance, P: PHY> Ethernet<'d, T, P> {
94 94
95 #[cfg(rcc_h5)] 95 #[cfg(rcc_h5)]
96 critical_section::with(|_| { 96 critical_section::with(|_| {
97 crate::pac::RCC.apb3enr().modify(|w| w.set_sbsen(true));
98
99 crate::pac::RCC.ahb1enr().modify(|w| { 97 crate::pac::RCC.ahb1enr().modify(|w| {
100 w.set_ethen(true); 98 w.set_ethen(true);
101 w.set_ethtxen(true); 99 w.set_ethtxen(true);
@@ -161,8 +159,6 @@ impl<'d, T: Instance, P: PHY> Ethernet<'d, T, P> {
161 159
162 #[cfg(rcc_h5)] 160 #[cfg(rcc_h5)]
163 critical_section::with(|_| { 161 critical_section::with(|_| {
164 crate::pac::RCC.apb3enr().modify(|w| w.set_sbsen(true));
165
166 crate::pac::RCC.ahb1enr().modify(|w| { 162 crate::pac::RCC.ahb1enr().modify(|w| {
167 w.set_ethen(true); 163 w.set_ethen(true);
168 w.set_ethtxen(true); 164 w.set_ethtxen(true);
diff --git a/embassy-stm32/src/rcc/f013.rs b/embassy-stm32/src/rcc/f013.rs
index 215f8a3d2..f33351e74 100644
--- a/embassy-stm32/src/rcc/f013.rs
+++ b/embassy-stm32/src/rcc/f013.rs
@@ -299,54 +299,66 @@ pub(crate) unsafe fn init(config: Config) {
299 299
300 let rtc = config.ls.init(); 300 let rtc = config.ls.init();
301 301
302 // TODO: all this ADC stuff should probably go into the ADC module, not here.
303 // Most STM32s manage ADC clocks in a similar way with ADCx_COMMON.
302 #[cfg(all(stm32f3, not(rcc_f37)))] 304 #[cfg(all(stm32f3, not(rcc_f37)))]
303 use crate::pac::adccommon::vals::Ckmode; 305 use crate::pac::adccommon::vals::Ckmode;
304 306
305 #[cfg(all(stm32f3, not(rcc_f37)))] 307 #[cfg(all(stm32f3, not(rcc_f37)))]
306 let adc = match config.adc { 308 let adc = {
307 AdcClockSource::Pll(adcpres) => { 309 #[cfg(peri_adc1_common)]
308 RCC.cfgr2().modify(|w| w.set_adc12pres(adcpres)); 310 let common = crate::pac::ADC1_COMMON;
309 crate::pac::ADC_COMMON 311 #[cfg(peri_adc12_common)]
310 .ccr() 312 let common = crate::pac::ADC12_COMMON;
311 .modify(|w| w.set_ckmode(Ckmode::ASYNCHRONOUS)); 313
312 314 match config.adc {
313 unwrap!(pll) / adcpres 315 AdcClockSource::Pll(adcpres) => {
314 } 316 RCC.cfgr2().modify(|w| w.set_adc12pres(adcpres));
315 AdcClockSource::Hclk(adcpres) => { 317 common.ccr().modify(|w| w.set_ckmode(Ckmode::ASYNCHRONOUS));
316 assert!(!(adcpres == AdcHclkPrescaler::Div1 && config.ahb_pre != AHBPrescaler::DIV1)); 318
319 unwrap!(pll) / adcpres
320 }
321 AdcClockSource::Hclk(adcpres) => {
322 assert!(!(adcpres == AdcHclkPrescaler::Div1 && config.ahb_pre != AHBPrescaler::DIV1));
317 323
318 let (div, ckmode) = match adcpres { 324 let (div, ckmode) = match adcpres {
319 AdcHclkPrescaler::Div1 => (1u32, Ckmode::SYNCDIV1), 325 AdcHclkPrescaler::Div1 => (1u32, Ckmode::SYNCDIV1),
320 AdcHclkPrescaler::Div2 => (2u32, Ckmode::SYNCDIV2), 326 AdcHclkPrescaler::Div2 => (2u32, Ckmode::SYNCDIV2),
321 AdcHclkPrescaler::Div4 => (4u32, Ckmode::SYNCDIV4), 327 AdcHclkPrescaler::Div4 => (4u32, Ckmode::SYNCDIV4),
322 }; 328 };
323 crate::pac::ADC_COMMON.ccr().modify(|w| w.set_ckmode(ckmode)); 329 common.ccr().modify(|w| w.set_ckmode(ckmode));
324 330
325 hclk / div 331 hclk / div
332 }
326 } 333 }
327 }; 334 };
328 335
329 #[cfg(all(stm32f3, not(rcc_f37), adc3_common))] 336 #[cfg(all(stm32f3, not(rcc_f37), adc3_common))]
330 let adc34 = match config.adc34 { 337 let adc34 = {
331 AdcClockSource::Pll(adcpres) => { 338 #[cfg(peri_adc3_common)]
332 RCC.cfgr2().modify(|w| w.set_adc34pres(adcpres)); 339 let common = crate::pac::ADC3_COMMON;
333 crate::pac::ADC3_COMMON 340 #[cfg(peri_adc34_common)]
334 .ccr() 341 let common = crate::pac::ADC34_COMMON;
335 .modify(|w| w.set_ckmode(Ckmode::ASYNCHRONOUS)); 342
336 343 match config.adc34 {
337 unwrap!(pll) / adcpres 344 AdcClockSource::Pll(adcpres) => {
338 } 345 RCC.cfgr2().modify(|w| w.set_adc34pres(adcpres));
339 AdcClockSource::Hclk(adcpres) => { 346 common.ccr().modify(|w| w.set_ckmode(Ckmode::ASYNCHRONOUS));
340 assert!(!(adcpres == AdcHclkPrescaler::Div1 && config.ahb_pre != AHBPrescaler::DIV1)); 347
348 unwrap!(pll) / adcpres
349 }
350 AdcClockSource::Hclk(adcpres) => {
351 assert!(!(adcpres == AdcHclkPrescaler::Div1 && config.ahb_pre != AHBPrescaler::DIV1));
341 352
342 let (div, ckmode) = match adcpres { 353 let (div, ckmode) = match adcpres {
343 AdcHclkPrescaler::Div1 => (1u32, Ckmode::SYNCDIV1), 354 AdcHclkPrescaler::Div1 => (1u32, Ckmode::SYNCDIV1),
344 AdcHclkPrescaler::Div2 => (2u32, Ckmode::SYNCDIV2), 355 AdcHclkPrescaler::Div2 => (2u32, Ckmode::SYNCDIV2),
345 AdcHclkPrescaler::Div4 => (4u32, Ckmode::SYNCDIV4), 356 AdcHclkPrescaler::Div4 => (4u32, Ckmode::SYNCDIV4),
346 }; 357 };
347 crate::pac::ADC3_COMMON.ccr().modify(|w| w.set_ckmode(ckmode)); 358 common.ccr().modify(|w| w.set_ckmode(ckmode));
348 359
349 hclk / div 360 hclk / div
361 }
350 } 362 }
351 }; 363 };
352 364