diff options
| -rw-r--r-- | embassy-stm32/src/rcc/mod.rs | 44 | ||||
| -rw-r--r-- | embassy-stm32/src/spi/mod.rs | 4 | ||||
| -rw-r--r-- | embassy-stm32/src/spi/v1.rs | 2 | ||||
| -rw-r--r-- | embassy-stm32/src/spi/v2.rs | 2 | ||||
| -rw-r--r-- | embassy-stm32/src/spi/v3.rs | 2 | ||||
| m--------- | stm32-data | 0 | ||||
| -rw-r--r-- | stm32-metapac/build.rs | 25 |
7 files changed, 77 insertions, 2 deletions
diff --git a/embassy-stm32/src/rcc/mod.rs b/embassy-stm32/src/rcc/mod.rs index 7112ad02f..3c5b53b05 100644 --- a/embassy-stm32/src/rcc/mod.rs +++ b/embassy-stm32/src/rcc/mod.rs | |||
| @@ -1,3 +1,6 @@ | |||
| 1 | #![macro_use] | ||
| 2 | |||
| 3 | use crate::peripherals; | ||
| 1 | use crate::time::Hertz; | 4 | use crate::time::Hertz; |
| 2 | use core::mem::MaybeUninit; | 5 | use core::mem::MaybeUninit; |
| 3 | 6 | ||
| @@ -44,3 +47,44 @@ cfg_if::cfg_if! { | |||
| 44 | } | 47 | } |
| 45 | } | 48 | } |
| 46 | } | 49 | } |
| 50 | |||
| 51 | pub(crate) mod sealed { | ||
| 52 | pub trait RccPeripheral { | ||
| 53 | fn reset(); | ||
| 54 | fn enable(); | ||
| 55 | fn disable(); | ||
| 56 | } | ||
| 57 | } | ||
| 58 | |||
| 59 | pub trait RccPeripheral: sealed::RccPeripheral + 'static {} | ||
| 60 | |||
| 61 | crate::pac::peripheral_rcc!( | ||
| 62 | ($inst:ident, $enable:ident, $reset:ident, $perien:ident, $perirst:ident) => { | ||
| 63 | impl sealed::RccPeripheral for peripherals::$inst { | ||
| 64 | fn enable() { | ||
| 65 | critical_section::with(|_| { | ||
| 66 | unsafe { | ||
| 67 | crate::pac::RCC.$enable().modify(|w| w.$perien(true)); | ||
| 68 | } | ||
| 69 | }) | ||
| 70 | } | ||
| 71 | fn disable() { | ||
| 72 | critical_section::with(|_| { | ||
| 73 | unsafe { | ||
| 74 | crate::pac::RCC.$enable().modify(|w| w.$perien(false)); | ||
| 75 | } | ||
| 76 | }) | ||
| 77 | } | ||
| 78 | fn reset() { | ||
| 79 | critical_section::with(|_| { | ||
| 80 | unsafe { | ||
| 81 | crate::pac::RCC.$reset().modify(|w| w.$perirst(true)); | ||
| 82 | crate::pac::RCC.$reset().modify(|w| w.$perirst(false)); | ||
| 83 | } | ||
| 84 | }) | ||
| 85 | } | ||
| 86 | } | ||
| 87 | |||
| 88 | impl RccPeripheral for peripherals::$inst {} | ||
| 89 | }; | ||
| 90 | ); | ||
diff --git a/embassy-stm32/src/spi/mod.rs b/embassy-stm32/src/spi/mod.rs index 730169ec0..9b04c03aa 100644 --- a/embassy-stm32/src/spi/mod.rs +++ b/embassy-stm32/src/spi/mod.rs | |||
| @@ -4,7 +4,7 @@ | |||
| 4 | #[cfg_attr(spi_v2, path = "v2.rs")] | 4 | #[cfg_attr(spi_v2, path = "v2.rs")] |
| 5 | #[cfg_attr(spi_v3, path = "v3.rs")] | 5 | #[cfg_attr(spi_v3, path = "v3.rs")] |
| 6 | mod _version; | 6 | mod _version; |
| 7 | use crate::peripherals; | 7 | use crate::{peripherals, rcc::RccPeripheral}; |
| 8 | pub use _version::*; | 8 | pub use _version::*; |
| 9 | 9 | ||
| 10 | use crate::gpio::Pin; | 10 | use crate::gpio::Pin; |
| @@ -64,7 +64,7 @@ pub(crate) mod sealed { | |||
| 64 | } | 64 | } |
| 65 | } | 65 | } |
| 66 | 66 | ||
| 67 | pub trait Instance: sealed::Instance + 'static {} | 67 | pub trait Instance: sealed::Instance + RccPeripheral + 'static {} |
| 68 | 68 | ||
| 69 | pub trait SckPin<T: Instance>: sealed::SckPin<T> + 'static {} | 69 | pub trait SckPin<T: Instance>: sealed::SckPin<T> + 'static {} |
| 70 | 70 | ||
diff --git a/embassy-stm32/src/spi/v1.rs b/embassy-stm32/src/spi/v1.rs index e3057a3b5..227a36a89 100644 --- a/embassy-stm32/src/spi/v1.rs +++ b/embassy-stm32/src/spi/v1.rs | |||
| @@ -61,6 +61,8 @@ impl<'d, T: Instance> Spi<'d, T> { | |||
| 61 | let br = Self::compute_baud_rate(pclk, freq.into()); | 61 | let br = Self::compute_baud_rate(pclk, freq.into()); |
| 62 | 62 | ||
| 63 | unsafe { | 63 | unsafe { |
| 64 | T::enable(); | ||
| 65 | T::reset(); | ||
| 64 | T::regs().cr1().modify(|w| { | 66 | T::regs().cr1().modify(|w| { |
| 65 | w.set_cpha( | 67 | w.set_cpha( |
| 66 | match config.mode.phase == Phase::CaptureOnSecondTransition { | 68 | match config.mode.phase == Phase::CaptureOnSecondTransition { |
diff --git a/embassy-stm32/src/spi/v2.rs b/embassy-stm32/src/spi/v2.rs index 46fe817ea..a7ac54cdd 100644 --- a/embassy-stm32/src/spi/v2.rs +++ b/embassy-stm32/src/spi/v2.rs | |||
| @@ -63,6 +63,8 @@ impl<'d, T: Instance> Spi<'d, T> { | |||
| 63 | let br = Self::compute_baud_rate(pclk, freq.into()); | 63 | let br = Self::compute_baud_rate(pclk, freq.into()); |
| 64 | 64 | ||
| 65 | unsafe { | 65 | unsafe { |
| 66 | T::enable(); | ||
| 67 | T::reset(); | ||
| 66 | T::regs().cr2().modify(|w| { | 68 | T::regs().cr2().modify(|w| { |
| 67 | w.set_ssoe(false); | 69 | w.set_ssoe(false); |
| 68 | }); | 70 | }); |
diff --git a/embassy-stm32/src/spi/v3.rs b/embassy-stm32/src/spi/v3.rs index da4686b9c..6073616bd 100644 --- a/embassy-stm32/src/spi/v3.rs +++ b/embassy-stm32/src/spi/v3.rs | |||
| @@ -64,6 +64,8 @@ impl<'d, T: Instance> Spi<'d, T> { | |||
| 64 | 64 | ||
| 65 | let br = Self::compute_baud_rate(pclk, freq.into()); | 65 | let br = Self::compute_baud_rate(pclk, freq.into()); |
| 66 | unsafe { | 66 | unsafe { |
| 67 | T::enable(); | ||
| 68 | T::reset(); | ||
| 67 | T::regs().ifcr().write(|w| w.0 = 0xffff_ffff); | 69 | T::regs().ifcr().write(|w| w.0 = 0xffff_ffff); |
| 68 | T::regs().cfg2().modify(|w| { | 70 | T::regs().cfg2().modify(|w| { |
| 69 | //w.set_ssoe(true); | 71 | //w.set_ssoe(true); |
diff --git a/stm32-data b/stm32-data | |||
| Subproject 6e4da8f04205dcc48767d12fac5cdfd170e52f1 | Subproject 4bb1b178cd1c555cfedaea31ad0be3c6a7b9956 | ||
diff --git a/stm32-metapac/build.rs b/stm32-metapac/build.rs index 083e06bfd..008c9eb37 100644 --- a/stm32-metapac/build.rs +++ b/stm32-metapac/build.rs | |||
| @@ -136,6 +136,7 @@ fn main() { | |||
| 136 | let mut interrupt_table: Vec<Vec<String>> = Vec::new(); | 136 | let mut interrupt_table: Vec<Vec<String>> = Vec::new(); |
| 137 | let mut peripherals_table: Vec<Vec<String>> = Vec::new(); | 137 | let mut peripherals_table: Vec<Vec<String>> = Vec::new(); |
| 138 | let mut peripheral_pins_table: Vec<Vec<String>> = Vec::new(); | 138 | let mut peripheral_pins_table: Vec<Vec<String>> = Vec::new(); |
| 139 | let mut peripheral_rcc_table: Vec<Vec<String>> = Vec::new(); | ||
| 139 | 140 | ||
| 140 | let dma_base = chip | 141 | let dma_base = chip |
| 141 | .peripherals | 142 | .peripherals |
| @@ -216,6 +217,29 @@ fn main() { | |||
| 216 | }; | 217 | }; |
| 217 | assert_eq!(p.address, dma_base + dma_stride * dma_num); | 218 | assert_eq!(p.address, dma_base + dma_stride * dma_num); |
| 218 | } | 219 | } |
| 220 | "spi" => { | ||
| 221 | if let Some(clock) = &p.clock { | ||
| 222 | // Workaround for APB1 register being split on some chip families. Assume | ||
| 223 | // first register until we can find a way to hint which register is used | ||
| 224 | let reg = clock.to_ascii_lowercase(); | ||
| 225 | let (enable_reg, reset_reg) = if chip.family == "STM32H7" && clock == "APB1" | ||
| 226 | { | ||
| 227 | (format!("{}lenr", reg), format!("{}lrstr", reg)) | ||
| 228 | } else if chip.family.starts_with("STM32L4") && clock == "APB1" { | ||
| 229 | (format!("{}enr1", reg), format!("{}rstr1", reg)) | ||
| 230 | } else { | ||
| 231 | (format!("{}enr", reg), format!("{}rstr", reg)) | ||
| 232 | }; | ||
| 233 | let field = name.to_ascii_lowercase(); | ||
| 234 | peripheral_rcc_table.push(vec![ | ||
| 235 | name.clone(), | ||
| 236 | enable_reg, | ||
| 237 | reset_reg, | ||
| 238 | format!("set_{}en", field), | ||
| 239 | format!("set_{}rst", field), | ||
| 240 | ]); | ||
| 241 | } | ||
| 242 | } | ||
| 219 | _ => {} | 243 | _ => {} |
| 220 | } | 244 | } |
| 221 | } | 245 | } |
| @@ -255,6 +279,7 @@ fn main() { | |||
| 255 | make_table(&mut extra, "peripherals", &peripherals_table); | 279 | make_table(&mut extra, "peripherals", &peripherals_table); |
| 256 | make_table(&mut extra, "peripheral_versions", &peripheral_version_table); | 280 | make_table(&mut extra, "peripheral_versions", &peripheral_version_table); |
| 257 | make_table(&mut extra, "peripheral_pins", &peripheral_pins_table); | 281 | make_table(&mut extra, "peripheral_pins", &peripheral_pins_table); |
| 282 | make_table(&mut extra, "peripheral_rcc", &peripheral_rcc_table); | ||
| 258 | 283 | ||
| 259 | for (module, version) in peripheral_versions { | 284 | for (module, version) in peripheral_versions { |
| 260 | println!("loading {} {}", module, version); | 285 | println!("loading {} {}", module, version); |
