aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2021-05-25 15:12:45 +0200
committerGitHub <[email protected]>2021-05-25 15:12:45 +0200
commita126e17fb2d5544f1506aec860cc1b218008e9fd (patch)
treeb26a8dabb73e99bfa09943810c61c405c187a354
parent4b98361967d25d258257d27d12624a296d5f70c4 (diff)
parentef254647f7bae68ae2f754071635a743b678fd61 (diff)
Merge pull request #204 from lulf/enable-stm32-macro
Enable stm32 macro
-rw-r--r--embassy-macros/Cargo.toml1
-rw-r--r--embassy-macros/src/chip/stm32.rs26
-rw-r--r--embassy-macros/src/lib.rs6
-rw-r--r--embassy-stm32/Cargo.toml4
-rw-r--r--embassy-stm32/src/lib.rs9
-rw-r--r--embassy-stm32/src/rcc/h7/mod.rs4
-rw-r--r--embassy-stm32/src/rcc/l0/mod.rs20
-rw-r--r--embassy-stm32/src/rcc/mod.rs17
8 files changed, 78 insertions, 9 deletions
diff --git a/embassy-macros/Cargo.toml b/embassy-macros/Cargo.toml
index 265a0c083..06dc6f072 100644
--- a/embassy-macros/Cargo.toml
+++ b/embassy-macros/Cargo.toml
@@ -15,5 +15,6 @@ proc-macro = true
15 15
16[features] 16[features]
17nrf = [] 17nrf = []
18stm32 = []
18rp = [] 19rp = []
19std = [] 20std = []
diff --git a/embassy-macros/src/chip/stm32.rs b/embassy-macros/src/chip/stm32.rs
new file mode 100644
index 000000000..a1ceadd55
--- /dev/null
+++ b/embassy-macros/src/chip/stm32.rs
@@ -0,0 +1,26 @@
1use crate::path::ModulePrefix;
2use proc_macro2::TokenStream;
3use quote::quote;
4
5pub fn generate(embassy_prefix: &ModulePrefix, config: syn::Expr) -> TokenStream {
6 let embassy_path = embassy_prefix.append("embassy").path();
7 let embassy_stm32_path = embassy_prefix.append("embassy_stm32").path();
8
9 quote!(
10 use #embassy_stm32_path::{clock::Clock};
11
12 let p = #embassy_stm32_path::init(#config);
13
14 /*
15 let mut rtc = #embass::RTC::new(unsafe { <peripherals::TIM2 as #embassy_path::util::Steal>::steal() }, interrupt::take!(TIM2));
16 let rtc = unsafe { make_static(&mut rtc) };
17 rtc.start();
18 let mut alarm = rtc.alarm0();
19
20 unsafe { #embassy_path::time::set_clock(rtc) };
21
22 let alarm = unsafe { make_static(&mut alarm) };
23 executor.set_alarm(alarm);
24 */
25 )
26}
diff --git a/embassy-macros/src/lib.rs b/embassy-macros/src/lib.rs
index d23526aa2..3dc295fc1 100644
--- a/embassy-macros/src/lib.rs
+++ b/embassy-macros/src/lib.rs
@@ -256,6 +256,10 @@ pub fn interrupt_take(item: TokenStream) -> TokenStream {
256 result.into() 256 result.into()
257} 257}
258 258
259#[cfg(feature = "stm32")]
260#[path = "chip/stm32.rs"]
261mod chip;
262
259#[cfg(feature = "nrf")] 263#[cfg(feature = "nrf")]
260#[path = "chip/nrf.rs"] 264#[path = "chip/nrf.rs"]
261mod chip; 265mod chip;
@@ -273,7 +277,7 @@ struct MainArgs {
273 config: Option<syn::LitStr>, 277 config: Option<syn::LitStr>,
274} 278}
275 279
276#[cfg(any(feature = "nrf", feature = "rp"))] 280#[cfg(any(feature = "nrf", feature = "rp", feature = "stm32"))]
277#[proc_macro_attribute] 281#[proc_macro_attribute]
278pub fn main(args: TokenStream, item: TokenStream) -> TokenStream { 282pub fn main(args: TokenStream, item: TokenStream) -> TokenStream {
279 let macro_args = syn::parse_macro_input!(args as syn::AttributeArgs); 283 let macro_args = syn::parse_macro_input!(args as syn::AttributeArgs);
diff --git a/embassy-stm32/Cargo.toml b/embassy-stm32/Cargo.toml
index 43d5250e5..6d234f65f 100644
--- a/embassy-stm32/Cargo.toml
+++ b/embassy-stm32/Cargo.toml
@@ -6,7 +6,7 @@ edition = "2018"
6 6
7[dependencies] 7[dependencies]
8embassy = { version = "0.1.0", path = "../embassy" } 8embassy = { version = "0.1.0", path = "../embassy" }
9embassy-macros = { version = "0.1.0", path = "../embassy-macros" } 9embassy-macros = { version = "0.1.0", path = "../embassy-macros", features = ["stm32"] }
10embassy-extras = {version = "0.1.0", path = "../embassy-extras" } 10embassy-extras = {version = "0.1.0", path = "../embassy-extras" }
11embassy-traits = {version = "0.1.0", path = "../embassy-traits" } 11embassy-traits = {version = "0.1.0", path = "../embassy-traits" }
12 12
@@ -23,6 +23,8 @@ critical-section = "0.2.1"
23bare-metal = "1.0.0" 23bare-metal = "1.0.0"
24atomic-polyfill = "0.1.2" 24atomic-polyfill = "0.1.2"
25 25
26cfg-if = "1.0.0"
27
26[build-dependencies] 28[build-dependencies]
27regex = "1.4.6" 29regex = "1.4.6"
28 30
diff --git a/embassy-stm32/src/lib.rs b/embassy-stm32/src/lib.rs
index 0ab998a87..250281f88 100644
--- a/embassy-stm32/src/lib.rs
+++ b/embassy-stm32/src/lib.rs
@@ -42,22 +42,25 @@ pub(crate) use pac::regs::generic;
42 42
43#[non_exhaustive] 43#[non_exhaustive]
44pub struct Config { 44pub struct Config {
45 _private: (), 45 rcc: rcc::Config,
46} 46}
47 47
48impl Default for Config { 48impl Default for Config {
49 fn default() -> Self { 49 fn default() -> Self {
50 Self { _private: () } 50 Self {
51 rcc: Default::default(),
52 }
51 } 53 }
52} 54}
53 55
54/// Initialize embassy. 56/// Initialize embassy.
55pub fn init(_config: Config) -> Peripherals { 57pub fn init(config: Config) -> Peripherals {
56 let p = Peripherals::take(); 58 let p = Peripherals::take();
57 59
58 unsafe { 60 unsafe {
59 dma::init(); 61 dma::init();
60 pac::init_exti(); 62 pac::init_exti();
63 rcc::init(config.rcc);
61 } 64 }
62 65
63 p 66 p
diff --git a/embassy-stm32/src/rcc/h7/mod.rs b/embassy-stm32/src/rcc/h7/mod.rs
index d8d231bae..85e1cd00f 100644
--- a/embassy-stm32/src/rcc/h7/mod.rs
+++ b/embassy-stm32/src/rcc/h7/mod.rs
@@ -527,3 +527,7 @@ impl<'d> Rcc<'d> {
527 } 527 }
528 } 528 }
529} 529}
530
531pub unsafe fn init(config: Config) {
532 // TODO
533}
diff --git a/embassy-stm32/src/rcc/l0/mod.rs b/embassy-stm32/src/rcc/l0/mod.rs
new file mode 100644
index 000000000..000aaa9e0
--- /dev/null
+++ b/embassy-stm32/src/rcc/l0/mod.rs
@@ -0,0 +1,20 @@
1use crate::pac;
2use embassy::util::Steal;
3use pac::rcc::{self, vals};
4
5#[derive(Default)]
6pub struct Config {}
7
8pub unsafe fn init(config: Config) {
9 let rcc = pac::RCC;
10
11 let enabled = vals::Iophen::ENABLED;
12 rcc.iopenr().write(|w| {
13 w.set_iopaen(enabled);
14 w.set_iopben(enabled);
15 w.set_iopcen(enabled);
16 w.set_iopden(enabled);
17 w.set_iopeen(enabled);
18 w.set_iophen(enabled);
19 });
20}
diff --git a/embassy-stm32/src/rcc/mod.rs b/embassy-stm32/src/rcc/mod.rs
index 0bf62ef7c..59938e7bf 100644
--- a/embassy-stm32/src/rcc/mod.rs
+++ b/embassy-stm32/src/rcc/mod.rs
@@ -1,4 +1,13 @@
1#[cfg(feature = "_stm32h7")] 1cfg_if::cfg_if! {
2mod h7; 2 if #[cfg(feature = "_stm32h7")] {
3#[cfg(feature = "_stm32h7")] 3 mod h7;
4pub use h7::*; 4 pub use h7::*;
5 } else if #[cfg(feature = "_stm32l0")] {
6 mod l0;
7 pub use l0::*;
8 } else {
9 #[derive(Default)]
10 pub struct Config {}
11 pub fn init(_config: Config) {}
12 }
13}