aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32/src
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2024-04-29 22:02:37 +0000
committerGitHub <[email protected]>2024-04-29 22:02:37 +0000
commite6d90b18c0bb4d3b02ecf73ee682e5892fe83b14 (patch)
treec4db46ebe52c160d118fe67620b41d4d551488c7 /embassy-stm32/src
parent2410e91785b318283f6e8b3cf9de1738ab064bd8 (diff)
parent1ed2a0504aba38e4b404c776808ee5229cd72615 (diff)
Merge pull request #2889 from embassy-rs/update-metapac-42
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/dmamux.rs24
-rw-r--r--embassy-stm32/src/dma/gpdma.rs6
-rw-r--r--embassy-stm32/src/dma/mod.rs2
-rw-r--r--embassy-stm32/src/eth/v2/mod.rs4
-rw-r--r--embassy-stm32/src/macros.rs27
-rw-r--r--embassy-stm32/src/rcc/f013.rs84
8 files changed, 61 insertions, 102 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/dmamux.rs b/embassy-stm32/src/dma/dmamux.rs
index dc7cd3a66..1585b30d4 100644
--- a/embassy-stm32/src/dma/dmamux.rs
+++ b/embassy-stm32/src/dma/dmamux.rs
@@ -19,30 +19,6 @@ pub(crate) fn configure_dmamux(info: &DmamuxInfo, request: u8) {
19 }); 19 });
20} 20}
21 21
22pub(crate) trait SealedMuxChannel {}
23
24/// DMAMUX1 instance.
25pub struct DMAMUX1;
26/// DMAMUX2 instance.
27#[cfg(stm32h7)]
28pub struct DMAMUX2;
29
30/// DMAMUX channel trait.
31#[allow(private_bounds)]
32pub trait MuxChannel: SealedMuxChannel {
33 /// DMAMUX instance this channel is on.
34 type Mux;
35}
36
37macro_rules! dmamux_channel_impl {
38 ($channel_peri:ident, $dmamux:ident) => {
39 impl crate::dma::SealedMuxChannel for crate::peripherals::$channel_peri {}
40 impl crate::dma::MuxChannel for crate::peripherals::$channel_peri {
41 type Mux = crate::dma::$dmamux;
42 }
43 };
44}
45
46/// safety: must be called only once 22/// safety: must be called only once
47pub(crate) unsafe fn init(_cs: critical_section::CriticalSection) { 23pub(crate) unsafe fn init(_cs: critical_section::CriticalSection) {
48 crate::_generated::init_dmamux(); 24 crate::_generated::init_dmamux();
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/dma/mod.rs b/embassy-stm32/src/dma/mod.rs
index 8766d0a60..3f5687a62 100644
--- a/embassy-stm32/src/dma/mod.rs
+++ b/embassy-stm32/src/dma/mod.rs
@@ -14,7 +14,7 @@ pub use gpdma::*;
14#[cfg(dmamux)] 14#[cfg(dmamux)]
15mod dmamux; 15mod dmamux;
16#[cfg(dmamux)] 16#[cfg(dmamux)]
17pub use dmamux::*; 17pub(crate) use dmamux::*;
18 18
19mod util; 19mod util;
20pub(crate) use util::*; 20pub(crate) use util::*;
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/macros.rs b/embassy-stm32/src/macros.rs
index 14137bc37..02dce1266 100644
--- a/embassy-stm32/src/macros.rs
+++ b/embassy-stm32/src/macros.rs
@@ -36,32 +36,7 @@ macro_rules! dma_trait {
36 36
37#[allow(unused)] 37#[allow(unused)]
38macro_rules! dma_trait_impl { 38macro_rules! dma_trait_impl {
39 // DMAMUX 39 (crate::$mod:ident::$trait:ident$(<$mode:ident>)?, $instance:ident, $channel:ident, $request:expr) => {
40 (crate::$mod:ident::$trait:ident$(<$mode:ident>)?, $instance:ident, {dmamux: $dmamux:ident}, $request:expr) => {
41 impl<T> crate::$mod::$trait<crate::peripherals::$instance $(, crate::$mod::$mode)?> for T
42 where
43 T: crate::dma::Channel + crate::dma::MuxChannel<Mux = crate::dma::$dmamux>,
44 {
45 fn request(&self) -> crate::dma::Request {
46 $request
47 }
48 }
49 };
50
51 // DMAMUX
52 (crate::$mod:ident::$trait:ident$(<$mode:ident>)?, $instance:ident, {dma: $dma:ident}, $request:expr) => {
53 impl<T> crate::$mod::$trait<crate::peripherals::$instance $(, crate::$mod::$mode)?> for T
54 where
55 T: crate::dma::Channel,
56 {
57 fn request(&self) -> crate::dma::Request {
58 $request
59 }
60 }
61 };
62
63 // DMA/GPDMA, without DMAMUX
64 (crate::$mod:ident::$trait:ident$(<$mode:ident>)?, $instance:ident, {channel: $channel:ident}, $request:expr) => {
65 impl crate::$mod::$trait<crate::peripherals::$instance $(, crate::$mod::$mode)?> for crate::peripherals::$channel { 40 impl crate::$mod::$trait<crate::peripherals::$instance $(, crate::$mod::$mode)?> for crate::peripherals::$channel {
66 fn request(&self) -> crate::dma::Request { 41 fn request(&self) -> crate::dma::Request {
67 $request 42 $request
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