diff options
| -rwxr-xr-x | ci.sh | 2 | ||||
| -rwxr-xr-x | ci_stable.sh | 2 | ||||
| -rw-r--r-- | embassy-stm32/Cargo.toml | 21 | ||||
| -rw-r--r-- | embassy-stm32/src/exti.rs | 16 | ||||
| -rw-r--r-- | embassy-stm32/src/lib.rs | 2 | ||||
| -rw-r--r-- | embassy-stm32/src/rcc/c0.rs | 233 | ||||
| -rw-r--r-- | embassy-stm32/src/rcc/mod.rs | 5 | ||||
| m--------- | stm32-data | 0 | ||||
| -rw-r--r-- | stm32-metapac-gen/Cargo.toml | 2 | ||||
| -rw-r--r-- | stm32-metapac/Cargo.toml | 21 |
10 files changed, 276 insertions, 28 deletions
| @@ -76,7 +76,7 @@ cargo batch \ | |||
| 76 | --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features nightly,stm32f217zg,defmt,exti,time-driver-any,unstable-traits \ | 76 | --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features nightly,stm32f217zg,defmt,exti,time-driver-any,unstable-traits \ |
| 77 | --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv8m.main-none-eabihf --features nightly,stm32l552ze,defmt,exti,time-driver-any,unstable-traits \ | 77 | --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv8m.main-none-eabihf --features nightly,stm32l552ze,defmt,exti,time-driver-any,unstable-traits \ |
| 78 | --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv6m-none-eabi --features nightly,stm32wl54jc-cm0p,defmt,exti,time-driver-any,unstable-traits \ | 78 | --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv6m-none-eabi --features nightly,stm32wl54jc-cm0p,defmt,exti,time-driver-any,unstable-traits \ |
| 79 | --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32wle5ub,defmt,exti,time-driver-any,unstable-traits \ | 79 | --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32wle5jb,defmt,exti,time-driver-any,unstable-traits \ |
| 80 | --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features nightly,stm32f107vc,defmt,exti,time-driver-any,unstable-traits \ | 80 | --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features nightly,stm32f107vc,defmt,exti,time-driver-any,unstable-traits \ |
| 81 | --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features nightly,stm32f103re,defmt,exti,time-driver-any,unstable-traits \ | 81 | --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features nightly,stm32f103re,defmt,exti,time-driver-any,unstable-traits \ |
| 82 | --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features nightly,stm32f100c4,defmt,exti,time-driver-any,unstable-traits \ | 82 | --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features nightly,stm32f100c4,defmt,exti,time-driver-any,unstable-traits \ |
diff --git a/ci_stable.sh b/ci_stable.sh index 60ddb659d..b4b0b83e7 100755 --- a/ci_stable.sh +++ b/ci_stable.sh | |||
| @@ -36,7 +36,7 @@ cargo batch \ | |||
| 36 | --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32g491re,defmt,exti,time-driver-any,unstable-traits \ | 36 | --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32g491re,defmt,exti,time-driver-any,unstable-traits \ |
| 37 | --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32u585zi,defmt,exti,time-driver-any,unstable-traits \ | 37 | --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32u585zi,defmt,exti,time-driver-any,unstable-traits \ |
| 38 | --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32wb55vy,defmt,exti,time-driver-any,unstable-traits \ | 38 | --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32wb55vy,defmt,exti,time-driver-any,unstable-traits \ |
| 39 | --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32wl55uc-cm4,defmt,exti,time-driver-any,unstable-traits \ | 39 | --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32wl55cc-cm4,defmt,exti,time-driver-any,unstable-traits \ |
| 40 | --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32l4r9zi,defmt,exti,time-driver-any,unstable-traits \ | 40 | --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32l4r9zi,defmt,exti,time-driver-any,unstable-traits \ |
| 41 | --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f303vc,defmt,exti,time-driver-any,unstable-traits \ | 41 | --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f303vc,defmt,exti,time-driver-any,unstable-traits \ |
| 42 | --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f411ce,defmt,time-driver-any \ | 42 | --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f411ce,defmt,time-driver-any \ |
diff --git a/embassy-stm32/Cargo.toml b/embassy-stm32/Cargo.toml index 67996cca4..d9c1f6dcf 100644 --- a/embassy-stm32/Cargo.toml +++ b/embassy-stm32/Cargo.toml | |||
| @@ -19,6 +19,7 @@ flavors = [ | |||
| 19 | { regex_feature = "stm32f3.*", target = "thumbv7em-none-eabi" }, | 19 | { regex_feature = "stm32f3.*", target = "thumbv7em-none-eabi" }, |
| 20 | { regex_feature = "stm32f42.*", target = "thumbv7em-none-eabi" }, | 20 | { regex_feature = "stm32f42.*", target = "thumbv7em-none-eabi" }, |
| 21 | { regex_feature = "stm32f7.*", target = "thumbv7em-none-eabi" }, | 21 | { regex_feature = "stm32f7.*", target = "thumbv7em-none-eabi" }, |
| 22 | { regex_feature = "stm32c0.*", target = "thumbv6m-none-eabi" }, | ||
| 22 | { regex_feature = "stm32g0.*", target = "thumbv6m-none-eabi" }, | 23 | { regex_feature = "stm32g0.*", target = "thumbv6m-none-eabi" }, |
| 23 | { regex_feature = "stm32g4.*", target = "thumbv7em-none-eabi" }, | 24 | { regex_feature = "stm32g4.*", target = "thumbv7em-none-eabi" }, |
| 24 | { regex_feature = "stm32h7.*", target = "thumbv7em-none-eabi" }, | 25 | { regex_feature = "stm32h7.*", target = "thumbv7em-none-eabi" }, |
| @@ -110,6 +111,19 @@ unstable-traits = ["embedded-hal-1", "dep:embedded-hal-nb"] | |||
| 110 | 111 | ||
| 111 | # BEGIN GENERATED FEATURES | 112 | # BEGIN GENERATED FEATURES |
| 112 | # Generated by stm32-gen-features. DO NOT EDIT. | 113 | # Generated by stm32-gen-features. DO NOT EDIT. |
| 114 | stm32c011d6 = [ "stm32-metapac/stm32c011d6" ] | ||
| 115 | stm32c011f4 = [ "stm32-metapac/stm32c011f4" ] | ||
| 116 | stm32c011f6 = [ "stm32-metapac/stm32c011f6" ] | ||
| 117 | stm32c011j4 = [ "stm32-metapac/stm32c011j4" ] | ||
| 118 | stm32c011j6 = [ "stm32-metapac/stm32c011j6" ] | ||
| 119 | stm32c031c4 = [ "stm32-metapac/stm32c031c4" ] | ||
| 120 | stm32c031c6 = [ "stm32-metapac/stm32c031c6" ] | ||
| 121 | stm32c031f4 = [ "stm32-metapac/stm32c031f4" ] | ||
| 122 | stm32c031f6 = [ "stm32-metapac/stm32c031f6" ] | ||
| 123 | stm32c031g4 = [ "stm32-metapac/stm32c031g4" ] | ||
| 124 | stm32c031g6 = [ "stm32-metapac/stm32c031g6" ] | ||
| 125 | stm32c031k4 = [ "stm32-metapac/stm32c031k4" ] | ||
| 126 | stm32c031k6 = [ "stm32-metapac/stm32c031k6" ] | ||
| 113 | stm32f030c6 = [ "stm32-metapac/stm32f030c6" ] | 127 | stm32f030c6 = [ "stm32-metapac/stm32f030c6" ] |
| 114 | stm32f030c8 = [ "stm32-metapac/stm32f030c8" ] | 128 | stm32f030c8 = [ "stm32-metapac/stm32f030c8" ] |
| 115 | stm32f030cc = [ "stm32-metapac/stm32f030cc" ] | 129 | stm32f030cc = [ "stm32-metapac/stm32f030cc" ] |
| @@ -1318,11 +1332,9 @@ stm32u575zi = [ "stm32-metapac/stm32u575zi" ] | |||
| 1318 | stm32u585ai = [ "stm32-metapac/stm32u585ai" ] | 1332 | stm32u585ai = [ "stm32-metapac/stm32u585ai" ] |
| 1319 | stm32u585ci = [ "stm32-metapac/stm32u585ci" ] | 1333 | stm32u585ci = [ "stm32-metapac/stm32u585ci" ] |
| 1320 | stm32u585oi = [ "stm32-metapac/stm32u585oi" ] | 1334 | stm32u585oi = [ "stm32-metapac/stm32u585oi" ] |
| 1321 | stm32u585qe = [ "stm32-metapac/stm32u585qe" ] | ||
| 1322 | stm32u585qi = [ "stm32-metapac/stm32u585qi" ] | 1335 | stm32u585qi = [ "stm32-metapac/stm32u585qi" ] |
| 1323 | stm32u585ri = [ "stm32-metapac/stm32u585ri" ] | 1336 | stm32u585ri = [ "stm32-metapac/stm32u585ri" ] |
| 1324 | stm32u585vi = [ "stm32-metapac/stm32u585vi" ] | 1337 | stm32u585vi = [ "stm32-metapac/stm32u585vi" ] |
| 1325 | stm32u585ze = [ "stm32-metapac/stm32u585ze" ] | ||
| 1326 | stm32u585zi = [ "stm32-metapac/stm32u585zi" ] | 1338 | stm32u585zi = [ "stm32-metapac/stm32u585zi" ] |
| 1327 | stm32wb10cc = [ "stm32-metapac/stm32wb10cc" ] | 1339 | stm32wb10cc = [ "stm32-metapac/stm32wb10cc" ] |
| 1328 | stm32wb15cc = [ "stm32-metapac/stm32wb15cc" ] | 1340 | stm32wb15cc = [ "stm32-metapac/stm32wb15cc" ] |
| @@ -1340,7 +1352,6 @@ stm32wb55vc = [ "stm32-metapac/stm32wb55vc" ] | |||
| 1340 | stm32wb55ve = [ "stm32-metapac/stm32wb55ve" ] | 1352 | stm32wb55ve = [ "stm32-metapac/stm32wb55ve" ] |
| 1341 | stm32wb55vg = [ "stm32-metapac/stm32wb55vg" ] | 1353 | stm32wb55vg = [ "stm32-metapac/stm32wb55vg" ] |
| 1342 | stm32wb55vy = [ "stm32-metapac/stm32wb55vy" ] | 1354 | stm32wb55vy = [ "stm32-metapac/stm32wb55vy" ] |
| 1343 | stm32wb5mmg = [ "stm32-metapac/stm32wb5mmg" ] | ||
| 1344 | stm32wl54cc-cm4 = [ "stm32-metapac/stm32wl54cc-cm4" ] | 1355 | stm32wl54cc-cm4 = [ "stm32-metapac/stm32wl54cc-cm4" ] |
| 1345 | stm32wl54cc-cm0p = [ "stm32-metapac/stm32wl54cc-cm0p" ] | 1356 | stm32wl54cc-cm0p = [ "stm32-metapac/stm32wl54cc-cm0p" ] |
| 1346 | stm32wl54jc-cm4 = [ "stm32-metapac/stm32wl54jc-cm4" ] | 1357 | stm32wl54jc-cm4 = [ "stm32-metapac/stm32wl54jc-cm4" ] |
| @@ -1349,8 +1360,6 @@ stm32wl55cc-cm4 = [ "stm32-metapac/stm32wl55cc-cm4" ] | |||
| 1349 | stm32wl55cc-cm0p = [ "stm32-metapac/stm32wl55cc-cm0p" ] | 1360 | stm32wl55cc-cm0p = [ "stm32-metapac/stm32wl55cc-cm0p" ] |
| 1350 | stm32wl55jc-cm4 = [ "stm32-metapac/stm32wl55jc-cm4" ] | 1361 | stm32wl55jc-cm4 = [ "stm32-metapac/stm32wl55jc-cm4" ] |
| 1351 | stm32wl55jc-cm0p = [ "stm32-metapac/stm32wl55jc-cm0p" ] | 1362 | stm32wl55jc-cm0p = [ "stm32-metapac/stm32wl55jc-cm0p" ] |
| 1352 | stm32wl55uc-cm4 = [ "stm32-metapac/stm32wl55uc-cm4" ] | ||
| 1353 | stm32wl55uc-cm0p = [ "stm32-metapac/stm32wl55uc-cm0p" ] | ||
| 1354 | stm32wle4c8 = [ "stm32-metapac/stm32wle4c8" ] | 1363 | stm32wle4c8 = [ "stm32-metapac/stm32wle4c8" ] |
| 1355 | stm32wle4cb = [ "stm32-metapac/stm32wle4cb" ] | 1364 | stm32wle4cb = [ "stm32-metapac/stm32wle4cb" ] |
| 1356 | stm32wle4cc = [ "stm32-metapac/stm32wle4cc" ] | 1365 | stm32wle4cc = [ "stm32-metapac/stm32wle4cc" ] |
| @@ -1363,6 +1372,4 @@ stm32wle5cc = [ "stm32-metapac/stm32wle5cc" ] | |||
| 1363 | stm32wle5j8 = [ "stm32-metapac/stm32wle5j8" ] | 1372 | stm32wle5j8 = [ "stm32-metapac/stm32wle5j8" ] |
| 1364 | stm32wle5jb = [ "stm32-metapac/stm32wle5jb" ] | 1373 | stm32wle5jb = [ "stm32-metapac/stm32wle5jb" ] |
| 1365 | stm32wle5jc = [ "stm32-metapac/stm32wle5jc" ] | 1374 | stm32wle5jc = [ "stm32-metapac/stm32wle5jc" ] |
| 1366 | stm32wle5u8 = [ "stm32-metapac/stm32wle5u8" ] | ||
| 1367 | stm32wle5ub = [ "stm32-metapac/stm32wle5ub" ] | ||
| 1368 | # END GENERATED FEATURES | 1375 | # END GENERATED FEATURES |
diff --git a/embassy-stm32/src/exti.rs b/embassy-stm32/src/exti.rs index f90785815..c9c3ef62a 100644 --- a/embassy-stm32/src/exti.rs +++ b/embassy-stm32/src/exti.rs | |||
| @@ -25,11 +25,11 @@ fn cpu_regs() -> pac::exti::Exti { | |||
| 25 | EXTI | 25 | EXTI |
| 26 | } | 26 | } |
| 27 | 27 | ||
| 28 | #[cfg(not(any(exti_g0, exti_l5, gpio_v1, exti_u5)))] | 28 | #[cfg(not(any(exti_c0, exti_g0, exti_l5, gpio_v1, exti_u5)))] |
| 29 | fn exticr_regs() -> pac::syscfg::Syscfg { | 29 | fn exticr_regs() -> pac::syscfg::Syscfg { |
| 30 | pac::SYSCFG | 30 | pac::SYSCFG |
| 31 | } | 31 | } |
| 32 | #[cfg(any(exti_g0, exti_l5, exti_u5))] | 32 | #[cfg(any(exti_c0, exti_g0, exti_l5, exti_u5))] |
| 33 | fn exticr_regs() -> pac::exti::Exti { | 33 | fn exticr_regs() -> pac::exti::Exti { |
| 34 | EXTI | 34 | EXTI |
| 35 | } | 35 | } |
| @@ -39,9 +39,9 @@ fn exticr_regs() -> pac::afio::Afio { | |||
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | pub unsafe fn on_irq() { | 41 | pub unsafe fn on_irq() { |
| 42 | #[cfg(not(any(exti_g0, exti_l5, exti_u5)))] | 42 | #[cfg(not(any(exti_c0, exti_g0, exti_l5, exti_u5)))] |
| 43 | let bits = EXTI.pr(0).read().0; | 43 | let bits = EXTI.pr(0).read().0; |
| 44 | #[cfg(any(exti_g0, exti_l5, exti_u5))] | 44 | #[cfg(any(exti_c0, exti_g0, exti_l5, exti_u5))] |
| 45 | let bits = EXTI.rpr(0).read().0 | EXTI.fpr(0).read().0; | 45 | let bits = EXTI.rpr(0).read().0 | EXTI.fpr(0).read().0; |
| 46 | 46 | ||
| 47 | // Mask all the channels that fired. | 47 | // Mask all the channels that fired. |
| @@ -53,9 +53,9 @@ pub unsafe fn on_irq() { | |||
| 53 | } | 53 | } |
| 54 | 54 | ||
| 55 | // Clear pending | 55 | // Clear pending |
| 56 | #[cfg(not(any(exti_g0, exti_l5, exti_u5)))] | 56 | #[cfg(not(any(exti_c0, exti_g0, exti_l5, exti_u5)))] |
| 57 | EXTI.pr(0).write_value(Lines(bits)); | 57 | EXTI.pr(0).write_value(Lines(bits)); |
| 58 | #[cfg(any(exti_g0, exti_l5, exti_u5))] | 58 | #[cfg(any(exti_c0, exti_g0, exti_l5, exti_u5))] |
| 59 | { | 59 | { |
| 60 | EXTI.rpr(0).write_value(Lines(bits)); | 60 | EXTI.rpr(0).write_value(Lines(bits)); |
| 61 | EXTI.fpr(0).write_value(Lines(bits)); | 61 | EXTI.fpr(0).write_value(Lines(bits)); |
| @@ -212,9 +212,9 @@ impl<'a> ExtiInputFuture<'a> { | |||
| 212 | EXTI.ftsr(0).modify(|w| w.set_line(pin, falling)); | 212 | EXTI.ftsr(0).modify(|w| w.set_line(pin, falling)); |
| 213 | 213 | ||
| 214 | // clear pending bit | 214 | // clear pending bit |
| 215 | #[cfg(not(any(exti_g0, exti_l5, exti_u5)))] | 215 | #[cfg(not(any(exti_c0, exti_g0, exti_l5, exti_u5)))] |
| 216 | EXTI.pr(0).write(|w| w.set_line(pin, true)); | 216 | EXTI.pr(0).write(|w| w.set_line(pin, true)); |
| 217 | #[cfg(any(exti_g0, exti_l5, exti_u5))] | 217 | #[cfg(any(exti_c0, exti_g0, exti_l5, exti_u5))] |
| 218 | { | 218 | { |
| 219 | EXTI.rpr(0).write(|w| w.set_line(pin, true)); | 219 | EXTI.rpr(0).write(|w| w.set_line(pin, true)); |
| 220 | EXTI.fpr(0).write(|w| w.set_line(pin, true)); | 220 | EXTI.fpr(0).write(|w| w.set_line(pin, true)); |
diff --git a/embassy-stm32/src/lib.rs b/embassy-stm32/src/lib.rs index 610c24888..eeaa04f67 100644 --- a/embassy-stm32/src/lib.rs +++ b/embassy-stm32/src/lib.rs | |||
| @@ -121,7 +121,7 @@ pub fn init(config: Config) -> Peripherals { | |||
| 121 | #[cfg(dbgmcu)] | 121 | #[cfg(dbgmcu)] |
| 122 | if config.enable_debug_during_sleep { | 122 | if config.enable_debug_during_sleep { |
| 123 | crate::pac::DBGMCU.cr().modify(|cr| { | 123 | crate::pac::DBGMCU.cr().modify(|cr| { |
| 124 | #[cfg(any(dbgmcu_f0, dbgmcu_g0, dbgmcu_u5))] | 124 | #[cfg(any(dbgmcu_f0, dbgmcu_c0, dbgmcu_g0, dbgmcu_u5))] |
| 125 | { | 125 | { |
| 126 | cr.set_dbg_stop(true); | 126 | cr.set_dbg_stop(true); |
| 127 | cr.set_dbg_standby(true); | 127 | cr.set_dbg_standby(true); |
diff --git a/embassy-stm32/src/rcc/c0.rs b/embassy-stm32/src/rcc/c0.rs new file mode 100644 index 000000000..6c7b36647 --- /dev/null +++ b/embassy-stm32/src/rcc/c0.rs | |||
| @@ -0,0 +1,233 @@ | |||
| 1 | use crate::pac::flash::vals::Latency; | ||
| 2 | use crate::pac::rcc::vals::{Hpre, Hsidiv, Ppre, Sw}; | ||
| 3 | use crate::pac::{FLASH, RCC}; | ||
| 4 | use crate::rcc::{set_freqs, Clocks}; | ||
| 5 | use crate::time::Hertz; | ||
| 6 | |||
| 7 | /// HSI speed | ||
| 8 | pub const HSI_FREQ: Hertz = Hertz(48_000_000); | ||
| 9 | |||
| 10 | /// LSI speed | ||
| 11 | pub const LSI_FREQ: Hertz = Hertz(32_000); | ||
| 12 | |||
| 13 | /// System clock mux source | ||
| 14 | #[derive(Clone, Copy)] | ||
| 15 | pub enum ClockSrc { | ||
| 16 | HSE(Hertz), | ||
| 17 | HSI(HSIPrescaler), | ||
| 18 | LSI, | ||
| 19 | } | ||
| 20 | |||
| 21 | #[derive(Clone, Copy)] | ||
| 22 | pub enum HSIPrescaler { | ||
| 23 | NotDivided, | ||
| 24 | Div2, | ||
| 25 | Div4, | ||
| 26 | Div8, | ||
| 27 | Div16, | ||
| 28 | Div32, | ||
| 29 | Div64, | ||
| 30 | Div128, | ||
| 31 | } | ||
| 32 | |||
| 33 | impl Into<Hsidiv> for HSIPrescaler { | ||
| 34 | fn into(self) -> Hsidiv { | ||
| 35 | match self { | ||
| 36 | HSIPrescaler::NotDivided => Hsidiv::DIV1, | ||
| 37 | HSIPrescaler::Div2 => Hsidiv::DIV2, | ||
| 38 | HSIPrescaler::Div4 => Hsidiv::DIV4, | ||
| 39 | HSIPrescaler::Div8 => Hsidiv::DIV8, | ||
| 40 | HSIPrescaler::Div16 => Hsidiv::DIV16, | ||
| 41 | HSIPrescaler::Div32 => Hsidiv::DIV32, | ||
| 42 | HSIPrescaler::Div64 => Hsidiv::DIV64, | ||
| 43 | HSIPrescaler::Div128 => Hsidiv::DIV128, | ||
| 44 | } | ||
| 45 | } | ||
| 46 | } | ||
| 47 | |||
| 48 | /// AHB prescaler | ||
| 49 | #[derive(Clone, Copy, PartialEq)] | ||
| 50 | pub enum AHBPrescaler { | ||
| 51 | NotDivided, | ||
| 52 | Div2, | ||
| 53 | Div4, | ||
| 54 | Div8, | ||
| 55 | Div16, | ||
| 56 | Div64, | ||
| 57 | Div128, | ||
| 58 | Div256, | ||
| 59 | Div512, | ||
| 60 | } | ||
| 61 | |||
| 62 | /// APB prescaler | ||
| 63 | #[derive(Clone, Copy)] | ||
| 64 | pub enum APBPrescaler { | ||
| 65 | NotDivided, | ||
| 66 | Div2, | ||
| 67 | Div4, | ||
| 68 | Div8, | ||
| 69 | Div16, | ||
| 70 | } | ||
| 71 | |||
| 72 | impl Into<Ppre> for APBPrescaler { | ||
| 73 | fn into(self) -> Ppre { | ||
| 74 | match self { | ||
| 75 | APBPrescaler::NotDivided => Ppre::DIV1, | ||
| 76 | APBPrescaler::Div2 => Ppre::DIV2, | ||
| 77 | APBPrescaler::Div4 => Ppre::DIV4, | ||
| 78 | APBPrescaler::Div8 => Ppre::DIV8, | ||
| 79 | APBPrescaler::Div16 => Ppre::DIV16, | ||
| 80 | } | ||
| 81 | } | ||
| 82 | } | ||
| 83 | |||
| 84 | impl Into<Hpre> for AHBPrescaler { | ||
| 85 | fn into(self) -> Hpre { | ||
| 86 | match self { | ||
| 87 | AHBPrescaler::NotDivided => Hpre::DIV1, | ||
| 88 | AHBPrescaler::Div2 => Hpre::DIV2, | ||
| 89 | AHBPrescaler::Div4 => Hpre::DIV4, | ||
| 90 | AHBPrescaler::Div8 => Hpre::DIV8, | ||
| 91 | AHBPrescaler::Div16 => Hpre::DIV16, | ||
| 92 | AHBPrescaler::Div64 => Hpre::DIV64, | ||
| 93 | AHBPrescaler::Div128 => Hpre::DIV128, | ||
| 94 | AHBPrescaler::Div256 => Hpre::DIV256, | ||
| 95 | AHBPrescaler::Div512 => Hpre::DIV512, | ||
| 96 | } | ||
| 97 | } | ||
| 98 | } | ||
| 99 | |||
| 100 | /// Clocks configutation | ||
| 101 | pub struct Config { | ||
| 102 | pub mux: ClockSrc, | ||
| 103 | pub ahb_pre: AHBPrescaler, | ||
| 104 | pub apb_pre: APBPrescaler, | ||
| 105 | } | ||
| 106 | |||
| 107 | impl Default for Config { | ||
| 108 | #[inline] | ||
| 109 | fn default() -> Config { | ||
| 110 | Config { | ||
| 111 | mux: ClockSrc::HSI(HSIPrescaler::NotDivided), | ||
| 112 | ahb_pre: AHBPrescaler::NotDivided, | ||
| 113 | apb_pre: APBPrescaler::NotDivided, | ||
| 114 | } | ||
| 115 | } | ||
| 116 | } | ||
| 117 | |||
| 118 | pub(crate) unsafe fn init(config: Config) { | ||
| 119 | let (sys_clk, sw) = match config.mux { | ||
| 120 | ClockSrc::HSI(div) => { | ||
| 121 | // Enable HSI | ||
| 122 | let div: Hsidiv = div.into(); | ||
| 123 | RCC.cr().write(|w| { | ||
| 124 | w.set_hsidiv(div); | ||
| 125 | w.set_hsion(true) | ||
| 126 | }); | ||
| 127 | while !RCC.cr().read().hsirdy() {} | ||
| 128 | |||
| 129 | (HSI_FREQ.0 >> div.0, Sw::HSI) | ||
| 130 | } | ||
| 131 | ClockSrc::HSE(freq) => { | ||
| 132 | // Enable HSE | ||
| 133 | RCC.cr().write(|w| w.set_hseon(true)); | ||
| 134 | while !RCC.cr().read().hserdy() {} | ||
| 135 | |||
| 136 | (freq.0, Sw::HSE) | ||
| 137 | } | ||
| 138 | ClockSrc::LSI => { | ||
| 139 | // Enable LSI | ||
| 140 | RCC.csr2().write(|w| w.set_lsion(true)); | ||
| 141 | while !RCC.csr2().read().lsirdy() {} | ||
| 142 | (LSI_FREQ.0, Sw::LSI) | ||
| 143 | } | ||
| 144 | }; | ||
| 145 | |||
| 146 | // Determine the flash latency implied by the target clock speed | ||
| 147 | // RM0454 § 3.3.4: | ||
| 148 | let target_flash_latency = if sys_clk <= 24_000_000 { | ||
| 149 | Latency::WS0 | ||
| 150 | } else { | ||
| 151 | Latency::WS1 | ||
| 152 | }; | ||
| 153 | |||
| 154 | // Increase the number of cycles we wait for flash if the new value is higher | ||
| 155 | // There's no harm in waiting a little too much before the clock change, but we'll | ||
| 156 | // crash immediately if we don't wait enough after the clock change | ||
| 157 | let mut set_flash_latency_after = false; | ||
| 158 | FLASH.acr().modify(|w| { | ||
| 159 | // Is the current flash latency less than what we need at the new SYSCLK? | ||
| 160 | if w.latency().0 <= target_flash_latency.0 { | ||
| 161 | // We must increase the number of wait states now | ||
| 162 | w.set_latency(target_flash_latency) | ||
| 163 | } else { | ||
| 164 | // We may decrease the number of wait states later | ||
| 165 | set_flash_latency_after = true; | ||
| 166 | } | ||
| 167 | |||
| 168 | // RM0490 § 3.3.4: | ||
| 169 | // > Prefetch is enabled by setting the PRFTEN bit of the FLASH access control register | ||
| 170 | // > (FLASH_ACR). This feature is useful if at least one wait state is needed to access the | ||
| 171 | // > Flash memory. | ||
| 172 | // | ||
| 173 | // Enable flash prefetching if we have at least one wait state, and disable it otherwise. | ||
| 174 | w.set_prften(target_flash_latency.0 > 0); | ||
| 175 | }); | ||
| 176 | |||
| 177 | if !set_flash_latency_after { | ||
| 178 | // Spin until the effective flash latency is compatible with the clock change | ||
| 179 | while FLASH.acr().read().latency().0 < target_flash_latency.0 {} | ||
| 180 | } | ||
| 181 | |||
| 182 | // Configure SYSCLK source, HCLK divisor, and PCLK divisor all at once | ||
| 183 | let (sw, hpre, ppre) = (sw.into(), config.ahb_pre.into(), config.apb_pre.into()); | ||
| 184 | RCC.cfgr().modify(|w| { | ||
| 185 | w.set_sw(sw); | ||
| 186 | w.set_hpre(hpre); | ||
| 187 | w.set_ppre(ppre); | ||
| 188 | }); | ||
| 189 | |||
| 190 | if set_flash_latency_after { | ||
| 191 | // We can make the flash require fewer wait states | ||
| 192 | // Spin until the SYSCLK changes have taken effect | ||
| 193 | loop { | ||
| 194 | let cfgr = RCC.cfgr().read(); | ||
| 195 | if cfgr.sw() == sw && cfgr.hpre() == hpre && cfgr.ppre() == ppre { | ||
| 196 | break; | ||
| 197 | } | ||
| 198 | } | ||
| 199 | |||
| 200 | // Set the flash latency to require fewer wait states | ||
| 201 | FLASH.acr().modify(|w| w.set_latency(target_flash_latency)); | ||
| 202 | } | ||
| 203 | |||
| 204 | let ahb_div = match config.ahb_pre { | ||
| 205 | AHBPrescaler::NotDivided => 1, | ||
| 206 | AHBPrescaler::Div2 => 2, | ||
| 207 | AHBPrescaler::Div4 => 4, | ||
| 208 | AHBPrescaler::Div8 => 8, | ||
| 209 | AHBPrescaler::Div16 => 16, | ||
| 210 | AHBPrescaler::Div64 => 64, | ||
| 211 | AHBPrescaler::Div128 => 128, | ||
| 212 | AHBPrescaler::Div256 => 256, | ||
| 213 | AHBPrescaler::Div512 => 512, | ||
| 214 | }; | ||
| 215 | let ahb_freq = sys_clk / ahb_div; | ||
| 216 | |||
| 217 | let (apb_freq, apb_tim_freq) = match config.apb_pre { | ||
| 218 | APBPrescaler::NotDivided => (ahb_freq, ahb_freq), | ||
| 219 | pre => { | ||
| 220 | let pre: Ppre = pre.into(); | ||
| 221 | let pre: u8 = 1 << (pre.0 - 3); | ||
| 222 | let freq = ahb_freq / pre as u32; | ||
| 223 | (freq, freq * 2) | ||
| 224 | } | ||
| 225 | }; | ||
| 226 | |||
| 227 | set_freqs(Clocks { | ||
| 228 | sys: Hertz(sys_clk), | ||
| 229 | ahb1: Hertz(ahb_freq), | ||
| 230 | apb1: Hertz(apb_freq), | ||
| 231 | apb1_tim: Hertz(apb_tim_freq), | ||
| 232 | }); | ||
| 233 | } | ||
diff --git a/embassy-stm32/src/rcc/mod.rs b/embassy-stm32/src/rcc/mod.rs index 1b1180c03..0a52089d1 100644 --- a/embassy-stm32/src/rcc/mod.rs +++ b/embassy-stm32/src/rcc/mod.rs | |||
| @@ -10,6 +10,7 @@ use crate::time::Hertz; | |||
| 10 | #[cfg_attr(rcc_f3, path = "f3.rs")] | 10 | #[cfg_attr(rcc_f3, path = "f3.rs")] |
| 11 | #[cfg_attr(any(rcc_f4, rcc_f410), path = "f4.rs")] | 11 | #[cfg_attr(any(rcc_f4, rcc_f410), path = "f4.rs")] |
| 12 | #[cfg_attr(rcc_f7, path = "f7.rs")] | 12 | #[cfg_attr(rcc_f7, path = "f7.rs")] |
| 13 | #[cfg_attr(rcc_c0, path = "c0.rs")] | ||
| 13 | #[cfg_attr(rcc_g0, path = "g0.rs")] | 14 | #[cfg_attr(rcc_g0, path = "g0.rs")] |
| 14 | #[cfg_attr(rcc_g4, path = "g4.rs")] | 15 | #[cfg_attr(rcc_g4, path = "g4.rs")] |
| 15 | #[cfg_attr(any(rcc_h7, rcc_h7ab), path = "h7.rs")] | 16 | #[cfg_attr(any(rcc_h7, rcc_h7ab), path = "h7.rs")] |
| @@ -30,9 +31,9 @@ pub struct Clocks { | |||
| 30 | // APB | 31 | // APB |
| 31 | pub apb1: Hertz, | 32 | pub apb1: Hertz, |
| 32 | pub apb1_tim: Hertz, | 33 | pub apb1_tim: Hertz, |
| 33 | #[cfg(not(rcc_g0))] | 34 | #[cfg(not(any(rcc_c0, rcc_g0)))] |
| 34 | pub apb2: Hertz, | 35 | pub apb2: Hertz, |
| 35 | #[cfg(not(rcc_g0))] | 36 | #[cfg(not(any(rcc_c0, rcc_g0)))] |
| 36 | pub apb2_tim: Hertz, | 37 | pub apb2_tim: Hertz, |
| 37 | #[cfg(any(rcc_wl5, rcc_wle, rcc_u5))] | 38 | #[cfg(any(rcc_wl5, rcc_wle, rcc_u5))] |
| 38 | pub apb3: Hertz, | 39 | pub apb3: Hertz, |
diff --git a/stm32-data b/stm32-data | |||
| Subproject 844793fc3da2ba3f12ab6a69b78cd8e6fb5497b | Subproject 96decdd6114d78813c1f748fb878a45e1b03bf7 | ||
diff --git a/stm32-metapac-gen/Cargo.toml b/stm32-metapac-gen/Cargo.toml index 9598a5945..6d136ba6b 100644 --- a/stm32-metapac-gen/Cargo.toml +++ b/stm32-metapac-gen/Cargo.toml | |||
| @@ -7,7 +7,7 @@ license = "MIT OR Apache-2.0" | |||
| 7 | 7 | ||
| 8 | [dependencies] | 8 | [dependencies] |
| 9 | regex = "1.5.4" | 9 | regex = "1.5.4" |
| 10 | chiptool = { git = "https://github.com/embassy-rs/chiptool", rev = "28ffa8a19d84914089547f52900ffb5877a5dc23" } | 10 | chiptool = { git = "https://github.com/embassy-rs/chiptool", rev = "1d9e0a39a6acc291e50cabc4ed617a87f06d5e89" } |
| 11 | serde = { version = "1.0.130", features = [ "derive" ] } | 11 | serde = { version = "1.0.130", features = [ "derive" ] } |
| 12 | serde_json = "1.0.87" | 12 | serde_json = "1.0.87" |
| 13 | serde_yaml = "0.8.21" | 13 | serde_yaml = "0.8.21" |
diff --git a/stm32-metapac/Cargo.toml b/stm32-metapac/Cargo.toml index 9d5aba0c0..2605cf3d3 100644 --- a/stm32-metapac/Cargo.toml +++ b/stm32-metapac/Cargo.toml | |||
| @@ -27,6 +27,7 @@ flavors = [ | |||
| 27 | { regex_feature = "stm32f3.*", target = "thumbv7em-none-eabi" }, | 27 | { regex_feature = "stm32f3.*", target = "thumbv7em-none-eabi" }, |
| 28 | { regex_feature = "stm32f4.*", target = "thumbv7em-none-eabi" }, | 28 | { regex_feature = "stm32f4.*", target = "thumbv7em-none-eabi" }, |
| 29 | { regex_feature = "stm32f7.*", target = "thumbv7em-none-eabi" }, | 29 | { regex_feature = "stm32f7.*", target = "thumbv7em-none-eabi" }, |
| 30 | { regex_feature = "stm32c0.*", target = "thumbv6m-none-eabi" }, | ||
| 30 | { regex_feature = "stm32g0.*", target = "thumbv6m-none-eabi" }, | 31 | { regex_feature = "stm32g0.*", target = "thumbv6m-none-eabi" }, |
| 31 | { regex_feature = "stm32g4.*", target = "thumbv7em-none-eabi" }, | 32 | { regex_feature = "stm32g4.*", target = "thumbv7em-none-eabi" }, |
| 32 | { regex_feature = "stm32h7.*", target = "thumbv7em-none-eabi" }, | 33 | { regex_feature = "stm32h7.*", target = "thumbv7em-none-eabi" }, |
| @@ -67,6 +68,19 @@ memory-x = [] | |||
| 67 | 68 | ||
| 68 | # BEGIN GENERATED FEATURES | 69 | # BEGIN GENERATED FEATURES |
| 69 | # Generated by stm32-gen-features. DO NOT EDIT. | 70 | # Generated by stm32-gen-features. DO NOT EDIT. |
| 71 | stm32c011d6 = [] | ||
| 72 | stm32c011f4 = [] | ||
| 73 | stm32c011f6 = [] | ||
| 74 | stm32c011j4 = [] | ||
| 75 | stm32c011j6 = [] | ||
| 76 | stm32c031c4 = [] | ||
| 77 | stm32c031c6 = [] | ||
| 78 | stm32c031f4 = [] | ||
| 79 | stm32c031f6 = [] | ||
| 80 | stm32c031g4 = [] | ||
| 81 | stm32c031g6 = [] | ||
| 82 | stm32c031k4 = [] | ||
| 83 | stm32c031k6 = [] | ||
| 70 | stm32f030c6 = [] | 84 | stm32f030c6 = [] |
| 71 | stm32f030c8 = [] | 85 | stm32f030c8 = [] |
| 72 | stm32f030cc = [] | 86 | stm32f030cc = [] |
| @@ -1275,11 +1289,9 @@ stm32u575zi = [] | |||
| 1275 | stm32u585ai = [] | 1289 | stm32u585ai = [] |
| 1276 | stm32u585ci = [] | 1290 | stm32u585ci = [] |
| 1277 | stm32u585oi = [] | 1291 | stm32u585oi = [] |
| 1278 | stm32u585qe = [] | ||
| 1279 | stm32u585qi = [] | 1292 | stm32u585qi = [] |
| 1280 | stm32u585ri = [] | 1293 | stm32u585ri = [] |
| 1281 | stm32u585vi = [] | 1294 | stm32u585vi = [] |
| 1282 | stm32u585ze = [] | ||
| 1283 | stm32u585zi = [] | 1295 | stm32u585zi = [] |
| 1284 | stm32wb10cc = [] | 1296 | stm32wb10cc = [] |
| 1285 | stm32wb15cc = [] | 1297 | stm32wb15cc = [] |
| @@ -1297,7 +1309,6 @@ stm32wb55vc = [] | |||
| 1297 | stm32wb55ve = [] | 1309 | stm32wb55ve = [] |
| 1298 | stm32wb55vg = [] | 1310 | stm32wb55vg = [] |
| 1299 | stm32wb55vy = [] | 1311 | stm32wb55vy = [] |
| 1300 | stm32wb5mmg = [] | ||
| 1301 | stm32wl54cc-cm4 = [] | 1312 | stm32wl54cc-cm4 = [] |
| 1302 | stm32wl54cc-cm0p = [] | 1313 | stm32wl54cc-cm0p = [] |
| 1303 | stm32wl54jc-cm4 = [] | 1314 | stm32wl54jc-cm4 = [] |
| @@ -1306,8 +1317,6 @@ stm32wl55cc-cm4 = [] | |||
| 1306 | stm32wl55cc-cm0p = [] | 1317 | stm32wl55cc-cm0p = [] |
| 1307 | stm32wl55jc-cm4 = [] | 1318 | stm32wl55jc-cm4 = [] |
| 1308 | stm32wl55jc-cm0p = [] | 1319 | stm32wl55jc-cm0p = [] |
| 1309 | stm32wl55uc-cm4 = [] | ||
| 1310 | stm32wl55uc-cm0p = [] | ||
| 1311 | stm32wle4c8 = [] | 1320 | stm32wle4c8 = [] |
| 1312 | stm32wle4cb = [] | 1321 | stm32wle4cb = [] |
| 1313 | stm32wle4cc = [] | 1322 | stm32wle4cc = [] |
| @@ -1320,6 +1329,4 @@ stm32wle5cc = [] | |||
| 1320 | stm32wle5j8 = [] | 1329 | stm32wle5j8 = [] |
| 1321 | stm32wle5jb = [] | 1330 | stm32wle5jb = [] |
| 1322 | stm32wle5jc = [] | 1331 | stm32wle5jc = [] |
| 1323 | stm32wle5u8 = [] | ||
| 1324 | stm32wle5ub = [] | ||
| 1325 | # END GENERATED FEATURES | 1332 | # END GENERATED FEATURES |
