aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32/src
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2022-02-09 15:27:35 +0000
committerGitHub <[email protected]>2022-02-09 15:27:35 +0000
commit1d265b73b2f46baf60a481c8b8036e50c2b6583f (patch)
tree862f3b9d41b38048d555e40e6e6425da29b0cf1d /embassy-stm32/src
parent3d6b8bd9832d5a29cab4aa21434663e6ea6f4488 (diff)
parent8160af6af99573d3ef66aede8c4b0aac033b0ff3 (diff)
Merge #601
601: [part 1/n] Change macrotables to build.rs codegen r=lulf a=Dirbaio This PR replaces the "macrotables" (the macros like `stm32_data::peripherals!`) with a `const METADATA`. Macrotables had some problems: - Hard to debug - Somewhat footgunny (typo the "pattern" and then nothing matches and the macro now expands to nothing, silently!) - Limited power - Can't count, so we had to add a [special macrotable for that](https://github.com/embassy-rs/embassy/blob/f50f3f0a73a41275e6ea21d8661081acad381e05/embassy-stm32/src/dma/bdma.rs#L26). - Can't remove duplicates, so we had to fallback to [Rust code in build.rs](https://github.com/embassy-rs/embassy/blob/f50f3f0a73a41275e6ea21d8661081acad381e05/embassy-stm32/build.rs#L105-L145) - Can't include the results as a listto another macro, so again [build.rs](https://github.com/embassy-rs/embassy/blob/master/embassy-stm32/build.rs#L100-L101). They work fine for the 95% of cases, but for the remaining 5% we need Rust code in build.rs. So we might as well do everything with Rust code, so everything is consistent. The new approach generates a `const METADATA: Metadata = Metadata { ... }` with [these structs](https://github.com/embassy-rs/embassy/blob/unmacrotablize/stm32-metapac-gen/src/assets/metadata.rs) in `stm32-metapac`. `build.rs` can then read that and generate whatever code. Co-authored-by: Dario Nieuwenhuis <[email protected]>
Diffstat (limited to 'embassy-stm32/src')
-rw-r--r--embassy-stm32/src/dma/bdma.rs7
-rw-r--r--embassy-stm32/src/dma/dma.rs7
-rw-r--r--embassy-stm32/src/dma/dmamux.rs8
-rw-r--r--embassy-stm32/src/gpio.rs8
-rw-r--r--embassy-stm32/src/interrupt.rs9
-rw-r--r--embassy-stm32/src/lib.rs2
-rw-r--r--embassy-stm32/src/rcc/mod.rs64
7 files changed, 5 insertions, 100 deletions
diff --git a/embassy-stm32/src/dma/bdma.rs b/embassy-stm32/src/dma/bdma.rs
index ebb0467dc..a37de2d63 100644
--- a/embassy-stm32/src/dma/bdma.rs
+++ b/embassy-stm32/src/dma/bdma.rs
@@ -9,7 +9,6 @@ use embassy::waitqueue::AtomicWaker;
9use crate::dma::Request; 9use crate::dma::Request;
10use crate::pac; 10use crate::pac;
11use crate::pac::bdma::vals; 11use crate::pac::bdma::vals;
12use crate::rcc::sealed::RccPeripheral;
13 12
14use super::{Word, WordSize}; 13use super::{Word, WordSize};
15 14
@@ -77,11 +76,7 @@ pub(crate) unsafe fn init() {
77 crate::interrupt::$irq::steal().enable(); 76 crate::interrupt::$irq::steal().enable();
78 }; 77 };
79 } 78 }
80 pac::peripherals! { 79 crate::generated::init_bdma();
81 (bdma, $peri:ident) => {
82 crate::peripherals::$peri::enable();
83 };
84 }
85} 80}
86 81
87pac::dma_channels! { 82pac::dma_channels! {
diff --git a/embassy-stm32/src/dma/dma.rs b/embassy-stm32/src/dma/dma.rs
index 21623b90c..c885452b0 100644
--- a/embassy-stm32/src/dma/dma.rs
+++ b/embassy-stm32/src/dma/dma.rs
@@ -7,7 +7,6 @@ use embassy::waitqueue::AtomicWaker;
7use crate::interrupt; 7use crate::interrupt;
8use crate::pac; 8use crate::pac;
9use crate::pac::dma::{regs, vals}; 9use crate::pac::dma::{regs, vals};
10use crate::rcc::sealed::RccPeripheral;
11 10
12use super::{Request, Word, WordSize}; 11use super::{Request, Word, WordSize};
13 12
@@ -74,11 +73,7 @@ pub(crate) unsafe fn init() {
74 interrupt::$irq::steal().enable(); 73 interrupt::$irq::steal().enable();
75 }; 74 };
76 } 75 }
77 pac::peripherals! { 76 crate::generated::init_dma();
78 (dma, $peri:ident) => {
79 crate::peripherals::$peri::enable();
80 };
81 }
82} 77}
83 78
84pac::dma_channels! { 79pac::dma_channels! {
diff --git a/embassy-stm32/src/dma/dmamux.rs b/embassy-stm32/src/dma/dmamux.rs
index 83dcff4e8..fd076581b 100644
--- a/embassy-stm32/src/dma/dmamux.rs
+++ b/embassy-stm32/src/dma/dmamux.rs
@@ -49,11 +49,5 @@ pac::dma_channels! {
49 49
50/// safety: must be called only once 50/// safety: must be called only once
51pub(crate) unsafe fn init() { 51pub(crate) unsafe fn init() {
52 crate::pac::peripheral_rcc! { 52 crate::generated::init_dmamux();
53 ($name:ident, dmamux, DMAMUX, $clock:ident, ($reg:ident, $field:ident, $set_field:ident), $rst:tt) => {
54 crate::pac::RCC.$reg().modify(|reg| {
55 reg.$set_field(true);
56 });
57 };
58 }
59} 53}
diff --git a/embassy-stm32/src/gpio.rs b/embassy-stm32/src/gpio.rs
index d4606716c..f154a66c4 100644
--- a/embassy-stm32/src/gpio.rs
+++ b/embassy-stm32/src/gpio.rs
@@ -608,13 +608,7 @@ crate::pac::pins!(
608); 608);
609 609
610pub(crate) unsafe fn init() { 610pub(crate) unsafe fn init() {
611 crate::pac::peripheral_rcc! { 611 crate::generated::init_gpio();
612 ($name:ident, gpio, GPIO, $clock:ident, ($reg:ident, $field:ident, $set_field:ident), $rst:tt) => {
613 crate::pac::RCC.$reg().modify(|reg| {
614 reg.$set_field(true);
615 });
616 };
617 }
618} 612}
619 613
620mod eh02 { 614mod eh02 {
diff --git a/embassy-stm32/src/interrupt.rs b/embassy-stm32/src/interrupt.rs
index 27e441644..c757b790c 100644
--- a/embassy-stm32/src/interrupt.rs
+++ b/embassy-stm32/src/interrupt.rs
@@ -3,11 +3,4 @@ pub use critical_section::CriticalSection;
3pub use embassy::interrupt::{take, Interrupt}; 3pub use embassy::interrupt::{take, Interrupt};
4pub use embassy_hal_common::interrupt::Priority4 as Priority; 4pub use embassy_hal_common::interrupt::Priority4 as Priority;
5 5
6use crate::pac::Interrupt as InterruptEnum; 6pub use crate::generated::interrupt::*;
7use embassy::interrupt::declare;
8
9crate::pac::interrupts!(
10 ($name:ident) => {
11 declare!($name);
12 };
13);
diff --git a/embassy-stm32/src/lib.rs b/embassy-stm32/src/lib.rs
index 4bc044047..a910f6950 100644
--- a/embassy-stm32/src/lib.rs
+++ b/embassy-stm32/src/lib.rs
@@ -65,8 +65,6 @@ mod generated {
65 #![allow(unused_imports)] 65 #![allow(unused_imports)]
66 #![allow(non_snake_case)] 66 #![allow(non_snake_case)]
67 67
68 use crate::interrupt;
69
70 include!(concat!(env!("OUT_DIR"), "/generated.rs")); 68 include!(concat!(env!("OUT_DIR"), "/generated.rs"));
71} 69}
72pub use embassy_macros::interrupt; 70pub use embassy_macros::interrupt;
diff --git a/embassy-stm32/src/rcc/mod.rs b/embassy-stm32/src/rcc/mod.rs
index 541d9c148..3aab01afd 100644
--- a/embassy-stm32/src/rcc/mod.rs
+++ b/embassy-stm32/src/rcc/mod.rs
@@ -1,6 +1,5 @@
1#![macro_use] 1#![macro_use]
2 2
3use crate::peripherals;
4use crate::time::Hertz; 3use crate::time::Hertz;
5use core::mem::MaybeUninit; 4use core::mem::MaybeUninit;
6 5
@@ -104,66 +103,3 @@ pub(crate) mod sealed {
104} 103}
105 104
106pub trait RccPeripheral: sealed::RccPeripheral + 'static {} 105pub trait RccPeripheral: sealed::RccPeripheral + 'static {}
107
108crate::pac::peripheral_rcc!(
109 ($inst:ident, gpio, GPIO, $clk:ident, $en:tt, $rst:tt) => {};
110 ($inst:ident, $module:ident, $block:ident, $clk:ident, ($en_reg:ident, $en_field:ident, $en_set_field:ident), ($rst_reg:ident, $rst_field:ident, $rst_set_field:ident)) => {
111 impl sealed::RccPeripheral for peripherals::$inst {
112 fn frequency() -> crate::time::Hertz {
113 critical_section::with(|_| {
114 unsafe { get_freqs().$clk }
115 })
116 }
117 fn enable() {
118 critical_section::with(|_| {
119 unsafe {
120 crate::pac::RCC.$en_reg().modify(|w| w.$en_set_field(true));
121 }
122 })
123 }
124 fn disable() {
125 critical_section::with(|_| {
126 unsafe {
127 crate::pac::RCC.$en_reg().modify(|w| w.$en_set_field(false));
128 }
129 })
130 }
131 fn reset() {
132 critical_section::with(|_| {
133 unsafe {
134 crate::pac::RCC.$rst_reg().modify(|w| w.$rst_set_field(true));
135 crate::pac::RCC.$rst_reg().modify(|w| w.$rst_set_field(false));
136 }
137 })
138 }
139 }
140
141 impl RccPeripheral for peripherals::$inst {}
142 };
143 ($inst:ident, $module:ident, $block:ident, $clk:ident, ($en_reg:ident, $en_field:ident, $en_set_field:ident), _) => {
144 impl sealed::RccPeripheral for peripherals::$inst {
145 fn frequency() -> crate::time::Hertz {
146 critical_section::with(|_| {
147 unsafe { get_freqs().$clk }
148 })
149 }
150 fn enable() {
151 critical_section::with(|_| {
152 unsafe {
153 crate::pac::RCC.$en_reg().modify(|w| w.$en_set_field(true));
154 }
155 })
156 }
157 fn disable() {
158 critical_section::with(|_| {
159 unsafe {
160 crate::pac::RCC.$en_reg().modify(|w| w.$en_set_field(false));
161 }
162 })
163 }
164 fn reset() {}
165 }
166
167 impl RccPeripheral for peripherals::$inst {}
168 };
169);