aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32
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
parent679160a1c573709ccf2c54755e69ea9e1b5a209e (diff)
stm32: update metapac. Adds U5 LPDMA, fixes ADC_COMMONs.
Diffstat (limited to 'embassy-stm32')
-rw-r--r--embassy-stm32/Cargo.toml4
-rw-r--r--embassy-stm32/build.rs44
-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
7 files changed, 78 insertions, 80 deletions
diff --git a/embassy-stm32/Cargo.toml b/embassy-stm32/Cargo.toml
index 653a376bd..93a30c5c5 100644
--- a/embassy-stm32/Cargo.toml
+++ b/embassy-stm32/Cargo.toml
@@ -72,7 +72,7 @@ rand_core = "0.6.3"
72sdio-host = "0.5.0" 72sdio-host = "0.5.0"
73critical-section = "1.1" 73critical-section = "1.1"
74#stm32-metapac = { version = "15" } 74#stm32-metapac = { version = "15" }
75stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-823168933f3860770111f7bde2a82b912eac58c0" } 75stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-37a0941112fd16fee53aaa2005fd67b77adab59c" }
76 76
77vcell = "0.1.3" 77vcell = "0.1.3"
78nb = "1.0.0" 78nb = "1.0.0"
@@ -98,7 +98,7 @@ proc-macro2 = "1.0.36"
98quote = "1.0.15" 98quote = "1.0.15"
99 99
100#stm32-metapac = { version = "15", default-features = false, features = ["metadata"]} 100#stm32-metapac = { version = "15", default-features = false, features = ["metadata"]}
101stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-823168933f3860770111f7bde2a82b912eac58c0", default-features = false, features = ["metadata"]} 101stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-37a0941112fd16fee53aaa2005fd67b77adab59c", default-features = false, features = ["metadata"]}
102 102
103[features] 103[features]
104default = ["rt"] 104default = ["rt"]
diff --git a/embassy-stm32/build.rs b/embassy-stm32/build.rs
index 67fceda56..49ffef217 100644
--- a/embassy-stm32/build.rs
+++ b/embassy-stm32/build.rs
@@ -49,6 +49,8 @@ fn main() {
49 .unwrap() 49 .unwrap()
50 .to_ascii_lowercase(); 50 .to_ascii_lowercase();
51 51
52 eprintln!("chip: {chip_name}");
53
52 for p in METADATA.peripherals { 54 for p in METADATA.peripherals {
53 if let Some(r) = &p.registers { 55 if let Some(r) = &p.registers {
54 println!("cargo:rustc-cfg={}", r.kind); 56 println!("cargo:rustc-cfg={}", r.kind);
@@ -1321,17 +1323,7 @@ fn main() {
1321 let mut interrupts_table: Vec<Vec<String>> = Vec::new(); 1323 let mut interrupts_table: Vec<Vec<String>> = Vec::new();
1322 let mut peripherals_table: Vec<Vec<String>> = Vec::new(); 1324 let mut peripherals_table: Vec<Vec<String>> = Vec::new();
1323 let mut pins_table: Vec<Vec<String>> = Vec::new(); 1325 let mut pins_table: Vec<Vec<String>> = Vec::new();
1324 let mut adc_common_table: Vec<Vec<String>> = Vec::new(); 1326 let mut adc_table: Vec<Vec<String>> = Vec::new();
1325
1326 /*
1327 If ADC3_COMMON exists, ADC3 and higher are assigned to it
1328 All other ADCs are assigned to ADC_COMMON
1329
1330 ADC3 and higher are assigned to the adc34 clock in the table
1331 The adc3_common cfg directive is added if ADC3_COMMON exists
1332 */
1333 let has_adc3 = METADATA.peripherals.iter().any(|p| p.name == "ADC3_COMMON");
1334 let set_adc345 = HashSet::from(["ADC3", "ADC4", "ADC5"]);
1335 1327
1336 for m in METADATA 1328 for m in METADATA
1337 .memory 1329 .memory
@@ -1388,14 +1380,18 @@ fn main() {
1388 } 1380 }
1389 1381
1390 if regs.kind == "adc" { 1382 if regs.kind == "adc" {
1391 let (adc_common, adc_clock) = if set_adc345.contains(p.name) && has_adc3 { 1383 let adc_num = p.name.strip_prefix("ADC").unwrap();
1392 ("ADC3_COMMON", "adc34") 1384 let mut adc_common = None;
1393 } else { 1385 for p2 in METADATA.peripherals {
1394 ("ADC_COMMON", "adc") 1386 if let Some(common_nums) = p2.name.strip_prefix("ADC").and_then(|s| s.strip_suffix("_COMMON")) {
1395 }; 1387 if common_nums.contains(adc_num) {
1396 1388 adc_common = Some(p2);
1397 let row = vec![p.name.to_string(), adc_common.to_string(), adc_clock.to_string()]; 1389 }
1398 adc_common_table.push(row); 1390 }
1391 }
1392 let adc_common = adc_common.map(|p| p.name).unwrap_or("none");
1393 let row = vec![p.name.to_string(), adc_common.to_string(), "adc".to_string()];
1394 adc_table.push(row);
1399 } 1395 }
1400 1396
1401 for irq in p.interrupts { 1397 for irq in p.interrupts {
@@ -1441,6 +1437,7 @@ fn main() {
1441 "dma" => quote!(crate::dma::DmaInfo::Dma(crate::pac::#dma)), 1437 "dma" => quote!(crate::dma::DmaInfo::Dma(crate::pac::#dma)),
1442 "bdma" => quote!(crate::dma::DmaInfo::Bdma(crate::pac::#dma)), 1438 "bdma" => quote!(crate::dma::DmaInfo::Bdma(crate::pac::#dma)),
1443 "gpdma" => quote!(crate::pac::#dma), 1439 "gpdma" => quote!(crate::pac::#dma),
1440 "lpdma" => quote!(unsafe { crate::pac::gpdma::Gpdma::from_ptr(crate::pac::#dma.as_ptr())}),
1444 _ => panic!("bad dma channel kind {}", bi.kind), 1441 _ => panic!("bad dma channel kind {}", bi.kind),
1445 }; 1442 };
1446 1443
@@ -1535,7 +1532,7 @@ fn main() {
1535 make_table(&mut m, "foreach_interrupt", &interrupts_table); 1532 make_table(&mut m, "foreach_interrupt", &interrupts_table);
1536 make_table(&mut m, "foreach_peripheral", &peripherals_table); 1533 make_table(&mut m, "foreach_peripheral", &peripherals_table);
1537 make_table(&mut m, "foreach_pin", &pins_table); 1534 make_table(&mut m, "foreach_pin", &pins_table);
1538 make_table(&mut m, "foreach_adc", &adc_common_table); 1535 make_table(&mut m, "foreach_adc", &adc_table);
1539 1536
1540 let out_dir = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); 1537 let out_dir = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
1541 let out_file = out_dir.join("_macros.rs").to_string_lossy().to_string(); 1538 let out_file = out_dir.join("_macros.rs").to_string_lossy().to_string();
@@ -1569,13 +1566,6 @@ fn main() {
1569 } 1566 }
1570 1567
1571 // ======= 1568 // =======
1572 // ADC3_COMMON is present
1573 #[allow(clippy::print_literal)]
1574 if has_adc3 {
1575 println!("cargo:rustc-cfg={}", "adc3_common");
1576 }
1577
1578 // =======
1579 // Features for targeting groups of chips 1569 // Features for targeting groups of chips
1580 1570
1581 if &chip_name[..8] == "stm32wba" { 1571 if &chip_name[..8] == "stm32wba" {
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