aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2021-04-06 01:31:29 +0200
committerDario Nieuwenhuis <[email protected]>2021-04-20 02:30:13 +0200
commitaa65d5ccaf0b144063d41d650e4b46c24172166c (patch)
tree6efa6bbd664261864f8f7768bbb437bb8fb1be5b
parent97ca54fa6639371e5a871bd1e87562c126d92a16 (diff)
it's alive
-rw-r--r--embassy-stm32-examples/Cargo.toml38
-rw-r--r--embassy-stm32-examples/src/bin/blinky.rs52
-rw-r--r--embassy-stm32-examples/src/bin/can.rs_ (renamed from embassy-stm32-examples/src/bin/can.rs)0
-rw-r--r--embassy-stm32-examples/src/bin/exti.rs_ (renamed from embassy-stm32-examples/src/bin/exti.rs)0
-rw-r--r--embassy-stm32-examples/src/bin/hello.rs42
-rw-r--r--embassy-stm32-examples/src/bin/rtc_async.rs_ (renamed from embassy-stm32-examples/src/bin/rtc_async.rs)0
-rw-r--r--embassy-stm32-examples/src/bin/serial.rs_ (renamed from embassy-stm32-examples/src/bin/serial.rs)0
-rw-r--r--embassy-stm32-examples/src/bin/usb_serial.rs_ (renamed from embassy-stm32-examples/src/bin/usb_serial.rs)0
-rw-r--r--embassy-stm32/Cargo.toml49
-rw-r--r--embassy-stm32/src/chip/f429.rs6
-rw-r--r--embassy-stm32/src/gpio.rs370
-rw-r--r--embassy-stm32/src/lib.rs415
12 files changed, 493 insertions, 479 deletions
diff --git a/embassy-stm32-examples/Cargo.toml b/embassy-stm32-examples/Cargo.toml
index f12ed9101..af809b838 100644
--- a/embassy-stm32-examples/Cargo.toml
+++ b/embassy-stm32-examples/Cargo.toml
@@ -7,6 +7,7 @@ version = "0.1.0"
7[features] 7[features]
8default = [ 8default = [
9 "defmt-default", 9 "defmt-default",
10 "f429",
10] 11]
11defmt-default = [] 12defmt-default = []
12defmt-trace = [] 13defmt-trace = []
@@ -15,23 +16,23 @@ defmt-info = []
15defmt-warn = [] 16defmt-warn = []
16defmt-error = [] 17defmt-error = []
17 18
18stm32f401 = ["embassy-stm32/stm32f401"] 19f401 = ["embassy-stm32/f401"]
19stm32f405 = ["embassy-stm32/stm32f405"] 20f405 = ["embassy-stm32/f405"]
20stm32f407 = ["embassy-stm32/stm32f407"] 21f407 = ["embassy-stm32/f407"]
21stm32f410 = ["embassy-stm32/stm32f410"] 22f410 = ["embassy-stm32/f410"]
22stm32f411 = ["embassy-stm32/stm32f411"] 23f411 = ["embassy-stm32/f411"]
23stm32f412 = ["embassy-stm32/stm32f412"] 24f412 = ["embassy-stm32/f412"]
24stm32f413 = ["embassy-stm32/stm32f413"] 25f413 = ["embassy-stm32/f413"]
25stm32f415 = ["embassy-stm32/stm32f405"] 26f415 = ["embassy-stm32/f405"]
26stm32f417 = ["embassy-stm32/stm32f407"] 27f417 = ["embassy-stm32/f407"]
27stm32f423 = ["embassy-stm32/stm32f413"] 28f423 = ["embassy-stm32/f413"]
28stm32f427 = ["embassy-stm32/stm32f427"] 29f427 = ["embassy-stm32/f427"]
29stm32f429 = ["embassy-stm32/stm32f429"] 30f429 = ["embassy-stm32/f429"]
30stm32f437 = ["embassy-stm32/stm32f427"] 31f437 = ["embassy-stm32/f427"]
31stm32f439 = ["embassy-stm32/stm32f429"] 32f439 = ["embassy-stm32/f429"]
32stm32f446 = ["embassy-stm32/stm32f446"] 33f446 = ["embassy-stm32/f446"]
33stm32f469 = ["embassy-stm32/stm32f469"] 34f469 = ["embassy-stm32/f469"]
34stm32f479 = ["embassy-stm32/stm32f469"] 35f479 = ["embassy-stm32/f469"]
35 36
36 37
37[dependencies] 38[dependencies]
@@ -39,6 +40,7 @@ embassy = { version = "0.1.0", path = "../embassy", features = ["defmt", "defmt-
39embassy-traits = { version = "0.1.0", path = "../embassy-traits", features = ["defmt"] } 40embassy-traits = { version = "0.1.0", path = "../embassy-traits", features = ["defmt"] }
40embassy-stm32 = { version = "0.1.0", path = "../embassy-stm32" } 41embassy-stm32 = { version = "0.1.0", path = "../embassy-stm32" }
41embassy-extras = {version = "0.1.0", path = "../embassy-extras" } 42embassy-extras = {version = "0.1.0", path = "../embassy-extras" }
43stm32f4 = { version = "0.13", features = ["stm32f429"] }
42 44
43defmt = "0.2.0" 45defmt = "0.2.0"
44defmt-rtt = "0.2.0" 46defmt-rtt = "0.2.0"
@@ -49,5 +51,3 @@ embedded-hal = { version = "0.2.4" }
49panic-probe = "0.1.0" 51panic-probe = "0.1.0"
50futures = { version = "0.3.8", default-features = false, features = ["async-await"] } 52futures = { version = "0.3.8", default-features = false, features = ["async-await"] }
51rtt-target = { version = "0.3", features = ["cortex-m"] } 53rtt-target = { version = "0.3", features = ["cortex-m"] }
52bxcan = "0.5.0"
53usb-device = "0.2.7"
diff --git a/embassy-stm32-examples/src/bin/blinky.rs b/embassy-stm32-examples/src/bin/blinky.rs
new file mode 100644
index 000000000..a90992be4
--- /dev/null
+++ b/embassy-stm32-examples/src/bin/blinky.rs
@@ -0,0 +1,52 @@
1#![no_std]
2#![no_main]
3#![feature(trait_alias)]
4#![feature(min_type_alias_impl_trait)]
5#![feature(impl_trait_in_bindings)]
6#![feature(type_alias_impl_trait)]
7
8#[path = "../example_common.rs"]
9mod example_common;
10use embassy_stm32::gpio::{Level, Output};
11use embedded_hal::digital::v2::OutputPin;
12use example_common::*;
13
14use cortex_m_rt::entry;
15use stm32f4::stm32f429 as pac;
16
17#[entry]
18fn main() -> ! {
19 info!("Hello World!");
20
21 let pp = pac::Peripherals::take().unwrap();
22
23 pp.DBGMCU.cr.modify(|_, w| {
24 w.dbg_sleep().set_bit();
25 w.dbg_standby().set_bit();
26 w.dbg_stop().set_bit()
27 });
28 pp.RCC.ahb1enr.modify(|_, w| w.dma1en().enabled());
29
30 pp.RCC.ahb1enr.modify(|_, w| {
31 w.gpioaen().enabled();
32 w.gpioben().enabled();
33 w.gpiocen().enabled();
34 w.gpioden().enabled();
35 w.gpioeen().enabled();
36 w.gpiofen().enabled();
37 w
38 });
39
40 let p = embassy_stm32::Peripherals::take().unwrap();
41 let mut led = Output::new(p.PB7, Level::High);
42
43 loop {
44 info!("high");
45 led.set_high().unwrap();
46 cortex_m::asm::delay(1_000_000);
47
48 info!("low");
49 led.set_low().unwrap();
50 cortex_m::asm::delay(1_000_000);
51 }
52}
diff --git a/embassy-stm32-examples/src/bin/can.rs b/embassy-stm32-examples/src/bin/can.rs_
index 72272212e..72272212e 100644
--- a/embassy-stm32-examples/src/bin/can.rs
+++ b/embassy-stm32-examples/src/bin/can.rs_
diff --git a/embassy-stm32-examples/src/bin/exti.rs b/embassy-stm32-examples/src/bin/exti.rs_
index e13b23bac..e13b23bac 100644
--- a/embassy-stm32-examples/src/bin/exti.rs
+++ b/embassy-stm32-examples/src/bin/exti.rs_
diff --git a/embassy-stm32-examples/src/bin/hello.rs b/embassy-stm32-examples/src/bin/hello.rs
deleted file mode 100644
index b851482d4..000000000
--- a/embassy-stm32-examples/src/bin/hello.rs
+++ /dev/null
@@ -1,42 +0,0 @@
1#![no_std]
2#![no_main]
3#![feature(trait_alias)]
4#![feature(min_type_alias_impl_trait)]
5#![feature(impl_trait_in_bindings)]
6#![feature(type_alias_impl_trait)]
7
8#[path = "../example_common.rs"]
9mod example_common;
10use example_common::*;
11
12use cortex_m_rt::entry;
13use embassy_stm32::hal::prelude::*;
14
15#[entry]
16fn main() -> ! {
17 info!("Hello World!");
18
19 let p = embassy_stm32::pac::Peripherals::take().unwrap();
20
21 p.DBGMCU.cr.modify(|_, w| {
22 w.dbg_sleep().set_bit();
23 w.dbg_standby().set_bit();
24 w.dbg_stop().set_bit()
25 });
26 p.RCC.ahb1enr.modify(|_, w| w.dma1en().enabled());
27
28 let gpioa = p.GPIOA.split();
29 let gpioc = p.GPIOC.split();
30
31 let mut led = gpioc.pc13.into_push_pull_output();
32 let button = gpioa.pa0.into_pull_up_input();
33 led.set_low().unwrap();
34
35 loop {
36 if button.is_high().unwrap() {
37 led.set_low().unwrap();
38 } else {
39 led.set_high().unwrap();
40 }
41 }
42}
diff --git a/embassy-stm32-examples/src/bin/rtc_async.rs b/embassy-stm32-examples/src/bin/rtc_async.rs_
index ea54a2a94..ea54a2a94 100644
--- a/embassy-stm32-examples/src/bin/rtc_async.rs
+++ b/embassy-stm32-examples/src/bin/rtc_async.rs_
diff --git a/embassy-stm32-examples/src/bin/serial.rs b/embassy-stm32-examples/src/bin/serial.rs_
index 9aeca5375..9aeca5375 100644
--- a/embassy-stm32-examples/src/bin/serial.rs
+++ b/embassy-stm32-examples/src/bin/serial.rs_
diff --git a/embassy-stm32-examples/src/bin/usb_serial.rs b/embassy-stm32-examples/src/bin/usb_serial.rs_
index 6a1d27d54..6a1d27d54 100644
--- a/embassy-stm32-examples/src/bin/usb_serial.rs
+++ b/embassy-stm32-examples/src/bin/usb_serial.rs_
diff --git a/embassy-stm32/Cargo.toml b/embassy-stm32/Cargo.toml
index 523359417..15f902cf6 100644
--- a/embassy-stm32/Cargo.toml
+++ b/embassy-stm32/Cargo.toml
@@ -11,31 +11,28 @@ defmt-info = [ ]
11defmt-warn = [ ] 11defmt-warn = [ ]
12defmt-error = [ ] 12defmt-error = [ ]
13 13
14stm32f401 = ["stm32f4xx-hal/stm32f401"] 14f4 = []
15stm32f405 = ["stm32f4xx-hal/stm32f405"] 15f401 = ["f4"]
16stm32f407 = ["stm32f4xx-hal/stm32f407"] 16f405 = ["f4"]
17stm32f410 = ["stm32f4xx-hal/stm32f410"] 17f407 = ["f4"]
18stm32f411 = ["stm32f4xx-hal/stm32f411"] 18f410 = ["f4"]
19stm32f412 = ["stm32f4xx-hal/stm32f412"] 19f411 = ["f4"]
20stm32f413 = ["stm32f4xx-hal/stm32f413"] 20f412 = ["f4"]
21stm32f415 = ["stm32f4xx-hal/stm32f405"] 21f413 = ["f4"]
22stm32f417 = ["stm32f4xx-hal/stm32f407"] 22f415 = ["f4"]
23stm32f423 = ["stm32f4xx-hal/stm32f413"] 23f417 = ["f4"]
24stm32f427 = ["stm32f4xx-hal/stm32f427"] 24f423 = ["f4"]
25stm32f429 = ["stm32f4xx-hal/stm32f429"] 25f427 = ["f4"]
26stm32f437 = ["stm32f4xx-hal/stm32f427"] 26f429 = ["f4"]
27stm32f439 = ["stm32f4xx-hal/stm32f429"] 27f437 = ["f4"]
28stm32f446 = ["stm32f4xx-hal/stm32f446"] 28f439 = ["f4"]
29stm32f469 = ["stm32f4xx-hal/stm32f469"] 29f446 = ["f4"]
30stm32f479 = ["stm32f4xx-hal/stm32f469"] 30f469 = ["f4"]
31 31f479 = ["f4"]
32stm32l0x1 = ["stm32l0xx-hal/stm32l0x1"]
33stm32l0x2 = ["stm32l0xx-hal/stm32l0x2"]
34stm32l0x3 = ["stm32l0xx-hal/stm32l0x3"]
35 32
36[dependencies] 33[dependencies]
37embassy = { version = "0.1.0", path = "../embassy" } 34embassy = { version = "0.1.0", path = "../embassy" }
38embassy-macros = { version = "0.1.0", path = "../embassy-macros", features = ["stm32"]} 35embassy-macros = { version = "0.1.0", path = "../embassy-macros" }
39embassy-extras = {version = "0.1.0", path = "../embassy-extras" } 36embassy-extras = {version = "0.1.0", path = "../embassy-extras" }
40 37
41defmt = { version = "0.2.0", optional = true } 38defmt = { version = "0.2.0", optional = true }
@@ -43,9 +40,5 @@ log = { version = "0.4.11", optional = true }
43cortex-m-rt = "0.6.13" 40cortex-m-rt = "0.6.13"
44cortex-m = "0.7.1" 41cortex-m = "0.7.1"
45embedded-hal = { version = "0.2.4" } 42embedded-hal = { version = "0.2.4" }
46embedded-dma = { version = "0.1.2" } 43futures = { version = "0.3.5", default-features = false, features = ["async-await"] }
47bxcan = "0.5.0" 44stm32-metapac = { path = "../../stm32-metapac"}
48nb = "*"
49stm32f4xx-hal = { version = "0.9.0", features = ["rt", "can", "usb_fs"], optional = true }
50stm32l0xx-hal = { version = "0.7.0", features = ["rt"], optional = true }
51futures = { version = "0.3.5", default-features = false, features = ["async-await"] } \ No newline at end of file
diff --git a/embassy-stm32/src/chip/f429.rs b/embassy-stm32/src/chip/f429.rs
new file mode 100644
index 000000000..1c2fdc0c6
--- /dev/null
+++ b/embassy-stm32/src/chip/f429.rs
@@ -0,0 +1,6 @@
1use embassy_extras::peripherals;
2
3peripherals!(
4 PA0, PA1, PA2, PA3, PA4, PA5, PA6, PA7, PA8, PA9, PA10, PA11, PA12, PA13, PA14, PA15, PB0, PB1,
5 PB2, PB3, PB4, PB5, PB6, PB7, PB8, PB9, PB10, PB11, PB12, PB13, PB14, PB15,
6);
diff --git a/embassy-stm32/src/gpio.rs b/embassy-stm32/src/gpio.rs
new file mode 100644
index 000000000..80fcbba24
--- /dev/null
+++ b/embassy-stm32/src/gpio.rs
@@ -0,0 +1,370 @@
1use core::convert::Infallible;
2use core::hint::unreachable_unchecked;
3use core::marker::PhantomData;
4
5use embassy::util::PeripheralBorrow;
6use embassy_extras::{impl_unborrow, unborrow};
7use embedded_hal::digital::v2::{InputPin, OutputPin, StatefulOutputPin};
8use gpio::vals::{self, Pupdr};
9
10use crate::pac;
11use crate::pac::gpio_v2 as gpio;
12use crate::peripherals;
13
14/// A GPIO port with up to 16 pins.
15#[derive(Debug, Eq, PartialEq)]
16pub enum Port {
17 PortA,
18 PortB,
19}
20
21/// Pull setting for an input.
22#[derive(Debug, Eq, PartialEq)]
23#[cfg_attr(feature = "defmt", derive(defmt::Format))]
24pub enum Pull {
25 None,
26 Up,
27 Down,
28}
29
30/*
31/// GPIO input driver.
32pub struct Input<'d, T: Pin> {
33 pub(crate) pin: T,
34 phantom: PhantomData<&'d mut T>,
35}
36
37impl<'d, T: Pin> Input<'d, T> {
38 pub fn new(pin: impl PeripheralBorrow<Target = T> + 'd, pull: Pull) -> Self {
39 unborrow!(pin);
40
41 pin.conf().write(|w| {
42 w.dir().input();
43 w.input().connect();
44 match pull {
45 Pull::None => {
46 w.pull().disabled();
47 }
48 Pull::Up => {
49 w.pull().pullup();
50 }
51 Pull::Down => {
52 w.pull().pulldown();
53 }
54 }
55 w.drive().s0s1();
56 w.sense().disabled();
57 w
58 });
59
60 Self {
61 pin,
62 phantom: PhantomData,
63 }
64 }
65}
66
67impl<'d, T: Pin> Drop for Input<'d, T> {
68 fn drop(&mut self) {
69 self.pin.conf().reset();
70 }
71}
72
73impl<'d, T: Pin> InputPin for Input<'d, T> {
74 type Error = Infallible;
75
76 fn is_high(&self) -> Result<bool, Self::Error> {
77 self.is_low().map(|v| !v)
78 }
79
80 fn is_low(&self) -> Result<bool, Self::Error> {
81 Ok(self.pin.block().in_.read().bits() & (1 << self.pin.pin()) == 0)
82 }
83}
84
85*/
86
87/// Digital input or output level.
88#[derive(Debug, Eq, PartialEq)]
89#[cfg_attr(feature = "defmt", derive(defmt::Format))]
90pub enum Level {
91 Low,
92 High,
93}
94
95/// GPIO output driver.
96pub struct Output<'d, T: Pin> {
97 pub(crate) pin: T,
98 phantom: PhantomData<&'d mut T>,
99}
100
101impl<'d, T: Pin> Output<'d, T> {
102 pub fn new(pin: impl PeripheralBorrow<Target = T> + 'd, initial_output: Level) -> Self {
103 unborrow!(pin);
104
105 match initial_output {
106 Level::High => pin.set_high(),
107 Level::Low => pin.set_low(),
108 }
109
110 cortex_m::interrupt::free(|_| unsafe {
111 let r = pin.block();
112 let n = pin.pin() as usize;
113 r.pupdr().modify(|w| w.set_pupdr(n, vals::Pupdr::FLOATING));
114 r.otyper().modify(|w| w.set_ot(n, vals::Ot::PUSHPULL));
115 r.moder().modify(|w| w.set_moder(n, vals::Moder::OUTPUT));
116 });
117
118 Self {
119 pin,
120 phantom: PhantomData,
121 }
122 }
123}
124
125impl<'d, T: Pin> Drop for Output<'d, T> {
126 fn drop(&mut self) {
127 cortex_m::interrupt::free(|_| unsafe {
128 let r = self.pin.block();
129 let n = self.pin.pin() as usize;
130 r.moder().modify(|w| w.set_moder(n, vals::Moder::INPUT));
131 });
132 }
133}
134
135impl<'d, T: Pin> OutputPin for Output<'d, T> {
136 type Error = Infallible;
137
138 /// Set the output as high.
139 fn set_high(&mut self) -> Result<(), Self::Error> {
140 self.pin.set_high();
141 Ok(())
142 }
143
144 /// Set the output as low.
145 fn set_low(&mut self) -> Result<(), Self::Error> {
146 self.pin.set_low();
147 Ok(())
148 }
149}
150
151impl<'d, T: Pin> StatefulOutputPin for Output<'d, T> {
152 /// Is the output pin set as high?
153 fn is_set_high(&self) -> Result<bool, Self::Error> {
154 self.is_set_low().map(|v| !v)
155 }
156
157 /// Is the output pin set as low?
158 fn is_set_low(&self) -> Result<bool, Self::Error> {
159 let state = unsafe { self.pin.block().odr().read().odr(self.pin.pin() as _) };
160 Ok(state == vals::Odr::LOW)
161 }
162}
163
164pub(crate) mod sealed {
165 use super::*;
166
167 pub trait Pin {
168 fn pin_port(&self) -> u8;
169
170 #[inline]
171 fn _pin(&self) -> u8 {
172 self.pin_port() % 16
173 }
174 #[inline]
175 fn _port(&self) -> u8 {
176 self.pin_port() / 16
177 }
178
179 #[inline]
180 fn block(&self) -> gpio::Gpio {
181 let p = 0x4002_0000 + (self._port() as u32) * 0x400;
182 gpio::Gpio(p as *mut u8)
183 }
184
185 /// Set the output as high.
186 #[inline]
187 fn set_high(&self) {
188 unsafe {
189 self.block()
190 .bsrr()
191 .write(|w| w.set_bs(self._pin() as _, true));
192 }
193 }
194
195 /// Set the output as low.
196 #[inline]
197 fn set_low(&self) {
198 unsafe {
199 self.block()
200 .bsrr()
201 .write(|w| w.set_br(self._pin() as _, true));
202 }
203 }
204 }
205
206 pub trait OptionalPin {}
207}
208
209pub trait Pin: sealed::Pin + Sized {
210 /// Number of the pin within the port (0..31)
211 #[inline]
212 fn pin(&self) -> u8 {
213 self._pin()
214 }
215
216 /// Port of the pin
217 #[inline]
218 fn port(&self) -> Port {
219 match self.pin_port() / 16 {
220 0 => Port::PortA,
221 1 => Port::PortB,
222 _ => unsafe { unreachable_unchecked() },
223 }
224 }
225
226 #[inline]
227 fn psel_bits(&self) -> u32 {
228 self.pin_port() as u32
229 }
230
231 /// Convert from concrete pin type PX_XX to type erased `AnyPin`.
232 #[inline]
233 fn degrade(self) -> AnyPin {
234 AnyPin {
235 pin_port: self.pin_port(),
236 }
237 }
238}
239
240// Type-erased GPIO pin
241pub struct AnyPin {
242 pin_port: u8,
243}
244
245impl AnyPin {
246 #[inline]
247 pub unsafe fn steal(pin_port: u8) -> Self {
248 Self { pin_port }
249 }
250}
251
252impl_unborrow!(AnyPin);
253impl Pin for AnyPin {}
254impl sealed::Pin for AnyPin {
255 #[inline]
256 fn pin_port(&self) -> u8 {
257 self.pin_port
258 }
259}
260
261// ====================
262
263pub trait OptionalPin: sealed::OptionalPin + Sized {
264 type Pin: Pin;
265 fn pin(&self) -> Option<&Self::Pin>;
266 fn pin_mut(&mut self) -> Option<&mut Self::Pin>;
267
268 #[inline]
269 fn psel_bits(&self) -> u32 {
270 self.pin().map_or(1u32 << 31, |pin| Pin::psel_bits(pin))
271 }
272
273 /// Convert from concrete pin type PX_XX to type erased `Option<AnyPin>`.
274 #[inline]
275 fn degrade_optional(mut self) -> Option<AnyPin> {
276 self.pin_mut()
277 .map(|pin| unsafe { core::ptr::read(pin) }.degrade())
278 }
279}
280
281impl<T: Pin> sealed::OptionalPin for T {}
282impl<T: Pin> OptionalPin for T {
283 type Pin = T;
284
285 #[inline]
286 fn pin(&self) -> Option<&T> {
287 Some(self)
288 }
289
290 #[inline]
291 fn pin_mut(&mut self) -> Option<&mut T> {
292 Some(self)
293 }
294}
295
296// Uninhabited enum, so it's actually impossible to create a DummyPin value.
297#[doc(hidden)]
298pub enum DummyPin {}
299impl Pin for DummyPin {}
300impl sealed::Pin for DummyPin {
301 #[inline]
302 fn pin_port(&self) -> u8 {
303 unreachable!()
304 }
305}
306
307#[derive(Clone, Copy, Debug)]
308pub struct NoPin;
309impl_unborrow!(NoPin);
310impl sealed::OptionalPin for NoPin {}
311impl OptionalPin for NoPin {
312 type Pin = DummyPin;
313
314 #[inline]
315 fn pin(&self) -> Option<&DummyPin> {
316 None
317 }
318
319 #[inline]
320 fn pin_mut(&mut self) -> Option<&mut DummyPin> {
321 None
322 }
323}
324
325// ====================
326
327macro_rules! impl_pin {
328 ($type:ident, $port_num:expr, $pin_num:expr) => {
329 impl Pin for peripherals::$type {}
330 impl sealed::Pin for peripherals::$type {
331 #[inline]
332 fn pin_port(&self) -> u8 {
333 $port_num * 16 + $pin_num
334 }
335 }
336 };
337}
338
339impl_pin!(PA0, 0, 0);
340impl_pin!(PA1, 0, 1);
341impl_pin!(PA2, 0, 2);
342impl_pin!(PA3, 0, 3);
343impl_pin!(PA4, 0, 4);
344impl_pin!(PA5, 0, 5);
345impl_pin!(PA6, 0, 6);
346impl_pin!(PA7, 0, 7);
347impl_pin!(PA8, 0, 8);
348impl_pin!(PA9, 0, 9);
349impl_pin!(PA10, 0, 10);
350impl_pin!(PA11, 0, 11);
351impl_pin!(PA12, 0, 12);
352impl_pin!(PA13, 0, 13);
353impl_pin!(PA14, 0, 14);
354impl_pin!(PA15, 0, 15);
355impl_pin!(PB0, 1, 0);
356impl_pin!(PB1, 1, 1);
357impl_pin!(PB2, 1, 2);
358impl_pin!(PB3, 1, 3);
359impl_pin!(PB4, 1, 4);
360impl_pin!(PB5, 1, 5);
361impl_pin!(PB6, 1, 6);
362impl_pin!(PB7, 1, 7);
363impl_pin!(PB8, 1, 8);
364impl_pin!(PB9, 1, 9);
365impl_pin!(PB10, 1, 10);
366impl_pin!(PB11, 1, 11);
367impl_pin!(PB12, 1, 12);
368impl_pin!(PB13, 1, 13);
369impl_pin!(PB14, 1, 14);
370impl_pin!(PB15, 1, 15);
diff --git a/embassy-stm32/src/lib.rs b/embassy-stm32/src/lib.rs
index 56efa461c..58a846229 100644
--- a/embassy-stm32/src/lib.rs
+++ b/embassy-stm32/src/lib.rs
@@ -6,395 +6,30 @@
6#![feature(type_alias_impl_trait)] 6#![feature(type_alias_impl_trait)]
7#![allow(incomplete_features)] 7#![allow(incomplete_features)]
8 8
9#[cfg(any(
10 feature = "stm32f401",
11 feature = "stm32f405",
12 feature = "stm32f407",
13 feature = "stm32f410",
14 feature = "stm32f411",
15 feature = "stm32f412",
16 feature = "stm32f413",
17 feature = "stm32f415",
18 feature = "stm32f417",
19 feature = "stm32f423",
20 feature = "stm32f427",
21 feature = "stm32f429",
22 feature = "stm32f437",
23 feature = "stm32f439",
24 feature = "stm32f446",
25 feature = "stm32f469",
26 feature = "stm32f479",
27))]
28mod f4;
29
30#[cfg(any(
31 feature = "stm32f401",
32 feature = "stm32f405",
33 feature = "stm32f407",
34 feature = "stm32f412",
35 feature = "stm32f413",
36 feature = "stm32f415",
37 feature = "stm32f417",
38 feature = "stm32f423",
39 feature = "stm32f427",
40 feature = "stm32f429",
41 feature = "stm32f437",
42 feature = "stm32f439",
43 feature = "stm32f446",
44 feature = "stm32f469",
45 feature = "stm32f479",
46))]
47pub use {stm32f4xx_hal as hal, stm32f4xx_hal::stm32 as pac};
48
49#[cfg(any(feature = "stm32l0x1", feature = "stm32l0x2", feature = "stm32l0x3",))]
50pub use {stm32l0xx_hal as hal, stm32l0xx_hal::pac};
51
52pub mod fmt; 9pub mod fmt;
53 10
54pub mod exti; 11#[cfg_attr(feature = "f401", path = "chip/f401.rs")]
55pub mod interrupt; 12#[cfg_attr(feature = "f405", path = "chip/f405.rs")]
56 13#[cfg_attr(feature = "f407", path = "chip/f407.rs")]
57#[cfg(any( 14#[cfg_attr(feature = "f410", path = "chip/f410.rs")]
58 feature = "stm32f401", 15#[cfg_attr(feature = "f411", path = "chip/f411.rs")]
59 feature = "stm32f405", 16#[cfg_attr(feature = "f412", path = "chip/f412.rs")]
60 feature = "stm32f407", 17#[cfg_attr(feature = "f413", path = "chip/f413.rs")]
61 feature = "stm32f412", 18#[cfg_attr(feature = "f415", path = "chip/f415.rs")]
62 feature = "stm32f413", 19#[cfg_attr(feature = "f417", path = "chip/f417.rs")]
63 feature = "stm32f415", 20#[cfg_attr(feature = "f423", path = "chip/f423.rs")]
64 feature = "stm32f417", 21#[cfg_attr(feature = "f427", path = "chip/f427.rs")]
65 feature = "stm32f423", 22#[cfg_attr(feature = "f429", path = "chip/f429.rs")]
66 feature = "stm32f427", 23#[cfg_attr(feature = "f437", path = "chip/f437.rs")]
67 feature = "stm32f429", 24#[cfg_attr(feature = "f439", path = "chip/f439.rs")]
68 feature = "stm32f437", 25#[cfg_attr(feature = "f446", path = "chip/f446.rs")]
69 feature = "stm32f439", 26#[cfg_attr(feature = "f469", path = "chip/f469.rs")]
70 feature = "stm32f446", 27#[cfg_attr(feature = "f479", path = "chip/f479.rs")]
71 feature = "stm32f469", 28mod chip;
72 feature = "stm32f479", 29pub use chip::{peripherals, Peripherals};
73))] 30
74pub mod can; 31pub mod gpio;
75 32//pub mod exti;
76#[cfg(any( 33//pub mod interrupt;
77 feature = "stm32f401", 34
78 feature = "stm32f405", 35pub(crate) use stm32_metapac as pac;
79 feature = "stm32f407",
80 feature = "stm32f412",
81 feature = "stm32f413",
82 feature = "stm32f415",
83 feature = "stm32f417",
84 feature = "stm32f423",
85 feature = "stm32f427",
86 feature = "stm32f429",
87 feature = "stm32f437",
88 feature = "stm32f439",
89 feature = "stm32f446",
90 feature = "stm32f469",
91 feature = "stm32f479",
92))]
93pub mod rtc;
94
95#[cfg(any(
96 feature = "stm32f401",
97 feature = "stm32f405",
98 feature = "stm32f407",
99 feature = "stm32f412",
100 feature = "stm32f413",
101 feature = "stm32f415",
102 feature = "stm32f417",
103 feature = "stm32f423",
104 feature = "stm32f427",
105 feature = "stm32f429",
106 feature = "stm32f437",
107 feature = "stm32f439",
108 feature = "stm32f446",
109 feature = "stm32f469",
110 feature = "stm32f479",
111))]
112pub use f4::{serial, spi};
113
114#[cfg(any(
115 feature = "stm32f401",
116 feature = "stm32f405",
117 feature = "stm32f407",
118 feature = "stm32f410",
119 feature = "stm32f411",
120 feature = "stm32f412",
121 feature = "stm32f413",
122 feature = "stm32f415",
123 feature = "stm32f417",
124 feature = "stm32f423",
125 feature = "stm32f427",
126 feature = "stm32f429",
127 feature = "stm32f437",
128 feature = "stm32f439",
129 feature = "stm32f446",
130 feature = "stm32f469",
131 feature = "stm32f479",
132))]
133unsafe impl embassy_extras::usb::USBInterrupt for interrupt::OTG_FS {}
134
135use core::option::Option;
136use hal::prelude::*;
137use hal::rcc::Clocks;
138
139#[cfg(feature = "stm32f446")]
140embassy_extras::std_peripherals! {
141 DCMI,
142 FMC,
143 DBGMCU,
144 DMA2,
145 DMA1,
146// RCC,
147 GPIOH,
148 GPIOG,
149 GPIOF,
150 GPIOE,
151 GPIOD,
152 GPIOC,
153 GPIOB,
154 GPIOA,
155 SYSCFG,
156 SPI1,
157 SPI2,
158 SPI3,
159 SPI4,
160 ADC1,
161 ADC2,
162 ADC3,
163 USART6,
164 USART1,
165 USART2,
166 USART3,
167 DAC,
168 I2C3,
169 I2C2,
170 I2C1,
171 IWDG,
172 WWDG,
173 RTC,
174 UART4,
175 UART5,
176 ADC_COMMON,
177 TIM1,
178 TIM2,
179 TIM8,
180// TIM3,
181 TIM4,
182 TIM5,
183 TIM9,
184 TIM12,
185 TIM10,
186 TIM13,
187 TIM14,
188 TIM11,
189 TIM6,
190 TIM7,
191 CRC,
192 OTG_FS_GLOBAL,
193 OTG_FS_HOST,
194 OTG_FS_DEVICE,
195 OTG_FS_PWRCLK,
196 CAN1,
197 CAN2,
198 FLASH,
199 EXTI,
200 OTG_HS_GLOBAL,
201 OTG_HS_HOST,
202 OTG_HS_DEVICE,
203 OTG_HS_PWRCLK,
204 SAI1,
205 SAI2,
206 PWR,
207 QUADSPI,
208 SPDIFRX,
209// SDMMC,
210 HDMI_CEC,
211 FPU,
212 STK,
213 NVIC_STIR,
214 FPU_CPACR,
215 SCB_ACTRL,
216}
217
218#[cfg(feature = "stm32f405")]
219embassy_extras::std_peripherals! {
220 RNG,
221 DCMI,
222 FSMC,
223 DBGMCU,
224 DMA2,
225 DMA1,
226// RCC,
227 GPIOI,
228 GPIOH,
229 GPIOG,
230 GPIOF,
231 GPIOE,
232 GPIOD,
233 GPIOC,
234 GPIOJ,
235 GPIOK,
236 GPIOB,
237 GPIOA,
238 SYSCFG,
239 SPI1,
240 SPI2,
241 SPI3,
242 I2S2EXT,
243 I2S3EXT,
244 SPI4,
245 SPI5,
246 SPI6,
247 SDIO,
248 ADC1,
249 ADC2,
250 ADC3,
251 USART6,
252 USART1,
253 USART2,
254 USART3,
255 DAC,
256 PWR,
257 I2C3,
258 I2C2,
259 I2C1,
260 IWDG,
261 WWDG,
262 RTC,
263 UART4,
264 UART5,
265 UART7,
266 UART8,
267 ADC_COMMON,
268 TIM1,
269 TIM8,
270 TIM2,
271// TIM3,
272 TIM4,
273 TIM5,
274 TIM9,
275 TIM12,
276 TIM10,
277 TIM13,
278 TIM14,
279 TIM11,
280 TIM6,
281 TIM7,
282 ETHERNET_MAC,
283 ETHERNET_MMC,
284 ETHERNET_PTP,
285 ETHERNET_DMA,
286 CRC,
287 OTG_FS_GLOBAL,
288 OTG_FS_HOST,
289 OTG_FS_DEVICE,
290 OTG_FS_PWRCLK,
291 CAN1,
292 CAN2,
293 FLASH,
294 EXTI,
295 OTG_HS_GLOBAL,
296 OTG_HS_HOST,
297 OTG_HS_DEVICE,
298 OTG_HS_PWRCLK,
299 SAI1,
300 LTDC,
301 HASH,
302 CRYP,
303 FPU,
304 STK,
305 NVIC_STIR,
306 FPU_CPACR,
307 SCB_ACTRL,
308}
309
310#[cfg(feature = "stm32f407")]
311embassy_extras::std_peripherals! {
312 RNG,
313 DCMI,
314 FSMC,
315 DBGMCU,
316 DMA2,
317 DMA1,
318// RCC,
319 GPIOI,
320 GPIOH,
321 GPIOG,
322 GPIOF,
323 GPIOE,
324 GPIOD,
325 GPIOC,
326 GPIOJ,
327 GPIOK,
328 GPIOB,
329 GPIOA,
330 SYSCFG,
331 SPI1,
332 SPI2,
333 SPI3,
334 I2S2EXT,
335 I2S3EXT,
336 SPI4,
337 SPI5,
338 SPI6,
339 SDIO,
340 ADC1,
341 ADC2,
342 ADC3,
343 USART6,
344 USART1,
345 USART2,
346 USART3,
347 DAC,
348 PWR,
349 I2C3,
350 I2C2,
351 I2C1,
352 IWDG,
353 WWDG,
354 RTC,
355 UART4,
356 UART5,
357 UART7,
358 UART8,
359 ADC_COMMON,
360 TIM1,
361 TIM8,
362 TIM2,
363// TIM3,
364 TIM4,
365 TIM5,
366 TIM9,
367 TIM12,
368 TIM10,
369 TIM13,
370 TIM14,
371 TIM11,
372 TIM6,
373 TIM7,
374 ETHERNET_MAC,
375 ETHERNET_MMC,
376 ETHERNET_PTP,
377 ETHERNET_DMA,
378 CRC,
379 OTG_FS_GLOBAL,
380 OTG_FS_HOST,
381 OTG_FS_DEVICE,
382 OTG_FS_PWRCLK,
383 CAN1,
384 CAN2,
385 FLASH,
386 EXTI,
387 OTG_HS_GLOBAL,
388 OTG_HS_HOST,
389 OTG_HS_DEVICE,
390 OTG_HS_PWRCLK,
391 SAI1,
392 LTDC,
393 HASH,
394 CRYP,
395 FPU,
396 STK,
397 NVIC_STIR,
398 FPU_CPACR,
399 SCB_ACTRL,
400}