aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRasmus Melchior Jacobsen <[email protected]>2023-05-25 16:06:02 +0200
committerRasmus Melchior Jacobsen <[email protected]>2023-05-25 16:06:02 +0200
commit963f3e305971d293d3e64f7bc073902152fbf66c (patch)
tree88bbe793a747456f3eb2bc1703d098fa1d52456d
parent6efcc9acaa15c6fa696c67b224297f9086732a75 (diff)
Align with updated stm32 metapac
-rw-r--r--embassy-stm32/Cargo.toml4
-rw-r--r--embassy-stm32/src/rcc/g4.rs84
-rw-r--r--embassy-stm32/src/rtc/v3.rs4
3 files changed, 57 insertions, 35 deletions
diff --git a/embassy-stm32/Cargo.toml b/embassy-stm32/Cargo.toml
index 21adb5ddf..e5e321a25 100644
--- a/embassy-stm32/Cargo.toml
+++ b/embassy-stm32/Cargo.toml
@@ -58,7 +58,7 @@ sdio-host = "0.5.0"
58embedded-sdmmc = { git = "https://github.com/embassy-rs/embedded-sdmmc-rs", rev = "a4f293d3a6f72158385f79c98634cb8a14d0d2fc", optional = true } 58embedded-sdmmc = { git = "https://github.com/embassy-rs/embedded-sdmmc-rs", rev = "a4f293d3a6f72158385f79c98634cb8a14d0d2fc", optional = true }
59critical-section = "1.1" 59critical-section = "1.1"
60atomic-polyfill = "1.0.1" 60atomic-polyfill = "1.0.1"
61stm32-metapac = "7" 61stm32-metapac = "8"
62vcell = "0.1.3" 62vcell = "0.1.3"
63bxcan = "0.7.0" 63bxcan = "0.7.0"
64nb = "1.0.0" 64nb = "1.0.0"
@@ -75,7 +75,7 @@ critical-section = { version = "1.1", features = ["std"] }
75[build-dependencies] 75[build-dependencies]
76proc-macro2 = "1.0.36" 76proc-macro2 = "1.0.36"
77quote = "1.0.15" 77quote = "1.0.15"
78stm32-metapac = { version = "7", default-features = false, features = ["metadata"]} 78stm32-metapac = { version = "8", default-features = false, features = ["metadata"]}
79 79
80[features] 80[features]
81default = ["stm32-metapac/rt"] 81default = ["stm32-metapac/rt"]
diff --git a/embassy-stm32/src/rcc/g4.rs b/embassy-stm32/src/rcc/g4.rs
index 0f078d328..7e748c7b5 100644
--- a/embassy-stm32/src/rcc/g4.rs
+++ b/embassy-stm32/src/rcc/g4.rs
@@ -1,3 +1,5 @@
1use stm32_metapac::rcc::vals::{Hpre, Ppre, Sw};
2
1use crate::pac::{PWR, RCC}; 3use crate::pac::{PWR, RCC};
2use crate::rcc::{set_freqs, Clocks}; 4use crate::rcc::{set_freqs, Clocks};
3use crate::time::Hertz; 5use crate::time::Hertz;
@@ -39,30 +41,58 @@ pub enum APBPrescaler {
39 Div16, 41 Div16,
40} 42}
41 43
42impl Into<u8> for APBPrescaler { 44impl AHBPrescaler {
43 fn into(self) -> u8 { 45 const fn div(self) -> u32 {
46 match self {
47 AHBPrescaler::NotDivided => 1,
48 AHBPrescaler::Div2 => 2,
49 AHBPrescaler::Div4 => 4,
50 AHBPrescaler::Div8 => 8,
51 AHBPrescaler::Div16 => 16,
52 AHBPrescaler::Div64 => 64,
53 AHBPrescaler::Div128 => 128,
54 AHBPrescaler::Div256 => 256,
55 AHBPrescaler::Div512 => 512,
56 }
57 }
58}
59
60impl APBPrescaler {
61 const fn div(self) -> u32 {
44 match self { 62 match self {
45 APBPrescaler::NotDivided => 1, 63 APBPrescaler::NotDivided => 1,
46 APBPrescaler::Div2 => 0x04, 64 APBPrescaler::Div2 => 2,
47 APBPrescaler::Div4 => 0x05, 65 APBPrescaler::Div4 => 4,
48 APBPrescaler::Div8 => 0x06, 66 APBPrescaler::Div8 => 8,
49 APBPrescaler::Div16 => 0x07, 67 APBPrescaler::Div16 => 16,
50 } 68 }
51 } 69 }
52} 70}
53 71
54impl Into<u8> for AHBPrescaler { 72impl Into<Ppre> for APBPrescaler {
55 fn into(self) -> u8 { 73 fn into(self) -> Ppre {
56 match self { 74 match self {
57 AHBPrescaler::NotDivided => 1, 75 APBPrescaler::NotDivided => Ppre::DIV1,
58 AHBPrescaler::Div2 => 0x08, 76 APBPrescaler::Div2 => Ppre::DIV2,
59 AHBPrescaler::Div4 => 0x09, 77 APBPrescaler::Div4 => Ppre::DIV4,
60 AHBPrescaler::Div8 => 0x0a, 78 APBPrescaler::Div8 => Ppre::DIV8,
61 AHBPrescaler::Div16 => 0x0b, 79 APBPrescaler::Div16 => Ppre::DIV16,
62 AHBPrescaler::Div64 => 0x0c, 80 }
63 AHBPrescaler::Div128 => 0x0d, 81 }
64 AHBPrescaler::Div256 => 0x0e, 82}
65 AHBPrescaler::Div512 => 0x0f, 83
84impl 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,
66 } 96 }
67 } 97 }
68} 98}
@@ -96,19 +126,19 @@ pub(crate) unsafe fn init(config: Config) {
96 RCC.cr().write(|w| w.set_hsion(true)); 126 RCC.cr().write(|w| w.set_hsion(true));
97 while !RCC.cr().read().hsirdy() {} 127 while !RCC.cr().read().hsirdy() {}
98 128
99 (HSI_FREQ.0, 0x01) 129 (HSI_FREQ.0, Sw::HSI16)
100 } 130 }
101 ClockSrc::HSE(freq) => { 131 ClockSrc::HSE(freq) => {
102 // Enable HSE 132 // Enable HSE
103 RCC.cr().write(|w| w.set_hseon(true)); 133 RCC.cr().write(|w| w.set_hseon(true));
104 while !RCC.cr().read().hserdy() {} 134 while !RCC.cr().read().hserdy() {}
105 135
106 (freq.0, 0x02) 136 (freq.0, Sw::HSE)
107 } 137 }
108 }; 138 };
109 139
110 RCC.cfgr().modify(|w| { 140 RCC.cfgr().modify(|w| {
111 w.set_sw(sw.into()); 141 w.set_sw(sw);
112 w.set_hpre(config.ahb_pre.into()); 142 w.set_hpre(config.ahb_pre.into());
113 w.set_ppre1(config.apb1_pre.into()); 143 w.set_ppre1(config.apb1_pre.into());
114 w.set_ppre2(config.apb2_pre.into()); 144 w.set_ppre2(config.apb2_pre.into());
@@ -116,19 +146,13 @@ pub(crate) unsafe fn init(config: Config) {
116 146
117 let ahb_freq: u32 = match config.ahb_pre { 147 let ahb_freq: u32 = match config.ahb_pre {
118 AHBPrescaler::NotDivided => sys_clk, 148 AHBPrescaler::NotDivided => sys_clk,
119 pre => { 149 pre => sys_clk / pre.div(),
120 let pre: u8 = pre.into();
121 let pre = 1 << (pre as u32 - 7);
122 sys_clk / pre
123 }
124 }; 150 };
125 151
126 let (apb1_freq, apb1_tim_freq) = match config.apb1_pre { 152 let (apb1_freq, apb1_tim_freq) = match config.apb1_pre {
127 APBPrescaler::NotDivided => (ahb_freq, ahb_freq), 153 APBPrescaler::NotDivided => (ahb_freq, ahb_freq),
128 pre => { 154 pre => {
129 let pre: u8 = pre.into(); 155 let freq = ahb_freq / pre.div();
130 let pre: u8 = 1 << (pre - 3);
131 let freq = ahb_freq / pre as u32;
132 (freq, freq * 2) 156 (freq, freq * 2)
133 } 157 }
134 }; 158 };
@@ -136,9 +160,7 @@ pub(crate) unsafe fn init(config: Config) {
136 let (apb2_freq, apb2_tim_freq) = match config.apb2_pre { 160 let (apb2_freq, apb2_tim_freq) = match config.apb2_pre {
137 APBPrescaler::NotDivided => (ahb_freq, ahb_freq), 161 APBPrescaler::NotDivided => (ahb_freq, ahb_freq),
138 pre => { 162 pre => {
139 let pre: u8 = pre.into(); 163 let freq = ahb_freq / pre.div();
140 let pre: u8 = 1 << (pre - 3);
141 let freq = ahb_freq / pre as u32;
142 (freq, freq * 2) 164 (freq, freq * 2)
143 } 165 }
144 }; 166 };
diff --git a/embassy-stm32/src/rtc/v3.rs b/embassy-stm32/src/rtc/v3.rs
index 19c52ee02..546fe88c7 100644
--- a/embassy-stm32/src/rtc/v3.rs
+++ b/embassy-stm32/src/rtc/v3.rs
@@ -9,7 +9,7 @@ impl<'d, T: Instance> super::Rtc<'d, T> {
9 pub(super) fn apply_config(&mut self, rtc_config: RtcConfig) { 9 pub(super) fn apply_config(&mut self, rtc_config: RtcConfig) {
10 // Unlock the backup domain 10 // Unlock the backup domain
11 unsafe { 11 unsafe {
12 #[cfg(any(rtc_v3u5, rcc_g0))] 12 #[cfg(any(rtc_v3u5, rcc_g0, rcc_g4))]
13 use crate::pac::rcc::vals::Rtcsel; 13 use crate::pac::rcc::vals::Rtcsel;
14 #[cfg(not(any(rtc_v3u5, rcc_g0, rcc_g4, rcc_wl5, rcc_wle)))] 14 #[cfg(not(any(rtc_v3u5, rcc_g0, rcc_g4, rcc_wl5, rcc_wle)))]
15 use crate::pac::rtc::vals::Rtcsel; 15 use crate::pac::rtc::vals::Rtcsel;
@@ -31,7 +31,7 @@ impl<'d, T: Instance> super::Rtc<'d, T> {
31 assert!(!reg.lsecsson(), "RTC is not compatible with LSE CSS, yet."); 31 assert!(!reg.lsecsson(), "RTC is not compatible with LSE CSS, yet.");
32 32
33 let config_rtcsel = rtc_config.clock_config as u8; 33 let config_rtcsel = rtc_config.clock_config as u8;
34 #[cfg(not(any(rcc_wl5, rcc_wle, rcc_g4)))] 34 #[cfg(not(any(rcc_wl5, rcc_wle)))]
35 let config_rtcsel = Rtcsel(config_rtcsel); 35 let config_rtcsel = Rtcsel(config_rtcsel);
36 36
37 if !reg.rtcen() || reg.rtcsel() != config_rtcsel { 37 if !reg.rtcen() || reg.rtcsel() != config_rtcsel {