aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2021-06-16 16:46:01 +0200
committerGitHub <[email protected]>2021-06-16 16:46:01 +0200
commit6386c34079913732466046194f79a683a4aefce4 (patch)
treedc7c1007adfe19c14a8f9979ed9d050ccfa75b5a
parent927be5010926f5ce1f81bd2cec75b1e8883be377 (diff)
parenta4ea08f89f47d1f3f6382997354f1d6ef8bcb58b (diff)
Merge pull request #250 from lulf/dual-core
Add support for generating PAC for dual cores
-rw-r--r--.github/workflows/rust.yml2
-rw-r--r--embassy-stm32/Cargo.toml84
-rw-r--r--embassy-stm32/gen.py19
-rw-r--r--embassy-stm32/gen_features.py17
-rw-r--r--embassy-stm32/src/rcc/mod.rs9
-rw-r--r--embassy-stm32/src/rcc/types.rs2
-rw-r--r--embassy-stm32/src/rcc/wl5x/mod.rs230
-rw-r--r--examples/stm32l0/src/bin/blinky.rs5
-rw-r--r--examples/stm32l0/src/bin/button.rs6
m---------stm32-data0
-rw-r--r--stm32-metapac/Cargo.toml93
-rw-r--r--stm32-metapac/gen/src/lib.rs89
-rw-r--r--stm32-metapac/gen_features.py14
13 files changed, 480 insertions, 90 deletions
diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml
index 0585b6d3d..f4105230d 100644
--- a/.github/workflows/rust.yml
+++ b/.github/workflows/rust.yml
@@ -71,7 +71,7 @@ jobs:
71 features: stm32f429zi,log 71 features: stm32f429zi,log
72 - package: embassy-stm32 72 - package: embassy-stm32
73 target: thumbv7em-none-eabi 73 target: thumbv7em-none-eabi
74 features: stm32h755zi,defmt 74 features: stm32h755zi_cm7,defmt
75 - package: embassy-stm32 75 - package: embassy-stm32
76 target: thumbv7em-none-eabi 76 target: thumbv7em-none-eabi
77 features: stm32l476vg,defmt 77 features: stm32l476vg,defmt
diff --git a/embassy-stm32/Cargo.toml b/embassy-stm32/Cargo.toml
index 8b9a00391..682ebaefc 100644
--- a/embassy-stm32/Cargo.toml
+++ b/embassy-stm32/Cargo.toml
@@ -239,23 +239,40 @@ stm32h743xg = [ "stm32-metapac/stm32h743xg",]
239stm32h743xi = [ "stm32-metapac/stm32h743xi",] 239stm32h743xi = [ "stm32-metapac/stm32h743xi",]
240stm32h743zg = [ "stm32-metapac/stm32h743zg",] 240stm32h743zg = [ "stm32-metapac/stm32h743zg",]
241stm32h743zi = [ "stm32-metapac/stm32h743zi",] 241stm32h743zi = [ "stm32-metapac/stm32h743zi",]
242stm32h745bg = [ "stm32-metapac/stm32h745bg",] 242stm32h745bg_cm7 = [ "stm32-metapac/stm32h745bg_cm7",]
243stm32h745bi = [ "stm32-metapac/stm32h745bi",] 243stm32h745bg_cm4 = [ "stm32-metapac/stm32h745bg_cm4",]
244stm32h745ig = [ "stm32-metapac/stm32h745ig",] 244stm32h745bi_cm7 = [ "stm32-metapac/stm32h745bi_cm7",]
245stm32h745ii = [ "stm32-metapac/stm32h745ii",] 245stm32h745bi_cm4 = [ "stm32-metapac/stm32h745bi_cm4",]
246stm32h745xg = [ "stm32-metapac/stm32h745xg",] 246stm32h745ig_cm7 = [ "stm32-metapac/stm32h745ig_cm7",]
247stm32h745xi = [ "stm32-metapac/stm32h745xi",] 247stm32h745ig_cm4 = [ "stm32-metapac/stm32h745ig_cm4",]
248stm32h745zg = [ "stm32-metapac/stm32h745zg",] 248stm32h745ii_cm7 = [ "stm32-metapac/stm32h745ii_cm7",]
249stm32h745zi = [ "stm32-metapac/stm32h745zi",] 249stm32h745ii_cm4 = [ "stm32-metapac/stm32h745ii_cm4",]
250stm32h747ag = [ "stm32-metapac/stm32h747ag",] 250stm32h745xg_cm7 = [ "stm32-metapac/stm32h745xg_cm7",]
251stm32h747ai = [ "stm32-metapac/stm32h747ai",] 251stm32h745xg_cm4 = [ "stm32-metapac/stm32h745xg_cm4",]
252stm32h747bg = [ "stm32-metapac/stm32h747bg",] 252stm32h745xi_cm7 = [ "stm32-metapac/stm32h745xi_cm7",]
253stm32h747bi = [ "stm32-metapac/stm32h747bi",] 253stm32h745xi_cm4 = [ "stm32-metapac/stm32h745xi_cm4",]
254stm32h747ig = [ "stm32-metapac/stm32h747ig",] 254stm32h745zg_cm7 = [ "stm32-metapac/stm32h745zg_cm7",]
255stm32h747ii = [ "stm32-metapac/stm32h747ii",] 255stm32h745zg_cm4 = [ "stm32-metapac/stm32h745zg_cm4",]
256stm32h747xg = [ "stm32-metapac/stm32h747xg",] 256stm32h745zi_cm7 = [ "stm32-metapac/stm32h745zi_cm7",]
257stm32h747xi = [ "stm32-metapac/stm32h747xi",] 257stm32h745zi_cm4 = [ "stm32-metapac/stm32h745zi_cm4",]
258stm32h747zi = [ "stm32-metapac/stm32h747zi",] 258stm32h747ag_cm7 = [ "stm32-metapac/stm32h747ag_cm7",]
259stm32h747ag_cm4 = [ "stm32-metapac/stm32h747ag_cm4",]
260stm32h747ai_cm7 = [ "stm32-metapac/stm32h747ai_cm7",]
261stm32h747ai_cm4 = [ "stm32-metapac/stm32h747ai_cm4",]
262stm32h747bg_cm7 = [ "stm32-metapac/stm32h747bg_cm7",]
263stm32h747bg_cm4 = [ "stm32-metapac/stm32h747bg_cm4",]
264stm32h747bi_cm7 = [ "stm32-metapac/stm32h747bi_cm7",]
265stm32h747bi_cm4 = [ "stm32-metapac/stm32h747bi_cm4",]
266stm32h747ig_cm7 = [ "stm32-metapac/stm32h747ig_cm7",]
267stm32h747ig_cm4 = [ "stm32-metapac/stm32h747ig_cm4",]
268stm32h747ii_cm7 = [ "stm32-metapac/stm32h747ii_cm7",]
269stm32h747ii_cm4 = [ "stm32-metapac/stm32h747ii_cm4",]
270stm32h747xg_cm7 = [ "stm32-metapac/stm32h747xg_cm7",]
271stm32h747xg_cm4 = [ "stm32-metapac/stm32h747xg_cm4",]
272stm32h747xi_cm7 = [ "stm32-metapac/stm32h747xi_cm7",]
273stm32h747xi_cm4 = [ "stm32-metapac/stm32h747xi_cm4",]
274stm32h747zi_cm7 = [ "stm32-metapac/stm32h747zi_cm7",]
275stm32h747zi_cm4 = [ "stm32-metapac/stm32h747zi_cm4",]
259stm32h750ib = [ "stm32-metapac/stm32h750ib",] 276stm32h750ib = [ "stm32-metapac/stm32h750ib",]
260stm32h750vb = [ "stm32-metapac/stm32h750vb",] 277stm32h750vb = [ "stm32-metapac/stm32h750vb",]
261stm32h750xb = [ "stm32-metapac/stm32h750xb",] 278stm32h750xb = [ "stm32-metapac/stm32h750xb",]
@@ -266,15 +283,24 @@ stm32h753ii = [ "stm32-metapac/stm32h753ii",]
266stm32h753vi = [ "stm32-metapac/stm32h753vi",] 283stm32h753vi = [ "stm32-metapac/stm32h753vi",]
267stm32h753xi = [ "stm32-metapac/stm32h753xi",] 284stm32h753xi = [ "stm32-metapac/stm32h753xi",]
268stm32h753zi = [ "stm32-metapac/stm32h753zi",] 285stm32h753zi = [ "stm32-metapac/stm32h753zi",]
269stm32h755bi = [ "stm32-metapac/stm32h755bi",] 286stm32h755bi_cm7 = [ "stm32-metapac/stm32h755bi_cm7",]
270stm32h755ii = [ "stm32-metapac/stm32h755ii",] 287stm32h755bi_cm4 = [ "stm32-metapac/stm32h755bi_cm4",]
271stm32h755xi = [ "stm32-metapac/stm32h755xi",] 288stm32h755ii_cm7 = [ "stm32-metapac/stm32h755ii_cm7",]
272stm32h755zi = [ "stm32-metapac/stm32h755zi",] 289stm32h755ii_cm4 = [ "stm32-metapac/stm32h755ii_cm4",]
273stm32h757ai = [ "stm32-metapac/stm32h757ai",] 290stm32h755xi_cm7 = [ "stm32-metapac/stm32h755xi_cm7",]
274stm32h757bi = [ "stm32-metapac/stm32h757bi",] 291stm32h755xi_cm4 = [ "stm32-metapac/stm32h755xi_cm4",]
275stm32h757ii = [ "stm32-metapac/stm32h757ii",] 292stm32h755zi_cm7 = [ "stm32-metapac/stm32h755zi_cm7",]
276stm32h757xi = [ "stm32-metapac/stm32h757xi",] 293stm32h755zi_cm4 = [ "stm32-metapac/stm32h755zi_cm4",]
277stm32h757zi = [ "stm32-metapac/stm32h757zi",] 294stm32h757ai_cm7 = [ "stm32-metapac/stm32h757ai_cm7",]
295stm32h757ai_cm4 = [ "stm32-metapac/stm32h757ai_cm4",]
296stm32h757bi_cm7 = [ "stm32-metapac/stm32h757bi_cm7",]
297stm32h757bi_cm4 = [ "stm32-metapac/stm32h757bi_cm4",]
298stm32h757ii_cm7 = [ "stm32-metapac/stm32h757ii_cm7",]
299stm32h757ii_cm4 = [ "stm32-metapac/stm32h757ii_cm4",]
300stm32h757xi_cm7 = [ "stm32-metapac/stm32h757xi_cm7",]
301stm32h757xi_cm4 = [ "stm32-metapac/stm32h757xi_cm4",]
302stm32h757zi_cm7 = [ "stm32-metapac/stm32h757zi_cm7",]
303stm32h757zi_cm4 = [ "stm32-metapac/stm32h757zi_cm4",]
278stm32h7a3ag = [ "stm32-metapac/stm32h7a3ag",] 304stm32h7a3ag = [ "stm32-metapac/stm32h7a3ag",]
279stm32h7a3ai = [ "stm32-metapac/stm32h7a3ai",] 305stm32h7a3ai = [ "stm32-metapac/stm32h7a3ai",]
280stm32h7a3ig = [ "stm32-metapac/stm32h7a3ig",] 306stm32h7a3ig = [ "stm32-metapac/stm32h7a3ig",]
@@ -554,4 +580,10 @@ stm32wb55vc = [ "stm32-metapac/stm32wb55vc",]
554stm32wb55ve = [ "stm32-metapac/stm32wb55ve",] 580stm32wb55ve = [ "stm32-metapac/stm32wb55ve",]
555stm32wb55vg = [ "stm32-metapac/stm32wb55vg",] 581stm32wb55vg = [ "stm32-metapac/stm32wb55vg",]
556stm32wb55vy = [ "stm32-metapac/stm32wb55vy",] 582stm32wb55vy = [ "stm32-metapac/stm32wb55vy",]
583stm32wl55cc_cm4 = [ "stm32-metapac/stm32wl55cc_cm4",]
584stm32wl55cc_cm0p = [ "stm32-metapac/stm32wl55cc_cm0p",]
585stm32wl55jc_cm4 = [ "stm32-metapac/stm32wl55jc_cm4",]
586stm32wl55jc_cm0p = [ "stm32-metapac/stm32wl55jc_cm0p",]
587stm32wl55uc_cm4 = [ "stm32-metapac/stm32wl55uc_cm4",]
588stm32wl55uc_cm0p = [ "stm32-metapac/stm32wl55uc_cm0p",]
557# END GENERATED FEATURES 589# END GENERATED FEATURES
diff --git a/embassy-stm32/gen.py b/embassy-stm32/gen.py
index 779389cac..b9391d309 100644
--- a/embassy-stm32/gen.py
+++ b/embassy-stm32/gen.py
@@ -19,10 +19,17 @@ data_path = '../stm32-data/data'
19try: 19try:
20 _, chip_name, output_file = sys.argv 20 _, chip_name, output_file = sys.argv
21except: 21except:
22 raise Exception("Usage: gen.py STM32F429ZI path/to/generated.rs") 22 raise Exception("Usage: gen.py STM32F429ZI_CM0 path/to/generated.rs")
23
24c = chip_name.split('_', 1)
25
26chip_name = c[0].upper()
27core_name = None
28
29if len(c) > 1:
30 core_name = c[1].lower()
23 31
24# ======= load chip 32# ======= load chip
25chip_name = chip_name.upper()
26with open(f'{data_path}/chips/{chip_name}.yaml', 'r') as f: 33with open(f'{data_path}/chips/{chip_name}.yaml', 'r') as f:
27 chip = yaml.load(f, Loader=SafeLoader) 34 chip = yaml.load(f, Loader=SafeLoader)
28 35
@@ -41,7 +48,13 @@ with open(output_file, 'w') as f:
41 singletons.extend((f'EXTI{x}' for x in range(16))) 48 singletons.extend((f'EXTI{x}' for x in range(16)))
42 num_dmas = 0 49 num_dmas = 0
43 50
44 for (name, peri) in chip['peripherals'].items(): 51 core = chip['cores'][0]
52 if core_name != None:
53 for c in chip['cores']:
54 if core_name == c['name']:
55 core = c
56
57 for (name, peri) in core['peripherals'].items():
45 if 'block' not in peri: 58 if 'block' not in peri:
46 continue 59 continue
47 60
diff --git a/embassy-stm32/gen_features.py b/embassy-stm32/gen_features.py
index 4c46d602e..10dfd7884 100644
--- a/embassy-stm32/gen_features.py
+++ b/embassy-stm32/gen_features.py
@@ -1,7 +1,13 @@
1import os 1import os
2import toml 2import toml
3import yaml
3from glob import glob 4from glob import glob
4 5
6try:
7 from yaml import CSafeLoader as SafeLoader
8except ImportError:
9 from yaml import SafeLoader
10
5abspath = os.path.abspath(__file__) 11abspath = os.path.abspath(__file__)
6dname = os.path.dirname(abspath) 12dname = os.path.dirname(abspath)
7os.chdir(dname) 13os.chdir(dname)
@@ -12,6 +18,7 @@ supported_families = [
12 'STM32L4', 18 'STM32L4',
13 'STM32H7', 19 'STM32H7',
14 'STM32WB55', 20 'STM32WB55',
21 'STM32WL55',
15] 22]
16 23
17# ======= load chip list 24# ======= load chip list
@@ -21,7 +28,15 @@ for f in sorted(glob('../stm32-data/data/chips/*.yaml')):
21 name = os.path.splitext(os.path.basename(f))[0] 28 name = os.path.splitext(os.path.basename(f))[0]
22 if any((family in name for family in supported_families)): 29 if any((family in name for family in supported_families)):
23 name = name.lower() 30 name = name.lower()
24 features[name] = ['stm32-metapac/' + name] 31 # ======= load chip
32 with open(f, 'r') as f:
33 chip = yaml.load(f, Loader=SafeLoader)
34
35 if len(chip['cores']) > 1:
36 for core in chip['cores']:
37 features[name + "_" + core['name']] = ['stm32-metapac/' + name + '_' + core['name']]
38 else:
39 features[name] = ['stm32-metapac/' + name]
25 40
26# ========= Update Cargo features 41# ========= Update Cargo features
27 42
diff --git a/embassy-stm32/src/rcc/mod.rs b/embassy-stm32/src/rcc/mod.rs
index 7721c2857..e84021272 100644
--- a/embassy-stm32/src/rcc/mod.rs
+++ b/embassy-stm32/src/rcc/mod.rs
@@ -16,13 +16,13 @@ pub struct Clocks {
16 #[cfg(any(rcc_l0))] 16 #[cfg(any(rcc_l0))]
17 pub ahb: Hertz, 17 pub ahb: Hertz,
18 18
19 #[cfg(any(rcc_l4, rcc_f4, rcc_h7, rcc_wb55))] 19 #[cfg(any(rcc_l4, rcc_f4, rcc_h7, rcc_wb55, rcc_wl5x))]
20 pub ahb1: Hertz, 20 pub ahb1: Hertz,
21 21
22 #[cfg(any(rcc_l4, rcc_f4, rcc_h7, rcc_wb55))] 22 #[cfg(any(rcc_l4, rcc_f4, rcc_h7, rcc_wb55, rcc_wl5x))]
23 pub ahb2: Hertz, 23 pub ahb2: Hertz,
24 24
25 #[cfg(any(rcc_l4, rcc_f4, rcc_h7, rcc_wb55))] 25 #[cfg(any(rcc_l4, rcc_f4, rcc_h7, rcc_wb55, rcc_wl5x))]
26 pub ahb3: Hertz, 26 pub ahb3: Hertz,
27 27
28 #[cfg(any(rcc_h7))] 28 #[cfg(any(rcc_h7))]
@@ -62,6 +62,9 @@ cfg_if::cfg_if! {
62 } else if #[cfg(rcc_wb55)] { 62 } else if #[cfg(rcc_wb55)] {
63 mod wb55; 63 mod wb55;
64 pub use wb55::*; 64 pub use wb55::*;
65 } else if #[cfg(rcc_wl5x)] {
66 mod wl5x;
67 pub use wl5x::*;
65 } 68 }
66} 69}
67 70
diff --git a/embassy-stm32/src/rcc/types.rs b/embassy-stm32/src/rcc/types.rs
index df7917ab3..1fcaa27e9 100644
--- a/embassy-stm32/src/rcc/types.rs
+++ b/embassy-stm32/src/rcc/types.rs
@@ -63,7 +63,7 @@ pub enum PLLMul {
63} 63}
64 64
65/// AHB prescaler 65/// AHB prescaler
66#[derive(Clone, Copy)] 66#[derive(Clone, Copy, PartialEq)]
67pub enum AHBPrescaler { 67pub enum AHBPrescaler {
68 NotDivided, 68 NotDivided,
69 Div2, 69 Div2,
diff --git a/embassy-stm32/src/rcc/wl5x/mod.rs b/embassy-stm32/src/rcc/wl5x/mod.rs
new file mode 100644
index 000000000..554a27ca2
--- /dev/null
+++ b/embassy-stm32/src/rcc/wl5x/mod.rs
@@ -0,0 +1,230 @@
1pub use super::types::*;
2use crate::pac;
3use crate::peripherals::{self, RCC};
4use crate::rcc::{get_freqs, set_freqs, Clocks};
5use crate::time::Hertz;
6use crate::time::U32Ext;
7use core::marker::PhantomData;
8use embassy::util::Unborrow;
9use embassy_extras::unborrow;
10
11/// Most of clock setup is copied from stm32l0xx-hal, and adopted to the generated PAC,
12/// and with the addition of the init function to configure a system clock.
13
14/// Only the basic setup using the HSE and HSI clocks are supported as of now.
15
16/// HSI speed
17pub const HSI_FREQ: u32 = 16_000_000;
18
19/// System clock mux source
20#[derive(Clone, Copy)]
21pub enum ClockSrc {
22 HSE(Hertz),
23 HSI16,
24}
25
26impl Into<u8> for APBPrescaler {
27 fn into(self) -> u8 {
28 match self {
29 APBPrescaler::NotDivided => 1,
30 APBPrescaler::Div2 => 0x04,
31 APBPrescaler::Div4 => 0x05,
32 APBPrescaler::Div8 => 0x06,
33 APBPrescaler::Div16 => 0x07,
34 }
35 }
36}
37
38impl Into<u8> for AHBPrescaler {
39 fn into(self) -> u8 {
40 match self {
41 AHBPrescaler::NotDivided => 1,
42 AHBPrescaler::Div2 => 0x08,
43 AHBPrescaler::Div4 => 0x09,
44 AHBPrescaler::Div8 => 0x0a,
45 AHBPrescaler::Div16 => 0x0b,
46 AHBPrescaler::Div64 => 0x0c,
47 AHBPrescaler::Div128 => 0x0d,
48 AHBPrescaler::Div256 => 0x0e,
49 AHBPrescaler::Div512 => 0x0f,
50 }
51 }
52}
53
54/// Clocks configutation
55pub struct Config {
56 mux: ClockSrc,
57 ahb_pre: AHBPrescaler,
58 apb1_pre: APBPrescaler,
59 apb2_pre: APBPrescaler,
60}
61
62impl Default for Config {
63 #[inline]
64 fn default() -> Config {
65 Config {
66 mux: ClockSrc::HSI16,
67 ahb_pre: AHBPrescaler::NotDivided,
68 apb1_pre: APBPrescaler::NotDivided,
69 apb2_pre: APBPrescaler::NotDivided,
70 }
71 }
72}
73
74impl Config {
75 #[inline]
76 pub fn clock_src(mut self, mux: ClockSrc) -> Self {
77 self.mux = mux;
78 self
79 }
80
81 #[inline]
82 pub fn ahb_pre(mut self, pre: AHBPrescaler) -> Self {
83 self.ahb_pre = pre;
84 self
85 }
86
87 #[inline]
88 pub fn apb1_pre(mut self, pre: APBPrescaler) -> Self {
89 self.apb1_pre = pre;
90 self
91 }
92
93 #[inline]
94 pub fn apb2_pre(mut self, pre: APBPrescaler) -> Self {
95 self.apb2_pre = pre;
96 self
97 }
98}
99
100/// RCC peripheral
101pub struct Rcc<'d> {
102 _rb: peripherals::RCC,
103 phantom: PhantomData<&'d mut peripherals::RCC>,
104}
105
106impl<'d> Rcc<'d> {
107 pub fn new(rcc: impl Unborrow<Target = peripherals::RCC> + 'd) -> Self {
108 unborrow!(rcc);
109 Self {
110 _rb: rcc,
111 phantom: PhantomData,
112 }
113 }
114
115 // Safety: RCC init must have been called
116 pub fn clocks(&self) -> &'static Clocks {
117 unsafe { get_freqs() }
118 }
119
120 pub fn enable_debug_wfe(&mut self, _dbg: &mut peripherals::DBGMCU, enable_dma: bool) {
121 // NOTE(unsafe) We have exclusive access to the RCC and DBGMCU
122 unsafe {
123 pac::RCC.ahb1enr().modify(|w| w.set_dma1en(enable_dma));
124
125 pac::DBGMCU.cr().modify(|w| {
126 w.set_dbg_sleep(true);
127 w.set_dbg_standby(true);
128 w.set_dbg_stop(true);
129 });
130 }
131 }
132}
133
134/// Extension trait that freezes the `RCC` peripheral with provided clocks configuration
135pub trait RccExt {
136 fn freeze(self, config: Config) -> Clocks;
137}
138
139impl RccExt for RCC {
140 #[inline]
141 fn freeze(self, cfgr: Config) -> Clocks {
142 let rcc = pac::RCC;
143 let (sys_clk, sw) = match cfgr.mux {
144 ClockSrc::HSI16 => {
145 // Enable HSI16
146 unsafe {
147 rcc.cr().write(|w| w.set_hsion(true));
148 while !rcc.cr().read().hsirdy() {}
149 }
150
151 (HSI_FREQ, 0x01)
152 }
153 ClockSrc::HSE(freq) => {
154 // Enable HSE
155 unsafe {
156 rcc.cr().write(|w| w.set_hseon(true));
157 while !rcc.cr().read().hserdy() {}
158 }
159
160 (freq.0, 0x02)
161 }
162 };
163
164 unsafe {
165 rcc.cfgr().modify(|w| {
166 w.set_sw(sw.into());
167 if cfgr.ahb_pre == AHBPrescaler::NotDivided {
168 w.set_hpre(0);
169 } else {
170 w.set_hpre(cfgr.ahb_pre.into());
171 }
172 w.set_ppre1(cfgr.apb1_pre.into());
173 w.set_ppre2(cfgr.apb2_pre.into());
174 });
175 }
176
177 let ahb_freq: u32 = match cfgr.ahb_pre {
178 AHBPrescaler::NotDivided => sys_clk,
179 pre => {
180 let pre: u8 = pre.into();
181 let pre = 1 << (pre as u32 - 7);
182 sys_clk / pre
183 }
184 };
185
186 let (apb1_freq, apb1_tim_freq) = match cfgr.apb1_pre {
187 APBPrescaler::NotDivided => (ahb_freq, ahb_freq),
188 pre => {
189 let pre: u8 = pre.into();
190 let pre: u8 = 1 << (pre - 3);
191 let freq = ahb_freq / pre as u32;
192 (freq, freq * 2)
193 }
194 };
195
196 let (apb2_freq, apb2_tim_freq) = match cfgr.apb2_pre {
197 APBPrescaler::NotDivided => (ahb_freq, ahb_freq),
198 pre => {
199 let pre: u8 = pre.into();
200 let pre: u8 = 1 << (pre - 3);
201 let freq = ahb_freq / (1 << (pre as u8 - 3));
202 (freq, freq * 2)
203 }
204 };
205
206 Clocks {
207 sys: sys_clk.hz(),
208 ahb1: ahb_freq.hz(),
209 ahb2: ahb_freq.hz(),
210 ahb3: ahb_freq.hz(),
211 apb1: apb1_freq.hz(),
212 apb2: apb2_freq.hz(),
213 apb1_tim: apb1_tim_freq.hz(),
214 apb2_tim: apb2_tim_freq.hz(),
215 }
216 }
217}
218
219pub unsafe fn init(config: Config) {
220 let r = <peripherals::RCC as embassy::util::Steal>::steal();
221 let rcc = pac::RCC;
222 rcc.ahb2enr().write(|w| {
223 w.set_gpioaen(true);
224 w.set_gpioben(true);
225 w.set_gpiocen(true);
226 w.set_gpiohen(true);
227 });
228 let clocks = r.freeze(config);
229 set_freqs(clocks);
230}
diff --git a/examples/stm32l0/src/bin/blinky.rs b/examples/stm32l0/src/bin/blinky.rs
index e7433c26f..ab0a2bdb2 100644
--- a/examples/stm32l0/src/bin/blinky.rs
+++ b/examples/stm32l0/src/bin/blinky.rs
@@ -8,7 +8,10 @@
8 8
9#[path = "../example_common.rs"] 9#[path = "../example_common.rs"]
10mod example_common; 10mod example_common;
11use embassy_stm32::{rcc::*, gpio::{Level, Output}}; 11use embassy_stm32::{
12 gpio::{Level, Output},
13 rcc::*,
14};
12use embedded_hal::digital::v2::OutputPin; 15use embedded_hal::digital::v2::OutputPin;
13use example_common::*; 16use example_common::*;
14 17
diff --git a/examples/stm32l0/src/bin/button.rs b/examples/stm32l0/src/bin/button.rs
index 1a2e20b14..04c48112a 100644
--- a/examples/stm32l0/src/bin/button.rs
+++ b/examples/stm32l0/src/bin/button.rs
@@ -8,13 +8,15 @@
8 8
9#[path = "../example_common.rs"] 9#[path = "../example_common.rs"]
10mod example_common; 10mod example_common;
11use embassy_stm32::{rcc::*, gpio::{Input, Level, Output, Pull}}; 11use embassy_stm32::{
12 gpio::{Input, Level, Output, Pull},
13 rcc::*,
14};
12use embedded_hal::digital::v2::{InputPin, OutputPin}; 15use embedded_hal::digital::v2::{InputPin, OutputPin};
13use example_common::*; 16use example_common::*;
14 17
15use cortex_m_rt::entry; 18use cortex_m_rt::entry;
16 19
17
18#[entry] 20#[entry]
19fn main() -> ! { 21fn main() -> ! {
20 info!("Hello World!"); 22 info!("Hello World!");
diff --git a/stm32-data b/stm32-data
Subproject 67b2029a7f203e52f6e1f68c71c7d0aacfef579 Subproject 94a0969afddbde239afeb0d678b8fac50de5d3d
diff --git a/stm32-metapac/Cargo.toml b/stm32-metapac/Cargo.toml
index 4a434b17e..bed772c81 100644
--- a/stm32-metapac/Cargo.toml
+++ b/stm32-metapac/Cargo.toml
@@ -778,23 +778,40 @@ stm32h743xg = []
778stm32h743xi = [] 778stm32h743xi = []
779stm32h743zg = [] 779stm32h743zg = []
780stm32h743zi = [] 780stm32h743zi = []
781stm32h745bg = [] 781stm32h745bg_cm7 = []
782stm32h745bi = [] 782stm32h745bg_cm4 = []
783stm32h745ig = [] 783stm32h745bi_cm7 = []
784stm32h745ii = [] 784stm32h745bi_cm4 = []
785stm32h745xg = [] 785stm32h745ig_cm7 = []
786stm32h745xi = [] 786stm32h745ig_cm4 = []
787stm32h745zg = [] 787stm32h745ii_cm7 = []
788stm32h745zi = [] 788stm32h745ii_cm4 = []
789stm32h747ag = [] 789stm32h745xg_cm7 = []
790stm32h747ai = [] 790stm32h745xg_cm4 = []
791stm32h747bg = [] 791stm32h745xi_cm7 = []
792stm32h747bi = [] 792stm32h745xi_cm4 = []
793stm32h747ig = [] 793stm32h745zg_cm7 = []
794stm32h747ii = [] 794stm32h745zg_cm4 = []
795stm32h747xg = [] 795stm32h745zi_cm7 = []
796stm32h747xi = [] 796stm32h745zi_cm4 = []
797stm32h747zi = [] 797stm32h747ag_cm7 = []
798stm32h747ag_cm4 = []
799stm32h747ai_cm7 = []
800stm32h747ai_cm4 = []
801stm32h747bg_cm7 = []
802stm32h747bg_cm4 = []
803stm32h747bi_cm7 = []
804stm32h747bi_cm4 = []
805stm32h747ig_cm7 = []
806stm32h747ig_cm4 = []
807stm32h747ii_cm7 = []
808stm32h747ii_cm4 = []
809stm32h747xg_cm7 = []
810stm32h747xg_cm4 = []
811stm32h747xi_cm7 = []
812stm32h747xi_cm4 = []
813stm32h747zi_cm7 = []
814stm32h747zi_cm4 = []
798stm32h750ib = [] 815stm32h750ib = []
799stm32h750vb = [] 816stm32h750vb = []
800stm32h750xb = [] 817stm32h750xb = []
@@ -805,15 +822,24 @@ stm32h753ii = []
805stm32h753vi = [] 822stm32h753vi = []
806stm32h753xi = [] 823stm32h753xi = []
807stm32h753zi = [] 824stm32h753zi = []
808stm32h755bi = [] 825stm32h755bi_cm7 = []
809stm32h755ii = [] 826stm32h755bi_cm4 = []
810stm32h755xi = [] 827stm32h755ii_cm7 = []
811stm32h755zi = [] 828stm32h755ii_cm4 = []
812stm32h757ai = [] 829stm32h755xi_cm7 = []
813stm32h757bi = [] 830stm32h755xi_cm4 = []
814stm32h757ii = [] 831stm32h755zi_cm7 = []
815stm32h757xi = [] 832stm32h755zi_cm4 = []
816stm32h757zi = [] 833stm32h757ai_cm7 = []
834stm32h757ai_cm4 = []
835stm32h757bi_cm7 = []
836stm32h757bi_cm4 = []
837stm32h757ii_cm7 = []
838stm32h757ii_cm4 = []
839stm32h757xi_cm7 = []
840stm32h757xi_cm4 = []
841stm32h757zi_cm7 = []
842stm32h757zi_cm4 = []
817stm32h7a3ag = [] 843stm32h7a3ag = []
818stm32h7a3ai = [] 844stm32h7a3ai = []
819stm32h7a3ig = [] 845stm32h7a3ig = []
@@ -1204,11 +1230,16 @@ stm32wb55ve = []
1204stm32wb55vg = [] 1230stm32wb55vg = []
1205stm32wb55vy = [] 1231stm32wb55vy = []
1206stm32wb5mmg = [] 1232stm32wb5mmg = []
1207stm32wl54cc = [] 1233stm32wl54cc_cm4 = []
1208stm32wl54jc = [] 1234stm32wl54cc_cm0p = []
1209stm32wl55cc = [] 1235stm32wl54jc_cm4 = []
1210stm32wl55jc = [] 1236stm32wl54jc_cm0p = []
1211stm32wl55uc = [] 1237stm32wl55cc_cm4 = []
1238stm32wl55cc_cm0p = []
1239stm32wl55jc_cm4 = []
1240stm32wl55jc_cm0p = []
1241stm32wl55uc_cm4 = []
1242stm32wl55uc_cm0p = []
1212stm32wle4c8 = [] 1243stm32wle4c8 = []
1213stm32wle4cb = [] 1244stm32wle4cb = []
1214stm32wle4cc = [] 1245stm32wle4cc = []
diff --git a/stm32-metapac/gen/src/lib.rs b/stm32-metapac/gen/src/lib.rs
index 5a021569c..a5c061009 100644
--- a/stm32-metapac/gen/src/lib.rs
+++ b/stm32-metapac/gen/src/lib.rs
@@ -16,11 +16,16 @@ pub struct Chip {
16 pub name: String, 16 pub name: String,
17 pub family: String, 17 pub family: String,
18 pub line: String, 18 pub line: String,
19 pub core: String, 19 pub cores: Vec<Core>,
20 pub flash: u32, 20 pub flash: u32,
21 pub ram: u32, 21 pub ram: u32,
22 pub gpio_af: String, 22 pub gpio_af: String,
23 pub packages: Vec<Package>, 23 pub packages: Vec<Package>,
24}
25
26#[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
27pub struct Core {
28 pub name: String,
24 pub peripherals: HashMap<String, Peripheral>, 29 pub peripherals: HashMap<String, Peripheral>,
25 pub interrupts: HashMap<String, u32>, 30 pub interrupts: HashMap<String, u32>,
26} 31}
@@ -153,13 +158,41 @@ pub fn gen(options: Options) {
153 println!("cwd: {:?}", env::current_dir()); 158 println!("cwd: {:?}", env::current_dir());
154 159
155 let mut all_peripheral_versions: HashSet<(String, String)> = HashSet::new(); 160 let mut all_peripheral_versions: HashSet<(String, String)> = HashSet::new();
161 let mut chip_cores: HashMap<String, Option<String>> = HashMap::new();
156 162
157 for chip_name in &options.chips { 163 for chip_name in &options.chips {
164 let mut s = chip_name.split('_');
165 let chip_name: &str = s.next().unwrap();
166 let core_name: Option<&str> = s.next();
167
168 chip_cores.insert(
169 chip_name.to_string(),
170 core_name.map(|s| s.to_ascii_lowercase().to_string()),
171 );
172
158 let chip_path = data_dir.join("chips").join(&format!("{}.yaml", chip_name)); 173 let chip_path = data_dir.join("chips").join(&format!("{}.yaml", chip_name));
159 println!("chip_path: {:?}", chip_path); 174 println!("chip_path: {:?}", chip_path);
160 let chip = fs::read(chip_path).unwrap(); 175 let chip = fs::read(chip_path).unwrap();
161 let chip: Chip = serde_yaml::from_slice(&chip).unwrap(); 176 let chip: Chip = serde_yaml::from_slice(&chip).unwrap();
162 177
178 println!("looking for core {:?}", core_name);
179 let core: Option<&Core> = if let Some(core_name) = core_name {
180 let core_name = core_name.to_ascii_lowercase();
181 let mut c = None;
182 for core in chip.cores.iter() {
183 if core.name == core_name {
184 c = Some(core);
185 break;
186 }
187 }
188 c
189 } else {
190 Some(&chip.cores[0])
191 };
192
193 let core = core.unwrap();
194 let core_name = &core.name;
195
163 let mut ir = ir::IR::new(); 196 let mut ir = ir::IR::new();
164 197
165 let mut dev = ir::Device { 198 let mut dev = ir::Device {
@@ -168,7 +201,7 @@ pub fn gen(options: Options) {
168 }; 201 };
169 202
170 // Load RCC register for chip 203 // Load RCC register for chip
171 let rcc = chip.peripherals.iter().find_map(|(name, p)| { 204 let rcc = core.peripherals.iter().find_map(|(name, p)| {
172 if name == "RCC" { 205 if name == "RCC" {
173 p.block.as_ref().map(|block| { 206 p.block.as_ref().map(|block| {
174 let bi = BlockInfo::parse(block); 207 let bi = BlockInfo::parse(block);
@@ -189,17 +222,17 @@ pub fn gen(options: Options) {
189 let mut peripheral_pins_table: Vec<Vec<String>> = Vec::new(); 222 let mut peripheral_pins_table: Vec<Vec<String>> = Vec::new();
190 let mut peripheral_rcc_table: Vec<Vec<String>> = Vec::new(); 223 let mut peripheral_rcc_table: Vec<Vec<String>> = Vec::new();
191 224
192 let dma_base = chip 225 let dma_base = core
193 .peripherals 226 .peripherals
194 .get(&"DMA".to_string()) 227 .get(&"DMA".to_string())
195 .unwrap_or_else(|| chip.peripherals.get(&"DMA1".to_string()).unwrap()) 228 .unwrap_or_else(|| core.peripherals.get(&"DMA1".to_string()).unwrap())
196 .address; 229 .address;
197 let dma_stride = 0x400; 230 let dma_stride = 0x400;
198 231
199 let gpio_base = chip.peripherals.get(&"GPIOA".to_string()).unwrap().address; 232 let gpio_base = core.peripherals.get(&"GPIOA".to_string()).unwrap().address;
200 let gpio_stride = 0x400; 233 let gpio_stride = 0x400;
201 234
202 for (name, p) in &chip.peripherals { 235 for (name, p) in &core.peripherals {
203 let mut ir_peri = ir::Peripheral { 236 let mut ir_peri = ir::Peripheral {
204 name: name.clone(), 237 name: name.clone(),
205 array: None, 238 array: None,
@@ -338,7 +371,7 @@ pub fn gen(options: Options) {
338 dev.peripherals.push(ir_peri); 371 dev.peripherals.push(ir_peri);
339 } 372 }
340 373
341 for (name, &num) in &chip.interrupts { 374 for (name, &num) in &core.interrupts {
342 dev.interrupts.push(ir::Interrupt { 375 dev.interrupts.push(ir::Interrupt {
343 name: name.clone(), 376 name: name.clone(),
344 description: None, 377 description: None,
@@ -386,9 +419,17 @@ pub fn gen(options: Options) {
386 transform::sort::Sort {}.run(&mut ir).unwrap(); 419 transform::sort::Sort {}.run(&mut ir).unwrap();
387 transform::Sanitize {}.run(&mut ir).unwrap(); 420 transform::Sanitize {}.run(&mut ir).unwrap();
388 421
389 let chip_dir = out_dir 422 let chip_dir = if chip.cores.len() > 1 {
390 .join("src/chips") 423 out_dir.join("src/chips").join(format!(
391 .join(chip_name.to_ascii_lowercase()); 424 "{}_{}",
425 chip_name.to_ascii_lowercase(),
426 core_name.to_ascii_lowercase()
427 ))
428 } else {
429 out_dir
430 .join("src/chips")
431 .join(chip_name.to_ascii_lowercase())
432 };
392 fs::create_dir_all(&chip_dir).unwrap(); 433 fs::create_dir_all(&chip_dir).unwrap();
393 434
394 let items = generate::render(&ir, &generate_opts).unwrap(); 435 let items = generate::render(&ir, &generate_opts).unwrap();
@@ -403,7 +444,7 @@ pub fn gen(options: Options) {
403 444
404 let mut device_x = String::new(); 445 let mut device_x = String::new();
405 446
406 for (name, _) in &chip.interrupts { 447 for (name, _) in &core.interrupts {
407 write!( 448 write!(
408 &mut device_x, 449 &mut device_x,
409 "PROVIDE({} = DefaultHandler);\n", 450 "PROVIDE({} = DefaultHandler);\n",
@@ -462,14 +503,24 @@ pub fn gen(options: Options) {
462 let librs = include_bytes!("assets/lib_inner.rs"); 503 let librs = include_bytes!("assets/lib_inner.rs");
463 let i = bytes_find(librs, PATHS_MARKER).unwrap(); 504 let i = bytes_find(librs, PATHS_MARKER).unwrap();
464 let mut paths = String::new(); 505 let mut paths = String::new();
465 for chip_name in &options.chips { 506
466 let x = chip_name.to_ascii_lowercase(); 507 for (chip, cores) in chip_cores.iter() {
467 write!( 508 let x = chip.to_ascii_lowercase();
468 &mut paths, 509 if let Some(c) = cores {
469 "#[cfg_attr(feature=\"{}\", path = \"chips/{}/pac.rs\")]", 510 write!(
470 x, x 511 &mut paths,
471 ) 512 "#[cfg_attr(feature=\"{}_{}\", path = \"chips/{}_{}/pac.rs\")]",
472 .unwrap(); 513 x, c, x, c
514 )
515 .unwrap();
516 } else {
517 write!(
518 &mut paths,
519 "#[cfg_attr(feature=\"{}\", path = \"chips/{}/pac.rs\")]",
520 x, x
521 )
522 .unwrap();
523 }
473 } 524 }
474 let mut contents: Vec<u8> = Vec::new(); 525 let mut contents: Vec<u8> = Vec::new();
475 contents.extend(&librs[..i]); 526 contents.extend(&librs[..i]);
diff --git a/stm32-metapac/gen_features.py b/stm32-metapac/gen_features.py
index ee92bd763..29cbd85a0 100644
--- a/stm32-metapac/gen_features.py
+++ b/stm32-metapac/gen_features.py
@@ -8,6 +8,11 @@ import toml
8from collections import OrderedDict 8from collections import OrderedDict
9from glob import glob 9from glob import glob
10 10
11try:
12 from yaml import CSafeLoader as SafeLoader
13except ImportError:
14 from yaml import SafeLoader
15
11abspath = os.path.abspath(__file__) 16abspath = os.path.abspath(__file__)
12dname = os.path.dirname(abspath) 17dname = os.path.dirname(abspath)
13os.chdir(dname) 18os.chdir(dname)
@@ -19,8 +24,13 @@ features = {}
19for f in sorted(glob('../stm32-data/data/chips/*.yaml')): 24for f in sorted(glob('../stm32-data/data/chips/*.yaml')):
20 # Use the filename to get the chip name. Ultra fast, we don't have to read YAML! 25 # Use the filename to get the chip name. Ultra fast, we don't have to read YAML!
21 name = os.path.splitext(os.path.basename(f))[0].lower() 26 name = os.path.splitext(os.path.basename(f))[0].lower()
22 features[name] = [] 27 with open(f, 'r') as f:
23 28 chip = yaml.load(f, Loader=SafeLoader)
29 if len(chip['cores']) > 1:
30 for core in chip['cores']:
31 features[name + "_" + core['name']] = []
32 else:
33 features[name] = []
24 34
25# ========= Update Cargo features 35# ========= Update Cargo features
26 36