aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlf Lilleengen <[email protected]>2021-09-23 14:43:17 +0200
committerUlf Lilleengen <[email protected]>2021-09-23 14:51:16 +0200
commitb6fc19182b4ae02ea1e9107ca28b88f4a3b0b60a (patch)
treef605fca37dda14c13ce655b6682fee957bd358da
parentd5b21b881eeb1cb391d383838383dc71138a0de1 (diff)
Add pwr for L1 and update RCC to new reg block
-rw-r--r--embassy-stm32/src/pwr/l1.rs1
-rw-r--r--embassy-stm32/src/pwr/mod.rs1
-rw-r--r--embassy-stm32/src/rcc/l1/mod.rs43
m---------stm32-data0
4 files changed, 24 insertions, 21 deletions
diff --git a/embassy-stm32/src/pwr/l1.rs b/embassy-stm32/src/pwr/l1.rs
new file mode 100644
index 000000000..8b1378917
--- /dev/null
+++ b/embassy-stm32/src/pwr/l1.rs
@@ -0,0 +1 @@
diff --git a/embassy-stm32/src/pwr/mod.rs b/embassy-stm32/src/pwr/mod.rs
index b19ab3265..37f7e572e 100644
--- a/embassy-stm32/src/pwr/mod.rs
+++ b/embassy-stm32/src/pwr/mod.rs
@@ -2,6 +2,7 @@
2#[cfg_attr(pwr_f4, path = "f4.rs")] 2#[cfg_attr(pwr_f4, path = "f4.rs")]
3#[cfg_attr(pwr_wl5, path = "wl5.rs")] 3#[cfg_attr(pwr_wl5, path = "wl5.rs")]
4#[cfg_attr(pwr_g0, path = "g0.rs")] 4#[cfg_attr(pwr_g0, path = "g0.rs")]
5#[cfg_attr(pwr_l1, path = "l1.rs")]
5mod _version; 6mod _version;
6 7
7pub use _version::*; 8pub use _version::*;
diff --git a/embassy-stm32/src/rcc/l1/mod.rs b/embassy-stm32/src/rcc/l1/mod.rs
index 25b5609c4..f6edd4e4f 100644
--- a/embassy-stm32/src/rcc/l1/mod.rs
+++ b/embassy-stm32/src/rcc/l1/mod.rs
@@ -7,7 +7,6 @@ use crate::time::U32Ext;
7use core::marker::PhantomData; 7use core::marker::PhantomData;
8use embassy::util::Unborrow; 8use embassy::util::Unborrow;
9use embassy_hal_common::unborrow; 9use embassy_hal_common::unborrow;
10use pac::rcc::vals::{Hpre, Ppre, Sw};
11 10
12/// Most of clock setup is copied from rcc/l0 11/// Most of clock setup is copied from rcc/l0
13 12
@@ -22,30 +21,32 @@ pub enum ClockSrc {
22 HSI, 21 HSI,
23} 22}
24 23
24type Ppre = u8;
25impl Into<Ppre> for APBPrescaler { 25impl Into<Ppre> for APBPrescaler {
26 fn into(self) -> Ppre { 26 fn into(self) -> Ppre {
27 match self { 27 match self {
28 APBPrescaler::NotDivided => Ppre::DIV1, 28 APBPrescaler::NotDivided => 0b000,
29 APBPrescaler::Div2 => Ppre::DIV2, 29 APBPrescaler::Div2 => 0b100,
30 APBPrescaler::Div4 => Ppre::DIV4, 30 APBPrescaler::Div4 => 0b101,
31 APBPrescaler::Div8 => Ppre::DIV8, 31 APBPrescaler::Div8 => 0b110,
32 APBPrescaler::Div16 => Ppre::DIV16, 32 APBPrescaler::Div16 => 0b111,
33 } 33 }
34 } 34 }
35} 35}
36 36
37type Hpre = u8;
37impl Into<Hpre> for AHBPrescaler { 38impl Into<Hpre> for AHBPrescaler {
38 fn into(self) -> Hpre { 39 fn into(self) -> Hpre {
39 match self { 40 match self {
40 AHBPrescaler::NotDivided => Hpre::DIV1, 41 AHBPrescaler::NotDivided => 0b0000,
41 AHBPrescaler::Div2 => Hpre::DIV2, 42 AHBPrescaler::Div2 => 0b1000,
42 AHBPrescaler::Div4 => Hpre::DIV4, 43 AHBPrescaler::Div4 => 0b1001,
43 AHBPrescaler::Div8 => Hpre::DIV8, 44 AHBPrescaler::Div8 => 0b1010,
44 AHBPrescaler::Div16 => Hpre::DIV16, 45 AHBPrescaler::Div16 => 0b1011,
45 AHBPrescaler::Div64 => Hpre::DIV64, 46 AHBPrescaler::Div64 => 0b1100,
46 AHBPrescaler::Div128 => Hpre::DIV128, 47 AHBPrescaler::Div128 => 0b1101,
47 AHBPrescaler::Div256 => Hpre::DIV256, 48 AHBPrescaler::Div256 => 0b1110,
48 AHBPrescaler::Div512 => Hpre::DIV512, 49 AHBPrescaler::Div512 => 0b1111,
49 } 50 }
50 } 51 }
51} 52}
@@ -157,7 +158,7 @@ impl RccExt for RCC {
157 } 158 }
158 159
159 let freq = 32_768 * (1 << (range as u8 + 1)); 160 let freq = 32_768 * (1 << (range as u8 + 1));
160 (freq, Sw::MSI) 161 (freq, 0b00)
161 } 162 }
162 ClockSrc::HSI => { 163 ClockSrc::HSI => {
163 // Enable HSI 164 // Enable HSI
@@ -166,7 +167,7 @@ impl RccExt for RCC {
166 while !rcc.cr().read().hsirdy() {} 167 while !rcc.cr().read().hsirdy() {}
167 } 168 }
168 169
169 (HSI_FREQ, Sw::HSI) 170 (HSI_FREQ, 0b01)
170 } 171 }
171 ClockSrc::HSE(freq) => { 172 ClockSrc::HSE(freq) => {
172 // Enable HSE 173 // Enable HSE
@@ -175,7 +176,7 @@ impl RccExt for RCC {
175 while !rcc.cr().read().hserdy() {} 176 while !rcc.cr().read().hserdy() {}
176 } 177 }
177 178
178 (freq.0, Sw::HSE) 179 (freq.0, 0b10)
179 } 180 }
180 }; 181 };
181 182
@@ -192,7 +193,7 @@ impl RccExt for RCC {
192 AHBPrescaler::NotDivided => sys_clk, 193 AHBPrescaler::NotDivided => sys_clk,
193 pre => { 194 pre => {
194 let pre: Hpre = pre.into(); 195 let pre: Hpre = pre.into();
195 let pre = 1 << (pre.0 as u32 - 7); 196 let pre = 1 << (pre as u32 - 7);
196 sys_clk / pre 197 sys_clk / pre
197 } 198 }
198 }; 199 };
@@ -201,7 +202,7 @@ impl RccExt for RCC {
201 APBPrescaler::NotDivided => (ahb_freq, ahb_freq), 202 APBPrescaler::NotDivided => (ahb_freq, ahb_freq),
202 pre => { 203 pre => {
203 let pre: Ppre = pre.into(); 204 let pre: Ppre = pre.into();
204 let pre: u8 = 1 << (pre.0 - 3); 205 let pre: u8 = 1 << (pre - 3);
205 let freq = ahb_freq / pre as u32; 206 let freq = ahb_freq / pre as u32;
206 (freq, freq * 2) 207 (freq, freq * 2)
207 } 208 }
@@ -211,7 +212,7 @@ impl RccExt for RCC {
211 APBPrescaler::NotDivided => (ahb_freq, ahb_freq), 212 APBPrescaler::NotDivided => (ahb_freq, ahb_freq),
212 pre => { 213 pre => {
213 let pre: Ppre = pre.into(); 214 let pre: Ppre = pre.into();
214 let pre: u8 = 1 << (pre.0 - 3); 215 let pre: u8 = 1 << (pre - 3);
215 let freq = ahb_freq / (1 << (pre as u8 - 3)); 216 let freq = ahb_freq / (1 << (pre as u8 - 3));
216 (freq, freq * 2) 217 (freq, freq * 2)
217 } 218 }
diff --git a/stm32-data b/stm32-data
Subproject 7f5f8e7c641d74a0e97e2d84bac61b7c6c267a7 Subproject 18df82005f29da14e7d4c442f7cff3a46939c43