aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2022-01-19 20:47:07 +0000
committerGitHub <[email protected]>2022-01-19 20:47:07 +0000
commit6b0cb0609b4bfa3e464e4603ce373a9de9886103 (patch)
tree70a6590ad9da8c625eb69c21faddb5721bfbcea4
parent071b034a5dbece727b28aee6362e36d66bcb763b (diff)
parent889d757ab8bcfc10caf0a7d75ffb7733a7e71ed1 (diff)
Merge #581
581: stm32: expose all functionality as inherent methods. r=Dirbaio a=Dirbaio This is the previous step to implementing both the embedded-hal 0.2 and embedded-hal 1.0 + embedded-hal-async traits. The equivalent in nrf was done in #552 - Removes need for `unwrap` in gpio. - Removes need for `use embedded_hal::whatever` in all cases. Co-authored-by: Dario Nieuwenhuis <[email protected]>
-rw-r--r--embassy-lora/src/stm32wl/mod.rs19
-rw-r--r--embassy-stm32/.pep82
-rw-r--r--embassy-stm32/src/dma/bdma.rs14
-rw-r--r--embassy-stm32/src/dma/dma.rs14
-rw-r--r--embassy-stm32/src/dma/mod.rs49
-rw-r--r--embassy-stm32/src/exti.rs84
-rw-r--r--embassy-stm32/src/gpio.rs242
-rw-r--r--embassy-stm32/src/i2c/v1.rs50
-rw-r--r--embassy-stm32/src/i2c/v2.rs103
-rw-r--r--embassy-stm32/src/sdmmc/v2.rs8
-rw-r--r--embassy-stm32/src/spi/mod.rs204
-rw-r--r--embassy-stm32/src/spi/v1.rs42
-rw-r--r--embassy-stm32/src/spi/v2.rs41
-rw-r--r--embassy-stm32/src/spi/v3.rs41
-rw-r--r--embassy-stm32/src/subghz/mod.rs28
-rw-r--r--embassy-stm32/src/usart/mod.rs44
-rw-r--r--examples/stm32f1/src/bin/blinky.rs5
-rw-r--r--examples/stm32f3/src/bin/blinky.rs5
-rw-r--r--examples/stm32f3/src/bin/button.rs11
-rw-r--r--examples/stm32f3/src/bin/button_exti.rs1
-rw-r--r--examples/stm32f3/src/bin/usart_dma.rs1
-rw-r--r--examples/stm32f4/src/bin/blinky.rs5
-rw-r--r--examples/stm32f4/src/bin/button.rs11
-rw-r--r--examples/stm32f4/src/bin/button_exti.rs1
-rw-r--r--examples/stm32f4/src/bin/spi.rs8
-rw-r--r--examples/stm32f4/src/bin/spi_dma.rs3
-rw-r--r--examples/stm32f4/src/bin/usart.rs7
-rw-r--r--examples/stm32f4/src/bin/usart_dma.rs1
-rw-r--r--examples/stm32f7/src/bin/blinky.rs5
-rw-r--r--examples/stm32f7/src/bin/button.rs11
-rw-r--r--examples/stm32f7/src/bin/button_exti.rs1
-rw-r--r--examples/stm32f7/src/bin/usart_dma.rs1
-rw-r--r--examples/stm32g0/src/bin/blinky.rs5
-rw-r--r--examples/stm32g0/src/bin/button.rs3
-rw-r--r--examples/stm32g0/src/bin/button_exti.rs1
-rw-r--r--examples/stm32g4/src/bin/blinky.rs5
-rw-r--r--examples/stm32g4/src/bin/button.rs3
-rw-r--r--examples/stm32g4/src/bin/button_exti.rs1
-rw-r--r--examples/stm32h7/src/bin/blinky.rs5
-rw-r--r--examples/stm32h7/src/bin/button_exti.rs1
-rw-r--r--examples/stm32h7/src/bin/camera.rs5
-rw-r--r--examples/stm32h7/src/bin/mco.rs5
-rw-r--r--examples/stm32h7/src/bin/rng.rs5
-rw-r--r--examples/stm32h7/src/bin/spi.rs3
-rw-r--r--examples/stm32h7/src/bin/usart.rs7
-rw-r--r--examples/stm32h7/src/bin/usart_dma.rs1
-rw-r--r--examples/stm32l0/.cargo/config.toml2
-rw-r--r--examples/stm32l0/Cargo.toml2
-rw-r--r--examples/stm32l0/build.rs30
-rw-r--r--examples/stm32l0/memory.x5
-rw-r--r--examples/stm32l0/src/bin/blinky.rs5
-rw-r--r--examples/stm32l0/src/bin/button.rs11
-rw-r--r--examples/stm32l0/src/bin/button_exti.rs1
-rw-r--r--examples/stm32l0/src/bin/spi.rs8
-rw-r--r--examples/stm32l0/src/bin/usart_dma.rs1
-rw-r--r--examples/stm32l1/src/bin/blinky.rs5
-rw-r--r--examples/stm32l1/src/bin/spi.rs8
-rw-r--r--examples/stm32l4/src/bin/blinky.rs5
-rw-r--r--examples/stm32l4/src/bin/button.rs3
-rw-r--r--examples/stm32l4/src/bin/button_exti.rs1
-rw-r--r--examples/stm32l4/src/bin/i2c.rs3
-rw-r--r--examples/stm32l4/src/bin/i2c_dma.rs1
-rw-r--r--examples/stm32l4/src/bin/spi.rs8
-rw-r--r--examples/stm32l4/src/bin/spi_blocking_async.rs9
-rw-r--r--examples/stm32l4/src/bin/spi_dma.rs9
-rw-r--r--examples/stm32l4/src/bin/usart.rs7
-rw-r--r--examples/stm32l4/src/bin/usart_dma.rs1
-rw-r--r--examples/stm32wb55/src/bin/blinky.rs5
-rw-r--r--examples/stm32wb55/src/bin/button_exti.rs1
-rw-r--r--examples/stm32wl55/src/bin/blinky.rs5
-rw-r--r--examples/stm32wl55/src/bin/button.rs11
-rw-r--r--examples/stm32wl55/src/bin/button_exti.rs1
-rw-r--r--examples/stm32wl55/src/bin/subghz.rs12
-rw-r--r--tests/stm32/src/bin/gpio.rs27
-rw-r--r--tests/stm32/src/bin/spi.rs3
-rw-r--r--tests/stm32/src/bin/usart.rs5
-rw-r--r--tests/stm32/src/bin/usart_dma.rs1
-rwxr-xr-xtests/stm32/teleprobe.sh12
78 files changed, 736 insertions, 584 deletions
diff --git a/embassy-lora/src/stm32wl/mod.rs b/embassy-lora/src/stm32wl/mod.rs
index 8cac46f7a..783140cb3 100644
--- a/embassy-lora/src/stm32wl/mod.rs
+++ b/embassy-lora/src/stm32wl/mod.rs
@@ -16,7 +16,6 @@ use embassy_stm32::{
16 TxParams, 16 TxParams,
17 }, 17 },
18}; 18};
19use embedded_hal::digital::v2::OutputPin;
20use lorawan_device::async_device::{ 19use lorawan_device::async_device::{
21 radio::{Bandwidth, PhyRxTx, RfConfig, RxQuality, SpreadingFactor, TxConfig}, 20 radio::{Bandwidth, PhyRxTx, RfConfig, RxQuality, SpreadingFactor, TxConfig},
22 Timings, 21 Timings,
@@ -329,22 +328,22 @@ impl<'a> RadioSwitch<'a> {
329 } 328 }
330 329
331 pub(crate) fn set_rx(&mut self) { 330 pub(crate) fn set_rx(&mut self) {
332 self.ctrl1.set_high().unwrap(); 331 self.ctrl1.set_high();
333 self.ctrl2.set_low().unwrap(); 332 self.ctrl2.set_low();
334 self.ctrl3.set_high().unwrap(); 333 self.ctrl3.set_high();
335 } 334 }
336 335
337 pub(crate) fn set_tx_lp(&mut self) { 336 pub(crate) fn set_tx_lp(&mut self) {
338 self.ctrl1.set_high().unwrap(); 337 self.ctrl1.set_high();
339 self.ctrl2.set_high().unwrap(); 338 self.ctrl2.set_high();
340 self.ctrl3.set_high().unwrap(); 339 self.ctrl3.set_high();
341 } 340 }
342 341
343 #[allow(dead_code)] 342 #[allow(dead_code)]
344 pub(crate) fn set_tx_hp(&mut self) { 343 pub(crate) fn set_tx_hp(&mut self) {
345 self.ctrl2.set_high().unwrap(); 344 self.ctrl2.set_high();
346 self.ctrl1.set_low().unwrap(); 345 self.ctrl1.set_low();
347 self.ctrl3.set_high().unwrap(); 346 self.ctrl3.set_high();
348 } 347 }
349} 348}
350 349
diff --git a/embassy-stm32/.pep8 b/embassy-stm32/.pep8
deleted file mode 100644
index c9a137c87..000000000
--- a/embassy-stm32/.pep8
+++ /dev/null
@@ -1,2 +0,0 @@
1[pep8]
2max_line_length = 255 \ No newline at end of file
diff --git a/embassy-stm32/src/dma/bdma.rs b/embassy-stm32/src/dma/bdma.rs
index b4c77757e..e06ce8c36 100644
--- a/embassy-stm32/src/dma/bdma.rs
+++ b/embassy-stm32/src/dma/bdma.rs
@@ -89,7 +89,8 @@ pac::dma_channels! {
89 ($channel_peri:ident, $dma_peri:ident, bdma, $channel_num:expr, $dmamux:tt) => { 89 ($channel_peri:ident, $dma_peri:ident, bdma, $channel_num:expr, $dmamux:tt) => {
90 impl crate::dma::sealed::Channel for crate::peripherals::$channel_peri { 90 impl crate::dma::sealed::Channel for crate::peripherals::$channel_peri {
91 91
92 unsafe fn start_write<W: Word>(&mut self, request: Request, buf: &[W], reg_addr: *mut W) { 92 unsafe fn start_write<W: Word>(&mut self, request: Request, buf: *const[W], reg_addr: *mut W) {
93 let (ptr, len) = super::slice_ptr_parts(buf);
93 low_level_api::start_transfer( 94 low_level_api::start_transfer(
94 pac::$dma_peri, 95 pac::$dma_peri,
95 $channel_num, 96 $channel_num,
@@ -97,8 +98,8 @@ pac::dma_channels! {
97 request, 98 request,
98 vals::Dir::FROMMEMORY, 99 vals::Dir::FROMMEMORY,
99 reg_addr as *const u32, 100 reg_addr as *const u32,
100 buf.as_ptr() as *mut u32, 101 ptr as *mut u32,
101 buf.len(), 102 len,
102 true, 103 true,
103 vals::Size::from(W::bits()), 104 vals::Size::from(W::bits()),
104 #[cfg(dmamux)] 105 #[cfg(dmamux)]
@@ -129,7 +130,8 @@ pac::dma_channels! {
129 ) 130 )
130 } 131 }
131 132
132 unsafe fn start_read<W: Word>(&mut self, request: Request, reg_addr: *mut W, buf: &mut [W]) { 133 unsafe fn start_read<W: Word>(&mut self, request: Request, reg_addr: *const W, buf: *mut [W]) {
134 let (ptr, len) = super::slice_ptr_parts_mut(buf);
133 low_level_api::start_transfer( 135 low_level_api::start_transfer(
134 pac::$dma_peri, 136 pac::$dma_peri,
135 $channel_num, 137 $channel_num,
@@ -137,8 +139,8 @@ pac::dma_channels! {
137 request, 139 request,
138 vals::Dir::FROMPERIPHERAL, 140 vals::Dir::FROMPERIPHERAL,
139 reg_addr as *const u32, 141 reg_addr as *const u32,
140 buf.as_ptr() as *mut u32, 142 ptr as *mut u32,
141 buf.len(), 143 len,
142 true, 144 true,
143 vals::Size::from(W::bits()), 145 vals::Size::from(W::bits()),
144 #[cfg(dmamux)] 146 #[cfg(dmamux)]
diff --git a/embassy-stm32/src/dma/dma.rs b/embassy-stm32/src/dma/dma.rs
index efe4d1d9d..8e48bb26f 100644
--- a/embassy-stm32/src/dma/dma.rs
+++ b/embassy-stm32/src/dma/dma.rs
@@ -84,15 +84,16 @@ pub(crate) unsafe fn init() {
84pac::dma_channels! { 84pac::dma_channels! {
85 ($channel_peri:ident, $dma_peri:ident, dma, $channel_num:expr, $dmamux:tt) => { 85 ($channel_peri:ident, $dma_peri:ident, dma, $channel_num:expr, $dmamux:tt) => {
86 impl crate::dma::sealed::Channel for crate::peripherals::$channel_peri { 86 impl crate::dma::sealed::Channel for crate::peripherals::$channel_peri {
87 unsafe fn start_write<W: Word>(&mut self, request: Request, buf: &[W], reg_addr: *mut W) { 87 unsafe fn start_write<W: Word>(&mut self, request: Request, buf: *const [W], reg_addr: *mut W) {
88 let (ptr, len) = super::slice_ptr_parts(buf);
88 low_level_api::start_transfer( 89 low_level_api::start_transfer(
89 pac::$dma_peri, 90 pac::$dma_peri,
90 $channel_num, 91 $channel_num,
91 request, 92 request,
92 vals::Dir::MEMORYTOPERIPHERAL, 93 vals::Dir::MEMORYTOPERIPHERAL,
93 reg_addr as *const u32, 94 reg_addr as *const u32,
94 buf.as_ptr() as *mut u32, 95 ptr as *mut u32,
95 buf.len(), 96 len,
96 true, 97 true,
97 vals::Size::from(W::bits()), 98 vals::Size::from(W::bits()),
98 #[cfg(dmamux)] 99 #[cfg(dmamux)]
@@ -121,15 +122,16 @@ pac::dma_channels! {
121 ) 122 )
122 } 123 }
123 124
124 unsafe fn start_read<W: Word>(&mut self, request: Request, reg_addr: *mut W, buf: &mut [W]) { 125 unsafe fn start_read<W: Word>(&mut self, request: Request, reg_addr: *const W, buf: *mut [W]) {
126 let (ptr, len) = super::slice_ptr_parts_mut(buf);
125 low_level_api::start_transfer( 127 low_level_api::start_transfer(
126 pac::$dma_peri, 128 pac::$dma_peri,
127 $channel_num, 129 $channel_num,
128 request, 130 request,
129 vals::Dir::PERIPHERALTOMEMORY, 131 vals::Dir::PERIPHERALTOMEMORY,
130 reg_addr as *const u32, 132 reg_addr as *const u32,
131 buf.as_ptr() as *mut u32, 133 ptr as *mut u32,
132 buf.len(), 134 len,
133 true, 135 true,
134 vals::Size::from(W::bits()), 136 vals::Size::from(W::bits()),
135 #[cfg(dmamux)] 137 #[cfg(dmamux)]
diff --git a/embassy-stm32/src/dma/mod.rs b/embassy-stm32/src/dma/mod.rs
index accc55653..b7067a9c4 100644
--- a/embassy-stm32/src/dma/mod.rs
+++ b/embassy-stm32/src/dma/mod.rs
@@ -10,6 +10,7 @@ pub use dmamux::*;
10 10
11use core::future::Future; 11use core::future::Future;
12use core::marker::PhantomData; 12use core::marker::PhantomData;
13use core::mem;
13use core::pin::Pin; 14use core::pin::Pin;
14use core::task::Waker; 15use core::task::Waker;
15use core::task::{Context, Poll}; 16use core::task::{Context, Poll};
@@ -36,12 +37,13 @@ pub(crate) mod sealed {
36 /// Starts this channel for writing a stream of words. 37 /// Starts this channel for writing a stream of words.
37 /// 38 ///
38 /// Safety: 39 /// Safety:
40 /// - `buf` must point to a valid buffer for DMA reading.
39 /// - `buf` must be alive for the entire duration of the DMA transfer. 41 /// - `buf` must be alive for the entire duration of the DMA transfer.
40 /// - `reg_addr` must be a valid peripheral register address to write to. 42 /// - `reg_addr` must be a valid peripheral register address to write to.
41 unsafe fn start_write<W: super::Word>( 43 unsafe fn start_write<W: super::Word>(
42 &mut self, 44 &mut self,
43 request: Request, 45 request: Request,
44 buf: &[W], 46 buf: *const [W],
45 reg_addr: *mut W, 47 reg_addr: *mut W,
46 ); 48 );
47 49
@@ -60,13 +62,14 @@ pub(crate) mod sealed {
60 /// Starts this channel for reading a stream of words. 62 /// Starts this channel for reading a stream of words.
61 /// 63 ///
62 /// Safety: 64 /// Safety:
65 /// - `buf` must point to a valid buffer for DMA writing.
63 /// - `buf` must be alive for the entire duration of the DMA transfer. 66 /// - `buf` must be alive for the entire duration of the DMA transfer.
64 /// - `reg_addr` must be a valid peripheral register address to write to. 67 /// - `reg_addr` must be a valid peripheral register address to read from.
65 unsafe fn start_read<W: super::Word>( 68 unsafe fn start_read<W: super::Word>(
66 &mut self, 69 &mut self,
67 request: Request, 70 request: Request,
68 reg_addr: *mut W, 71 reg_addr: *const W,
69 buf: &mut [W], 72 buf: *mut [W],
70 ); 73 );
71 74
72 /// Requests the channel to stop. 75 /// Requests the channel to stop.
@@ -132,10 +135,7 @@ mod transfers {
132 135
133 unsafe { channel.start_read::<W>(request, reg_addr, buf) }; 136 unsafe { channel.start_read::<W>(request, reg_addr, buf) };
134 137
135 Transfer { 138 Transfer::new(channel)
136 channel,
137 _phantom: PhantomData,
138 }
139 } 139 }
140 140
141 #[allow(unused)] 141 #[allow(unused)]
@@ -150,10 +150,7 @@ mod transfers {
150 150
151 unsafe { channel.start_write::<W>(request, buf, reg_addr) }; 151 unsafe { channel.start_write::<W>(request, buf, reg_addr) };
152 152
153 Transfer { 153 Transfer::new(channel)
154 channel,
155 _phantom: PhantomData,
156 }
157 } 154 }
158 155
159 #[allow(unused)] 156 #[allow(unused)]
@@ -168,17 +165,24 @@ mod transfers {
168 165
169 unsafe { channel.start_write_repeated::<W>(request, repeated, count, reg_addr) }; 166 unsafe { channel.start_write_repeated::<W>(request, repeated, count, reg_addr) };
170 167
171 Transfer { 168 Transfer::new(channel)
172 channel,
173 _phantom: PhantomData,
174 }
175 } 169 }
176 170
177 struct Transfer<'a, C: Channel> { 171 pub(crate) struct Transfer<'a, C: Channel> {
178 channel: C, 172 channel: C,
179 _phantom: PhantomData<&'a mut C>, 173 _phantom: PhantomData<&'a mut C>,
180 } 174 }
181 175
176 impl<'a, C: Channel> Transfer<'a, C> {
177 pub(crate) fn new(channel: impl Unborrow<Target = C> + 'a) -> Self {
178 unborrow!(channel);
179 Self {
180 channel,
181 _phantom: PhantomData,
182 }
183 }
184 }
185
182 impl<'a, C: Channel> Drop for Transfer<'a, C> { 186 impl<'a, C: Channel> Drop for Transfer<'a, C> {
183 fn drop(&mut self) { 187 fn drop(&mut self) {
184 self.channel.request_stop(); 188 self.channel.request_stop();
@@ -221,3 +225,14 @@ pub(crate) unsafe fn init() {
221 #[cfg(dmamux)] 225 #[cfg(dmamux)]
222 dmamux::init(); 226 dmamux::init();
223} 227}
228
229// TODO: replace transmutes with core::ptr::metadata once it's stable
230#[allow(unused)]
231pub(crate) fn slice_ptr_parts<T>(slice: *const [T]) -> (usize, usize) {
232 unsafe { mem::transmute(slice) }
233}
234
235#[allow(unused)]
236pub(crate) fn slice_ptr_parts_mut<T>(slice: *mut [T]) -> (usize, usize) {
237 unsafe { mem::transmute(slice) }
238}
diff --git a/embassy-stm32/src/exti.rs b/embassy-stm32/src/exti.rs
index 5af51cd11..af401796c 100644
--- a/embassy-stm32/src/exti.rs
+++ b/embassy-stm32/src/exti.rs
@@ -3,7 +3,9 @@ use core::future::Future;
3use core::marker::PhantomData; 3use core::marker::PhantomData;
4use core::pin::Pin; 4use core::pin::Pin;
5use core::task::{Context, Poll}; 5use core::task::{Context, Poll};
6use embassy::traits::gpio::{WaitForAnyEdge, WaitForFallingEdge, WaitForRisingEdge}; 6use embassy::traits::gpio::{
7 WaitForAnyEdge, WaitForFallingEdge, WaitForHigh, WaitForLow, WaitForRisingEdge,
8};
7use embassy::util::Unborrow; 9use embassy::util::Unborrow;
8use embassy::waitqueue::AtomicWaker; 10use embassy::waitqueue::AtomicWaker;
9use embassy_hal_common::unsafe_impl_unborrow; 11use embassy_hal_common::unsafe_impl_unborrow;
@@ -94,17 +96,75 @@ impl<'d, T: GpioPin> ExtiInput<'d, T> {
94 pub fn new(pin: Input<'d, T>, _ch: impl Unborrow<Target = T::ExtiChannel> + 'd) -> Self { 96 pub fn new(pin: Input<'d, T>, _ch: impl Unborrow<Target = T::ExtiChannel> + 'd) -> Self {
95 Self { pin } 97 Self { pin }
96 } 98 }
99
100 pub fn is_high(&self) -> bool {
101 self.pin.is_high()
102 }
103
104 pub fn is_low(&self) -> bool {
105 self.pin.is_low()
106 }
107
108 pub async fn wait_for_high<'a>(&'a mut self) {
109 let fut = ExtiInputFuture::new(self.pin.pin.pin(), self.pin.pin.port(), true, false);
110 if self.is_high() {
111 return;
112 }
113 fut.await
114 }
115
116 pub async fn wait_for_low<'a>(&'a mut self) {
117 let fut = ExtiInputFuture::new(self.pin.pin.pin(), self.pin.pin.port(), false, true);
118 if self.is_low() {
119 return;
120 }
121 fut.await
122 }
123
124 pub async fn wait_for_rising_edge<'a>(&'a mut self) {
125 ExtiInputFuture::new(self.pin.pin.pin(), self.pin.pin.port(), true, false).await
126 }
127
128 pub async fn wait_for_falling_edge<'a>(&'a mut self) {
129 ExtiInputFuture::new(self.pin.pin.pin(), self.pin.pin.port(), false, true).await
130 }
131
132 pub async fn wait_for_any_edge<'a>(&'a mut self) {
133 ExtiInputFuture::new(self.pin.pin.pin(), self.pin.pin.port(), true, true).await
134 }
97} 135}
98 136
99impl<'d, T: GpioPin> InputPin for ExtiInput<'d, T> { 137impl<'d, T: GpioPin> InputPin for ExtiInput<'d, T> {
100 type Error = Infallible; 138 type Error = Infallible;
101 139
102 fn is_high(&self) -> Result<bool, Self::Error> { 140 fn is_high(&self) -> Result<bool, Self::Error> {
103 self.pin.is_high() 141 Ok(self.is_high())
104 } 142 }
105 143
106 fn is_low(&self) -> Result<bool, Self::Error> { 144 fn is_low(&self) -> Result<bool, Self::Error> {
107 self.pin.is_low() 145 Ok(self.is_low())
146 }
147}
148
149impl<'d, T: GpioPin> WaitForHigh for ExtiInput<'d, T> {
150 type Future<'a>
151 where
152 Self: 'a,
153 = impl Future<Output = ()> + 'a;
154
155 fn wait_for_high<'a>(&'a mut self) -> Self::Future<'a> {
156 self.wait_for_high()
157 }
158}
159
160impl<'d, T: GpioPin> WaitForLow for ExtiInput<'d, T> {
161 type Future<'a>
162 where
163 Self: 'a,
164 = impl Future<Output = ()> + 'a;
165
166 fn wait_for_low<'a>(&'a mut self) -> Self::Future<'a> {
167 self.wait_for_low()
108 } 168 }
109} 169}
110 170
@@ -112,10 +172,10 @@ impl<'d, T: GpioPin> WaitForRisingEdge for ExtiInput<'d, T> {
112 type Future<'a> 172 type Future<'a>
113 where 173 where
114 Self: 'a, 174 Self: 'a,
115 = ExtiInputFuture<'a>; 175 = impl Future<Output = ()> + 'a;
116 176
117 fn wait_for_rising_edge<'a>(&'a mut self) -> Self::Future<'a> { 177 fn wait_for_rising_edge<'a>(&'a mut self) -> Self::Future<'a> {
118 ExtiInputFuture::new(self.pin.pin.pin(), self.pin.pin.port(), true, false) 178 self.wait_for_rising_edge()
119 } 179 }
120} 180}
121 181
@@ -123,10 +183,10 @@ impl<'d, T: GpioPin> WaitForFallingEdge for ExtiInput<'d, T> {
123 type Future<'a> 183 type Future<'a>
124 where 184 where
125 Self: 'a, 185 Self: 'a,
126 = ExtiInputFuture<'a>; 186 = impl Future<Output = ()> + 'a;
127 187
128 fn wait_for_falling_edge<'a>(&'a mut self) -> Self::Future<'a> { 188 fn wait_for_falling_edge<'a>(&'a mut self) -> Self::Future<'a> {
129 ExtiInputFuture::new(self.pin.pin.pin(), self.pin.pin.port(), false, true) 189 self.wait_for_falling_edge()
130 } 190 }
131} 191}
132 192
@@ -134,21 +194,21 @@ impl<'d, T: GpioPin> WaitForAnyEdge for ExtiInput<'d, T> {
134 type Future<'a> 194 type Future<'a>
135 where 195 where
136 Self: 'a, 196 Self: 'a,
137 = ExtiInputFuture<'a>; 197 = impl Future<Output = ()> + 'a;
138 198
139 fn wait_for_any_edge<'a>(&'a mut self) -> Self::Future<'a> { 199 fn wait_for_any_edge<'a>(&'a mut self) -> Self::Future<'a> {
140 ExtiInputFuture::new(self.pin.pin.pin(), self.pin.pin.port(), true, true) 200 self.wait_for_any_edge()
141 } 201 }
142} 202}
143 203
144pub struct ExtiInputFuture<'a> { 204struct ExtiInputFuture<'a> {
145 pin: u8, 205 pin: u8,
146 phantom: PhantomData<&'a mut AnyPin>, 206 phantom: PhantomData<&'a mut AnyPin>,
147} 207}
148 208
149impl<'a> ExtiInputFuture<'a> { 209impl<'a> ExtiInputFuture<'a> {
150 fn new(pin: u8, port: u8, rising: bool, falling: bool) -> Self { 210 fn new(pin: u8, port: u8, rising: bool, falling: bool) -> Self {
151 cortex_m::interrupt::free(|_| unsafe { 211 critical_section::with(|_| unsafe {
152 let pin = pin as usize; 212 let pin = pin as usize;
153 exticr_regs() 213 exticr_regs()
154 .exticr(pin / 4) 214 .exticr(pin / 4)
@@ -177,7 +237,7 @@ impl<'a> ExtiInputFuture<'a> {
177 237
178impl<'a> Drop for ExtiInputFuture<'a> { 238impl<'a> Drop for ExtiInputFuture<'a> {
179 fn drop(&mut self) { 239 fn drop(&mut self) {
180 cortex_m::interrupt::free(|_| unsafe { 240 critical_section::with(|_| unsafe {
181 let pin = self.pin as _; 241 let pin = self.pin as _;
182 cpu_regs().imr(0).modify(|w| w.set_line(pin, false)); 242 cpu_regs().imr(0).modify(|w| w.set_line(pin, false));
183 }); 243 });
diff --git a/embassy-stm32/src/gpio.rs b/embassy-stm32/src/gpio.rs
index 1b257c386..57b9ba6b7 100644
--- a/embassy-stm32/src/gpio.rs
+++ b/embassy-stm32/src/gpio.rs
@@ -3,7 +3,7 @@ use core::convert::Infallible;
3use core::marker::PhantomData; 3use core::marker::PhantomData;
4use embassy::util::Unborrow; 4use embassy::util::Unborrow;
5use embassy_hal_common::{unborrow, unsafe_impl_unborrow}; 5use embassy_hal_common::{unborrow, unsafe_impl_unborrow};
6use embedded_hal::digital::v2::{toggleable, InputPin, OutputPin, StatefulOutputPin}; 6use embedded_hal::digital::v2::{InputPin, OutputPin, StatefulOutputPin, ToggleableOutputPin};
7 7
8use crate::pac; 8use crate::pac;
9use crate::pac::gpio::{self, vals}; 9use crate::pac::gpio::{self, vals};
@@ -80,7 +80,7 @@ impl<'d, T: Pin> Input<'d, T> {
80 pub fn new(pin: impl Unborrow<Target = T> + 'd, pull: Pull) -> Self { 80 pub fn new(pin: impl Unborrow<Target = T> + 'd, pull: Pull) -> Self {
81 unborrow!(pin); 81 unborrow!(pin);
82 82
83 cortex_m::interrupt::free(|_| unsafe { 83 critical_section::with(|_| unsafe {
84 let r = pin.block(); 84 let r = pin.block();
85 let n = pin.pin() as usize; 85 let n = pin.pin() as usize;
86 #[cfg(gpio_v1)] 86 #[cfg(gpio_v1)]
@@ -113,11 +113,20 @@ impl<'d, T: Pin> Input<'d, T> {
113 phantom: PhantomData, 113 phantom: PhantomData,
114 } 114 }
115 } 115 }
116
117 pub fn is_high(&self) -> bool {
118 !self.is_low()
119 }
120
121 pub fn is_low(&self) -> bool {
122 let state = unsafe { self.pin.block().idr().read().idr(self.pin.pin() as _) };
123 state == vals::Idr::LOW
124 }
116} 125}
117 126
118impl<'d, T: Pin> Drop for Input<'d, T> { 127impl<'d, T: Pin> Drop for Input<'d, T> {
119 fn drop(&mut self) { 128 fn drop(&mut self) {
120 cortex_m::interrupt::free(|_| unsafe { 129 critical_section::with(|_| unsafe {
121 let r = self.pin.block(); 130 let r = self.pin.block();
122 let n = self.pin.pin() as usize; 131 let n = self.pin.pin() as usize;
123 #[cfg(gpio_v1)] 132 #[cfg(gpio_v1)]
@@ -132,19 +141,6 @@ impl<'d, T: Pin> Drop for Input<'d, T> {
132 } 141 }
133} 142}
134 143
135impl<'d, T: Pin> InputPin for Input<'d, T> {
136 type Error = Infallible;
137
138 fn is_high(&self) -> Result<bool, Self::Error> {
139 self.is_low().map(|v| !v)
140 }
141
142 fn is_low(&self) -> Result<bool, Self::Error> {
143 let state = unsafe { self.pin.block().idr().read().idr(self.pin.pin() as _) };
144 Ok(state == vals::Idr::LOW)
145 }
146}
147
148/// Digital input or output level. 144/// Digital input or output level.
149#[derive(Debug, Eq, PartialEq)] 145#[derive(Debug, Eq, PartialEq)]
150#[cfg_attr(feature = "defmt", derive(defmt::Format))] 146#[cfg_attr(feature = "defmt", derive(defmt::Format))]
@@ -168,7 +164,7 @@ impl<'d, T: Pin> Output<'d, T> {
168 Level::Low => pin.set_low(), 164 Level::Low => pin.set_low(),
169 } 165 }
170 166
171 cortex_m::interrupt::free(|_| unsafe { 167 critical_section::with(|_| unsafe {
172 let r = pin.block(); 168 let r = pin.block();
173 let n = pin.pin() as usize; 169 let n = pin.pin() as usize;
174 #[cfg(gpio_v1)] 170 #[cfg(gpio_v1)]
@@ -191,11 +187,41 @@ impl<'d, T: Pin> Output<'d, T> {
191 phantom: PhantomData, 187 phantom: PhantomData,
192 } 188 }
193 } 189 }
190
191 /// Set the output as high.
192 pub fn set_high(&mut self) {
193 self.pin.set_high();
194 }
195
196 /// Set the output as low.
197 pub fn set_low(&mut self) {
198 self.pin.set_low();
199 }
200
201 /// Is the output pin set as high?
202 pub fn is_set_high(&self) -> bool {
203 !self.is_set_low()
204 }
205
206 /// Is the output pin set as low?
207 pub fn is_set_low(&self) -> bool {
208 let state = unsafe { self.pin.block().odr().read().odr(self.pin.pin() as _) };
209 state == vals::Odr::LOW
210 }
211
212 /// Toggle pin output
213 pub fn toggle(&mut self) {
214 if self.is_set_low() {
215 self.set_high()
216 } else {
217 self.set_low()
218 }
219 }
194} 220}
195 221
196impl<'d, T: Pin> Drop for Output<'d, T> { 222impl<'d, T: Pin> Drop for Output<'d, T> {
197 fn drop(&mut self) { 223 fn drop(&mut self) {
198 cortex_m::interrupt::free(|_| unsafe { 224 critical_section::with(|_| unsafe {
199 let r = self.pin.block(); 225 let r = self.pin.block();
200 let n = self.pin.pin() as usize; 226 let n = self.pin.pin() as usize;
201 #[cfg(gpio_v1)] 227 #[cfg(gpio_v1)]
@@ -214,37 +240,6 @@ impl<'d, T: Pin> Drop for Output<'d, T> {
214 } 240 }
215} 241}
216 242
217impl<'d, T: Pin> OutputPin for Output<'d, T> {
218 type Error = Infallible;
219
220 /// Set the output as high.
221 fn set_high(&mut self) -> Result<(), Self::Error> {
222 self.pin.set_high();
223 Ok(())
224 }
225
226 /// Set the output as low.
227 fn set_low(&mut self) -> Result<(), Self::Error> {
228 self.pin.set_low();
229 Ok(())
230 }
231}
232
233impl<'d, T: Pin> StatefulOutputPin for Output<'d, T> {
234 /// Is the output pin set as high?
235 fn is_set_high(&self) -> Result<bool, Self::Error> {
236 self.is_set_low().map(|v| !v)
237 }
238
239 /// Is the output pin set as low?
240 fn is_set_low(&self) -> Result<bool, Self::Error> {
241 let state = unsafe { self.pin.block().odr().read().odr(self.pin.pin() as _) };
242 Ok(state == vals::Odr::LOW)
243 }
244}
245
246impl<'d, T: Pin> toggleable::Default for Output<'d, T> {}
247
248/// GPIO output open-drain driver. 243/// GPIO output open-drain driver.
249pub struct OutputOpenDrain<'d, T: Pin> { 244pub struct OutputOpenDrain<'d, T: Pin> {
250 pub(crate) pin: T, 245 pub(crate) pin: T,
@@ -265,7 +260,7 @@ impl<'d, T: Pin> OutputOpenDrain<'d, T> {
265 Level::Low => pin.set_low(), 260 Level::Low => pin.set_low(),
266 } 261 }
267 262
268 cortex_m::interrupt::free(|_| unsafe { 263 critical_section::with(|_| unsafe {
269 let r = pin.block(); 264 let r = pin.block();
270 let n = pin.pin() as usize; 265 let n = pin.pin() as usize;
271 #[cfg(gpio_v1)] 266 #[cfg(gpio_v1)]
@@ -294,11 +289,50 @@ impl<'d, T: Pin> OutputOpenDrain<'d, T> {
294 phantom: PhantomData, 289 phantom: PhantomData,
295 } 290 }
296 } 291 }
292
293 pub fn is_high(&self) -> bool {
294 !self.is_low()
295 }
296
297 pub fn is_low(&self) -> bool {
298 let state = unsafe { self.pin.block().idr().read().idr(self.pin.pin() as _) };
299 state == vals::Idr::LOW
300 }
301
302 /// Set the output as high.
303 pub fn set_high(&mut self) {
304 self.pin.set_high();
305 }
306
307 /// Set the output as low.
308 pub fn set_low(&mut self) {
309 self.pin.set_low();
310 }
311
312 /// Is the output pin set as high?
313 pub fn is_set_high(&self) -> bool {
314 !self.is_set_low()
315 }
316
317 /// Is the output pin set as low?
318 pub fn is_set_low(&self) -> bool {
319 let state = unsafe { self.pin.block().odr().read().odr(self.pin.pin() as _) };
320 state == vals::Odr::LOW
321 }
322
323 /// Toggle pin output
324 pub fn toggle(&mut self) {
325 if self.is_set_low() {
326 self.set_high()
327 } else {
328 self.set_low()
329 }
330 }
297} 331}
298 332
299impl<'d, T: Pin> Drop for OutputOpenDrain<'d, T> { 333impl<'d, T: Pin> Drop for OutputOpenDrain<'d, T> {
300 fn drop(&mut self) { 334 fn drop(&mut self) {
301 cortex_m::interrupt::free(|_| unsafe { 335 critical_section::with(|_| unsafe {
302 let r = self.pin.block(); 336 let r = self.pin.block();
303 let n = self.pin.pin() as usize; 337 let n = self.pin.pin() as usize;
304 #[cfg(gpio_v1)] 338 #[cfg(gpio_v1)]
@@ -317,36 +351,6 @@ impl<'d, T: Pin> Drop for OutputOpenDrain<'d, T> {
317 } 351 }
318} 352}
319 353
320impl<'d, T: Pin> OutputPin for OutputOpenDrain<'d, T> {
321 type Error = Infallible;
322
323 /// Set the output as high.
324 fn set_high(&mut self) -> Result<(), Self::Error> {
325 self.pin.set_high();
326 Ok(())
327 }
328
329 /// Set the output as low.
330 fn set_low(&mut self) -> Result<(), Self::Error> {
331 self.pin.set_low();
332 Ok(())
333 }
334}
335
336impl<'d, T: Pin> InputPin for OutputOpenDrain<'d, T> {
337 type Error = Infallible;
338
339 fn is_high(&self) -> Result<bool, Self::Error> {
340 self.is_low().map(|v| !v)
341 }
342
343 fn is_low(&self) -> Result<bool, Self::Error> {
344 // NOTE(safety) Atomic read
345 let state = unsafe { self.pin.block().idr().read().idr(self.pin.pin() as usize) };
346 Ok(state == vals::Idr::LOW)
347 }
348}
349
350pub(crate) mod sealed { 354pub(crate) mod sealed {
351 use super::*; 355 use super::*;
352 356
@@ -612,3 +616,79 @@ pub(crate) unsafe fn init() {
612 }; 616 };
613 } 617 }
614} 618}
619
620mod eh02 {
621 use super::*;
622
623 impl<'d, T: Pin> InputPin for Input<'d, T> {
624 type Error = Infallible;
625
626 fn is_high(&self) -> Result<bool, Self::Error> {
627 Ok(self.is_high())
628 }
629
630 fn is_low(&self) -> Result<bool, Self::Error> {
631 Ok(self.is_low())
632 }
633 }
634
635 impl<'d, T: Pin> OutputPin for Output<'d, T> {
636 type Error = Infallible;
637
638 fn set_high(&mut self) -> Result<(), Self::Error> {
639 Ok(self.set_high())
640 }
641
642 fn set_low(&mut self) -> Result<(), Self::Error> {
643 Ok(self.set_low())
644 }
645 }
646
647 impl<'d, T: Pin> StatefulOutputPin for Output<'d, T> {
648 fn is_set_high(&self) -> Result<bool, Self::Error> {
649 Ok(self.is_set_high())
650 }
651
652 /// Is the output pin set as low?
653 fn is_set_low(&self) -> Result<bool, Self::Error> {
654 Ok(self.is_set_low())
655 }
656 }
657
658 impl<'d, T: Pin> ToggleableOutputPin for Output<'d, T> {
659 type Error = Infallible;
660 fn toggle(&mut self) -> Result<(), Self::Error> {
661 Ok(self.toggle())
662 }
663 }
664
665 impl<'d, T: Pin> OutputPin for OutputOpenDrain<'d, T> {
666 type Error = Infallible;
667
668 fn set_high(&mut self) -> Result<(), Self::Error> {
669 Ok(self.set_high())
670 }
671
672 fn set_low(&mut self) -> Result<(), Self::Error> {
673 Ok(self.set_low())
674 }
675 }
676
677 impl<'d, T: Pin> StatefulOutputPin for OutputOpenDrain<'d, T> {
678 fn is_set_high(&self) -> Result<bool, Self::Error> {
679 Ok(self.is_set_high())
680 }
681
682 /// Is the output pin set as low?
683 fn is_set_low(&self) -> Result<bool, Self::Error> {
684 Ok(self.is_set_low())
685 }
686 }
687
688 impl<'d, T: Pin> ToggleableOutputPin for OutputOpenDrain<'d, T> {
689 type Error = Infallible;
690 fn toggle(&mut self) -> Result<(), Self::Error> {
691 Ok(self.toggle())
692 }
693 }
694}
diff --git a/embassy-stm32/src/i2c/v1.rs b/embassy-stm32/src/i2c/v1.rs
index 6fa269fc2..6b2c8a35c 100644
--- a/embassy-stm32/src/i2c/v1.rs
+++ b/embassy-stm32/src/i2c/v1.rs
@@ -3,9 +3,6 @@ use crate::time::Hertz;
3use core::marker::PhantomData; 3use core::marker::PhantomData;
4use embassy::util::Unborrow; 4use embassy::util::Unborrow;
5use embassy_hal_common::unborrow; 5use embassy_hal_common::unborrow;
6use embedded_hal::blocking::i2c::Read;
7use embedded_hal::blocking::i2c::Write;
8use embedded_hal::blocking::i2c::WriteRead;
9 6
10use crate::pac::i2c; 7use crate::pac::i2c;
11 8
@@ -179,12 +176,8 @@ impl<'d, T: Instance> I2c<'d, T> {
179 let value = T::regs().dr().read().dr(); 176 let value = T::regs().dr().read().dr();
180 Ok(value) 177 Ok(value)
181 } 178 }
182}
183
184impl<'d, T: Instance> Read for I2c<'d, T> {
185 type Error = Error;
186 179
187 fn read(&mut self, addr: u8, buffer: &mut [u8]) -> Result<(), Self::Error> { 180 pub fn blocking_read(&mut self, addr: u8, buffer: &mut [u8]) -> Result<(), Error> {
188 if let Some((last, buffer)) = buffer.split_last_mut() { 181 if let Some((last, buffer)) = buffer.split_last_mut() {
189 // Send a START condition and set ACK bit 182 // Send a START condition and set ACK bit
190 unsafe { 183 unsafe {
@@ -248,12 +241,8 @@ impl<'d, T: Instance> Read for I2c<'d, T> {
248 Err(Error::Overrun) 241 Err(Error::Overrun)
249 } 242 }
250 } 243 }
251}
252
253impl<'d, T: Instance> Write for I2c<'d, T> {
254 type Error = Error;
255 244
256 fn write(&mut self, addr: u8, bytes: &[u8]) -> Result<(), Self::Error> { 245 pub fn blocking_write(&mut self, addr: u8, bytes: &[u8]) -> Result<(), Error> {
257 unsafe { 246 unsafe {
258 self.write_bytes(addr, bytes)?; 247 self.write_bytes(addr, bytes)?;
259 // Send a STOP condition 248 // Send a STOP condition
@@ -267,16 +256,41 @@ impl<'d, T: Instance> Write for I2c<'d, T> {
267 // Fallthrough is success 256 // Fallthrough is success
268 Ok(()) 257 Ok(())
269 } 258 }
259
260 pub fn blocking_write_read(
261 &mut self,
262 addr: u8,
263 bytes: &[u8],
264 buffer: &mut [u8],
265 ) -> Result<(), Error> {
266 unsafe { self.write_bytes(addr, bytes)? };
267 self.blocking_read(addr, buffer)?;
268
269 Ok(())
270 }
270} 271}
271 272
272impl<'d, T: Instance> WriteRead for I2c<'d, T> { 273impl<'d, T: Instance> embedded_hal::blocking::i2c::Read for I2c<'d, T> {
273 type Error = Error; 274 type Error = Error;
274 275
275 fn write_read(&mut self, addr: u8, bytes: &[u8], buffer: &mut [u8]) -> Result<(), Self::Error> { 276 fn read(&mut self, addr: u8, buffer: &mut [u8]) -> Result<(), Self::Error> {
276 unsafe { self.write_bytes(addr, bytes)? }; 277 self.blocking_read(addr, buffer)
277 self.read(addr, buffer)?; 278 }
279}
278 280
279 Ok(()) 281impl<'d, T: Instance> embedded_hal::blocking::i2c::Write for I2c<'d, T> {
282 type Error = Error;
283
284 fn write(&mut self, addr: u8, bytes: &[u8]) -> Result<(), Self::Error> {
285 self.blocking_write(addr, bytes)
286 }
287}
288
289impl<'d, T: Instance> embedded_hal::blocking::i2c::WriteRead for I2c<'d, T> {
290 type Error = Error;
291
292 fn write_read(&mut self, addr: u8, bytes: &[u8], buffer: &mut [u8]) -> Result<(), Self::Error> {
293 self.blocking_write_read(addr, bytes, buffer)
280 } 294 }
281} 295}
282 296
diff --git a/embassy-stm32/src/i2c/v2.rs b/embassy-stm32/src/i2c/v2.rs
index 73b6f5517..af04dc061 100644
--- a/embassy-stm32/src/i2c/v2.rs
+++ b/embassy-stm32/src/i2c/v2.rs
@@ -10,9 +10,6 @@ use embassy::util::Unborrow;
10use embassy::waitqueue::AtomicWaker; 10use embassy::waitqueue::AtomicWaker;
11use embassy_hal_common::drop::OnDrop; 11use embassy_hal_common::drop::OnDrop;
12use embassy_hal_common::unborrow; 12use embassy_hal_common::unborrow;
13use embedded_hal::blocking::i2c::Read;
14use embedded_hal::blocking::i2c::Write;
15use embedded_hal::blocking::i2c::WriteRead;
16use futures::future::poll_fn; 13use futures::future::poll_fn;
17 14
18use crate::dma::NoDma; 15use crate::dma::NoDma;
@@ -300,7 +297,12 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> {
300 } 297 }
301 } 298 }
302 299
303 fn read(&mut self, address: u8, buffer: &mut [u8], restart: bool) -> Result<(), Error> { 300 fn read_internal(
301 &mut self,
302 address: u8,
303 buffer: &mut [u8],
304 restart: bool,
305 ) -> Result<(), Error> {
304 let completed_chunks = buffer.len() / 255; 306 let completed_chunks = buffer.len() / 255;
305 let total_chunks = if completed_chunks * 255 == buffer.len() { 307 let total_chunks = if completed_chunks * 255 == buffer.len() {
306 completed_chunks 308 completed_chunks
@@ -339,7 +341,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> {
339 Ok(()) 341 Ok(())
340 } 342 }
341 343
342 fn write(&mut self, address: u8, bytes: &[u8], send_stop: bool) -> Result<(), Error> { 344 fn write_internal(&mut self, address: u8, bytes: &[u8], send_stop: bool) -> Result<(), Error> {
343 let completed_chunks = bytes.len() / 255; 345 let completed_chunks = bytes.len() / 255;
344 let total_chunks = if completed_chunks * 255 == bytes.len() { 346 let total_chunks = if completed_chunks * 255 == bytes.len() {
345 completed_chunks 347 completed_chunks
@@ -568,14 +570,17 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> {
568 Ok(()) 570 Ok(())
569 } 571 }
570 572
571 pub async fn write_dma(&mut self, address: u8, bytes: &[u8]) -> Result<(), Error> 573 // =========================
574 // Async public API
575
576 pub async fn write(&mut self, address: u8, bytes: &[u8]) -> Result<(), Error>
572 where 577 where
573 TXDMA: crate::i2c::TxDma<T>, 578 TXDMA: crate::i2c::TxDma<T>,
574 { 579 {
575 self.write_dma_internal(address, bytes, true, true).await 580 self.write_dma_internal(address, bytes, true, true).await
576 } 581 }
577 582
578 pub async fn write_dma_vectored(&mut self, address: u8, bytes: &[&[u8]]) -> Result<(), Error> 583 pub async fn write_vectored(&mut self, address: u8, bytes: &[&[u8]]) -> Result<(), Error>
579 where 584 where
580 TXDMA: crate::i2c::TxDma<T>, 585 TXDMA: crate::i2c::TxDma<T>,
581 { 586 {
@@ -597,19 +602,52 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> {
597 Ok(()) 602 Ok(())
598 } 603 }
599 604
600 pub async fn read_dma( 605 pub async fn read(&mut self, address: u8, buffer: &mut [u8]) -> Result<(), Error>
606 where
607 RXDMA: crate::i2c::RxDma<T>,
608 {
609 self.read_dma_internal(address, buffer, false).await
610 }
611
612 pub async fn write_read(
601 &mut self, 613 &mut self,
602 address: u8, 614 address: u8,
615 bytes: &[u8],
603 buffer: &mut [u8], 616 buffer: &mut [u8],
604 restart: bool,
605 ) -> Result<(), Error> 617 ) -> Result<(), Error>
606 where 618 where
607 RXDMA: crate::i2c::RxDma<T>, 619 TXDMA: super::TxDma<T>,
620 RXDMA: super::RxDma<T>,
608 { 621 {
609 self.read_dma_internal(address, buffer, restart).await 622 self.write_dma_internal(address, bytes, true, true).await?;
623 self.read_dma_internal(address, buffer, true).await?;
624 Ok(())
625 }
626
627 // =========================
628 // Blocking public API
629
630 pub fn blocking_read(&mut self, address: u8, buffer: &mut [u8]) -> Result<(), Error> {
631 self.read_internal(address, buffer, false)
632 // Automatic Stop
633 }
634
635 pub fn blocking_write(&mut self, address: u8, bytes: &[u8]) -> Result<(), Error> {
636 self.write_internal(address, bytes, true)
610 } 637 }
611 638
612 pub fn write_vectored(&mut self, address: u8, bytes: &[&[u8]]) -> Result<(), Error> { 639 pub fn blocking_write_read(
640 &mut self,
641 address: u8,
642 bytes: &[u8],
643 buffer: &mut [u8],
644 ) -> Result<(), Error> {
645 self.write_internal(address, bytes, false)?;
646 self.read_internal(address, buffer, true)
647 // Automatic Stop
648 }
649
650 pub fn blocking_write_vectored(&mut self, address: u8, bytes: &[&[u8]]) -> Result<(), Error> {
613 if bytes.is_empty() { 651 if bytes.is_empty() {
614 return Err(Error::ZeroLengthTransfer); 652 return Err(Error::ZeroLengthTransfer);
615 } 653 }
@@ -679,24 +717,23 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> {
679 } 717 }
680} 718}
681 719
682impl<'d, T: Instance> Read for I2c<'d, T> { 720impl<'d, T: Instance> embedded_hal::blocking::i2c::Read for I2c<'d, T> {
683 type Error = Error; 721 type Error = Error;
684 722
685 fn read(&mut self, address: u8, buffer: &mut [u8]) -> Result<(), Self::Error> { 723 fn read(&mut self, address: u8, buffer: &mut [u8]) -> Result<(), Self::Error> {
686 self.read(address, buffer, false) 724 self.blocking_read(address, buffer)
687 // Automatic Stop
688 } 725 }
689} 726}
690 727
691impl<'d, T: Instance> Write for I2c<'d, T> { 728impl<'d, T: Instance> embedded_hal::blocking::i2c::Write for I2c<'d, T> {
692 type Error = Error; 729 type Error = Error;
693 730
694 fn write(&mut self, address: u8, bytes: &[u8]) -> Result<(), Self::Error> { 731 fn write(&mut self, address: u8, bytes: &[u8]) -> Result<(), Self::Error> {
695 self.write(address, bytes, true) 732 self.blocking_write(address, bytes)
696 } 733 }
697} 734}
698 735
699impl<'d, T: Instance> WriteRead for I2c<'d, T> { 736impl<'d, T: Instance> embedded_hal::blocking::i2c::WriteRead for I2c<'d, T> {
700 type Error = Error; 737 type Error = Error;
701 738
702 fn write_read( 739 fn write_read(
@@ -705,9 +742,7 @@ impl<'d, T: Instance> WriteRead for I2c<'d, T> {
705 bytes: &[u8], 742 bytes: &[u8],
706 buffer: &mut [u8], 743 buffer: &mut [u8],
707 ) -> Result<(), Self::Error> { 744 ) -> Result<(), Self::Error> {
708 self.write(address, bytes, false)?; 745 self.blocking_write_read(address, bytes, buffer)
709 self.read(address, buffer, true)
710 // Automatic Stop
711 } 746 }
712} 747}
713 748
@@ -715,7 +750,7 @@ impl<'d, T: Instance> WriteRead for I2c<'d, T> {
715/// 750///
716/// Peripheral options for generating the STOP condition 751/// Peripheral options for generating the STOP condition
717#[derive(Copy, Clone, PartialEq)] 752#[derive(Copy, Clone, PartialEq)]
718pub enum Stop { 753enum Stop {
719 /// Software end mode: Must write register to generate STOP condition 754 /// Software end mode: Must write register to generate STOP condition
720 Software, 755 Software,
721 /// Automatic end mode: A STOP condition is automatically generated once the 756 /// Automatic end mode: A STOP condition is automatically generated once the
@@ -860,32 +895,23 @@ impl<'d, T: Instance, TXDMA: super::TxDma<T>, RXDMA: super::RxDma<T>> I2cTrait<u
860 895
861 type WriteFuture<'a> 896 type WriteFuture<'a>
862 where 897 where
863 'd: 'a, 898 Self: 'a,
864 T: 'a,
865 TXDMA: 'a,
866 RXDMA: 'a,
867 = impl Future<Output = Result<(), Self::Error>> + 'a; 899 = impl Future<Output = Result<(), Self::Error>> + 'a;
868 type ReadFuture<'a> 900 type ReadFuture<'a>
869 where 901 where
870 'd: 'a, 902 Self: 'a,
871 T: 'a,
872 TXDMA: 'a,
873 RXDMA: 'a,
874 = impl Future<Output = Result<(), Self::Error>> + 'a; 903 = impl Future<Output = Result<(), Self::Error>> + 'a;
875 type WriteReadFuture<'a> 904 type WriteReadFuture<'a>
876 where 905 where
877 'd: 'a, 906 Self: 'a,
878 T: 'a,
879 TXDMA: 'a,
880 RXDMA: 'a,
881 = impl Future<Output = Result<(), Self::Error>> + 'a; 907 = impl Future<Output = Result<(), Self::Error>> + 'a;
882 908
883 fn read<'a>(&'a mut self, address: u8, buffer: &'a mut [u8]) -> Self::ReadFuture<'a> { 909 fn read<'a>(&'a mut self, address: u8, buffer: &'a mut [u8]) -> Self::ReadFuture<'a> {
884 self.read_dma(address, buffer, false) 910 self.read(address, buffer)
885 } 911 }
886 912
887 fn write<'a>(&'a mut self, address: u8, bytes: &'a [u8]) -> Self::WriteFuture<'a> { 913 fn write<'a>(&'a mut self, address: u8, bytes: &'a [u8]) -> Self::WriteFuture<'a> {
888 self.write_dma(address, bytes) 914 self.write(address, bytes)
889 } 915 }
890 916
891 fn write_read<'a>( 917 fn write_read<'a>(
@@ -894,9 +920,6 @@ impl<'d, T: Instance, TXDMA: super::TxDma<T>, RXDMA: super::RxDma<T>> I2cTrait<u
894 bytes: &'a [u8], 920 bytes: &'a [u8],
895 buffer: &'a mut [u8], 921 buffer: &'a mut [u8],
896 ) -> Self::WriteReadFuture<'a> { 922 ) -> Self::WriteReadFuture<'a> {
897 async move { 923 self.write_read(address, bytes, buffer)
898 self.write_dma(address, bytes).await?;
899 self.read_dma(address, buffer, true).await
900 }
901 } 924 }
902} 925}
diff --git a/embassy-stm32/src/sdmmc/v2.rs b/embassy-stm32/src/sdmmc/v2.rs
index 5914f92f5..74382ce64 100644
--- a/embassy-stm32/src/sdmmc/v2.rs
+++ b/embassy-stm32/src/sdmmc/v2.rs
@@ -1254,7 +1254,7 @@ where
1254 fn configure(&mut self) { 1254 fn configure(&mut self) {
1255 let (clk_pin, cmd_pin, d0_pin, d1_pin, d2_pin, d3_pin) = self; 1255 let (clk_pin, cmd_pin, d0_pin, d1_pin, d2_pin, d3_pin) = self;
1256 1256
1257 cortex_m::interrupt::free(|_| unsafe { 1257 critical_section::with(|_| unsafe {
1258 // clk 1258 // clk
1259 let block = clk_pin.block(); 1259 let block = clk_pin.block();
1260 let n = clk_pin.pin() as usize; 1260 let n = clk_pin.pin() as usize;
@@ -1298,7 +1298,7 @@ where
1298 1298
1299 let (clk_pin, cmd_pin, d0_pin, d1_pin, d2_pin, d3_pin) = self; 1299 let (clk_pin, cmd_pin, d0_pin, d1_pin, d2_pin, d3_pin) = self;
1300 1300
1301 cortex_m::interrupt::free(|_| unsafe { 1301 critical_section::with(|_| unsafe {
1302 // clk 1302 // clk
1303 let n = clk_pin.pin().into(); 1303 let n = clk_pin.pin().into();
1304 clk_pin 1304 clk_pin
@@ -1400,7 +1400,7 @@ where
1400 fn configure(&mut self) { 1400 fn configure(&mut self) {
1401 let (clk_pin, cmd_pin, d0_pin) = self; 1401 let (clk_pin, cmd_pin, d0_pin) = self;
1402 1402
1403 cortex_m::interrupt::free(|_| unsafe { 1403 critical_section::with(|_| unsafe {
1404 // clk 1404 // clk
1405 let block = clk_pin.block(); 1405 let block = clk_pin.block();
1406 let n = clk_pin.pin() as usize; 1406 let n = clk_pin.pin() as usize;
@@ -1426,7 +1426,7 @@ where
1426 1426
1427 let (clk_pin, cmd_pin, d0_pin) = self; 1427 let (clk_pin, cmd_pin, d0_pin) = self;
1428 1428
1429 cortex_m::interrupt::free(|_| unsafe { 1429 critical_section::with(|_| unsafe {
1430 // clk 1430 // clk
1431 let n = clk_pin.pin().into(); 1431 let n = clk_pin.pin().into();
1432 clk_pin 1432 clk_pin
diff --git a/embassy-stm32/src/spi/mod.rs b/embassy-stm32/src/spi/mod.rs
index f83ef7852..f1ea8592d 100644
--- a/embassy-stm32/src/spi/mod.rs
+++ b/embassy-stm32/src/spi/mod.rs
@@ -1,5 +1,13 @@
1#![macro_use] 1#![macro_use]
2 2
3use core::future::Future;
4use core::marker::PhantomData;
5use core::ptr;
6use embassy::util::Unborrow;
7use embassy_hal_common::unborrow;
8use embassy_traits::spi as traits;
9
10use self::sealed::WordSize;
3use crate::dma; 11use crate::dma;
4use crate::dma::NoDma; 12use crate::dma::NoDma;
5use crate::gpio::sealed::{AFType, Pin}; 13use crate::gpio::sealed::{AFType, Pin};
@@ -8,19 +16,14 @@ use crate::pac::spi::{regs, vals};
8use crate::peripherals; 16use crate::peripherals;
9use crate::rcc::RccPeripheral; 17use crate::rcc::RccPeripheral;
10use crate::time::Hertz; 18use crate::time::Hertz;
11use core::future::Future; 19
12use core::marker::PhantomData; 20pub use embedded_hal::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3};
13use core::ptr;
14use embassy::util::Unborrow;
15use embassy_hal_common::unborrow;
16use embassy_traits::spi as traits;
17 21
18#[cfg_attr(spi_v1, path = "v1.rs")] 22#[cfg_attr(spi_v1, path = "v1.rs")]
19#[cfg_attr(spi_f1, path = "v1.rs")] 23#[cfg_attr(spi_f1, path = "v1.rs")]
20#[cfg_attr(spi_v2, path = "v2.rs")] 24#[cfg_attr(spi_v2, path = "v2.rs")]
21#[cfg_attr(spi_v3, path = "v3.rs")] 25#[cfg_attr(spi_v3, path = "v3.rs")]
22mod _version; 26mod _version;
23pub use _version::*;
24 27
25type Regs = &'static crate::pac::spi::Spi; 28type Regs = &'static crate::pac::spi::Spi;
26 29
@@ -40,54 +43,6 @@ pub enum BitOrder {
40 MsbFirst, 43 MsbFirst,
41} 44}
42 45
43#[derive(Copy, Clone, PartialOrd, PartialEq)]
44enum WordSize {
45 EightBit,
46 SixteenBit,
47}
48
49impl WordSize {
50 #[cfg(any(spi_v1, spi_f1))]
51 fn dff(&self) -> vals::Dff {
52 match self {
53 WordSize::EightBit => vals::Dff::EIGHTBIT,
54 WordSize::SixteenBit => vals::Dff::SIXTEENBIT,
55 }
56 }
57
58 #[cfg(spi_v2)]
59 fn ds(&self) -> vals::Ds {
60 match self {
61 WordSize::EightBit => vals::Ds::EIGHTBIT,
62 WordSize::SixteenBit => vals::Ds::SIXTEENBIT,
63 }
64 }
65
66 #[cfg(spi_v2)]
67 fn frxth(&self) -> vals::Frxth {
68 match self {
69 WordSize::EightBit => vals::Frxth::QUARTER,
70 WordSize::SixteenBit => vals::Frxth::HALF,
71 }
72 }
73
74 #[cfg(spi_v3)]
75 fn dsize(&self) -> u8 {
76 match self {
77 WordSize::EightBit => 0b0111,
78 WordSize::SixteenBit => 0b1111,
79 }
80 }
81
82 #[cfg(spi_v3)]
83 fn _frxth(&self) -> vals::Fthlv {
84 match self {
85 WordSize::EightBit => vals::Fthlv::ONEFRAME,
86 WordSize::SixteenBit => vals::Fthlv::ONEFRAME,
87 }
88 }
89}
90
91#[non_exhaustive] 46#[non_exhaustive]
92#[derive(Copy, Clone)] 47#[derive(Copy, Clone)]
93pub struct Config { 48pub struct Config {
@@ -379,6 +334,47 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
379 334
380 self.current_word_size = word_size; 335 self.current_word_size = word_size;
381 } 336 }
337
338 pub async fn write(&mut self, data: &[u8]) -> Result<(), Error>
339 where
340 Tx: TxDmaChannel<T>,
341 {
342 self.write_dma_u8(data).await
343 }
344
345 pub async fn read(&mut self, data: &mut [u8]) -> Result<(), Error>
346 where
347 Tx: TxDmaChannel<T>,
348 Rx: RxDmaChannel<T>,
349 {
350 self.read_dma_u8(data).await
351 }
352
353 pub async fn transfer(&mut self, read: &mut [u8], write: &[u8]) -> Result<(), Error>
354 where
355 Tx: TxDmaChannel<T>,
356 Rx: RxDmaChannel<T>,
357 {
358 self.transfer_dma_u8(read, write).await
359 }
360
361 pub fn blocking_write<W: Word>(&mut self, words: &[W]) -> Result<(), Error> {
362 self.set_word_size(W::WORDSIZE);
363 let regs = T::regs();
364 for word in words.iter() {
365 let _ = transfer_word(regs, *word)?;
366 }
367 Ok(())
368 }
369
370 pub fn blocking_transfer_in_place<W: Word>(&mut self, words: &mut [W]) -> Result<(), Error> {
371 self.set_word_size(W::WORDSIZE);
372 let regs = T::regs();
373 for word in words.iter_mut() {
374 *word = transfer_word(regs, *word)?;
375 }
376 Ok(())
377 }
382} 378}
383 379
384impl<'d, T: Instance, Tx, Rx> Drop for Spi<'d, T, Tx, Rx> { 380impl<'d, T: Instance, Tx, Rx> Drop for Spi<'d, T, Tx, Rx> {
@@ -537,17 +533,6 @@ fn finish_dma(regs: Regs) {
537 } 533 }
538} 534}
539 535
540trait Word {
541 const WORDSIZE: WordSize;
542}
543
544impl Word for u8 {
545 const WORDSIZE: WordSize = WordSize::EightBit;
546}
547impl Word for u16 {
548 const WORDSIZE: WordSize = WordSize::SixteenBit;
549}
550
551fn transfer_word<W: Word>(regs: Regs, tx_word: W) -> Result<W, Error> { 536fn transfer_word<W: Word>(regs: Regs, tx_word: W) -> Result<W, Error> {
552 spin_until_tx_ready(regs)?; 537 spin_until_tx_ready(regs)?;
553 538
@@ -572,14 +557,7 @@ macro_rules! impl_blocking {
572 type Error = Error; 557 type Error = Error;
573 558
574 fn write(&mut self, words: &[$w]) -> Result<(), Self::Error> { 559 fn write(&mut self, words: &[$w]) -> Result<(), Self::Error> {
575 self.set_word_size($w::WORDSIZE); 560 self.blocking_write(words)
576 let regs = T::regs();
577
578 for word in words.iter() {
579 let _ = transfer_word(regs, *word)?;
580 }
581
582 Ok(())
583 } 561 }
584 } 562 }
585 563
@@ -589,13 +567,7 @@ macro_rules! impl_blocking {
589 type Error = Error; 567 type Error = Error;
590 568
591 fn transfer<'w>(&mut self, words: &'w mut [$w]) -> Result<&'w [$w], Self::Error> { 569 fn transfer<'w>(&mut self, words: &'w mut [$w]) -> Result<&'w [$w], Self::Error> {
592 self.set_word_size($w::WORDSIZE); 570 self.blocking_transfer_in_place(words)?;
593 let regs = T::regs();
594
595 for word in words.iter_mut() {
596 *word = transfer_word(regs, *word)?;
597 }
598
599 Ok(words) 571 Ok(words)
600 } 572 }
601 } 573 }
@@ -616,7 +588,7 @@ impl<'d, T: Instance, Tx: TxDmaChannel<T>, Rx> traits::Write<u8> for Spi<'d, T,
616 = impl Future<Output = Result<(), Self::Error>> + 'a; 588 = impl Future<Output = Result<(), Self::Error>> + 'a;
617 589
618 fn write<'a>(&'a mut self, data: &'a [u8]) -> Self::WriteFuture<'a> { 590 fn write<'a>(&'a mut self, data: &'a [u8]) -> Self::WriteFuture<'a> {
619 self.write_dma_u8(data) 591 self.write(data)
620 } 592 }
621} 593}
622 594
@@ -629,7 +601,7 @@ impl<'d, T: Instance, Tx: TxDmaChannel<T>, Rx: RxDmaChannel<T>> traits::Read<u8>
629 = impl Future<Output = Result<(), Self::Error>> + 'a; 601 = impl Future<Output = Result<(), Self::Error>> + 'a;
630 602
631 fn read<'a>(&'a mut self, data: &'a mut [u8]) -> Self::ReadFuture<'a> { 603 fn read<'a>(&'a mut self, data: &'a mut [u8]) -> Self::ReadFuture<'a> {
632 self.read_dma_u8(data) 604 self.read(data)
633 } 605 }
634} 606}
635 607
@@ -646,7 +618,7 @@ impl<'d, T: Instance, Tx: TxDmaChannel<T>, Rx: RxDmaChannel<T>> traits::FullDupl
646 read: &'a mut [u8], 618 read: &'a mut [u8],
647 write: &'a [u8], 619 write: &'a [u8],
648 ) -> Self::WriteReadFuture<'a> { 620 ) -> Self::WriteReadFuture<'a> {
649 self.read_write_dma_u8(read, write) 621 self.transfer(read, write)
650 } 622 }
651} 623}
652 624
@@ -676,8 +648,72 @@ pub(crate) mod sealed {
676 pub trait RxDmaChannel<T: Instance> { 648 pub trait RxDmaChannel<T: Instance> {
677 fn request(&self) -> dma::Request; 649 fn request(&self) -> dma::Request;
678 } 650 }
651
652 pub trait Word: Copy + 'static {
653 const WORDSIZE: WordSize;
654 }
655
656 impl Word for u8 {
657 const WORDSIZE: WordSize = WordSize::EightBit;
658 }
659 impl Word for u16 {
660 const WORDSIZE: WordSize = WordSize::SixteenBit;
661 }
662
663 #[derive(Copy, Clone, PartialOrd, PartialEq)]
664 pub enum WordSize {
665 EightBit,
666 SixteenBit,
667 }
668
669 impl WordSize {
670 #[cfg(any(spi_v1, spi_f1))]
671 pub fn dff(&self) -> vals::Dff {
672 match self {
673 WordSize::EightBit => vals::Dff::EIGHTBIT,
674 WordSize::SixteenBit => vals::Dff::SIXTEENBIT,
675 }
676 }
677
678 #[cfg(spi_v2)]
679 pub fn ds(&self) -> vals::Ds {
680 match self {
681 WordSize::EightBit => vals::Ds::EIGHTBIT,
682 WordSize::SixteenBit => vals::Ds::SIXTEENBIT,
683 }
684 }
685
686 #[cfg(spi_v2)]
687 pub fn frxth(&self) -> vals::Frxth {
688 match self {
689 WordSize::EightBit => vals::Frxth::QUARTER,
690 WordSize::SixteenBit => vals::Frxth::HALF,
691 }
692 }
693
694 #[cfg(spi_v3)]
695 pub fn dsize(&self) -> u8 {
696 match self {
697 WordSize::EightBit => 0b0111,
698 WordSize::SixteenBit => 0b1111,
699 }
700 }
701
702 #[cfg(spi_v3)]
703 pub fn _frxth(&self) -> vals::Fthlv {
704 match self {
705 WordSize::EightBit => vals::Fthlv::ONEFRAME,
706 WordSize::SixteenBit => vals::Fthlv::ONEFRAME,
707 }
708 }
709 }
679} 710}
680 711
712pub trait Word: Copy + 'static + sealed::Word {}
713
714impl Word for u8 {}
715impl Word for u16 {}
716
681pub trait Instance: sealed::Instance + RccPeripheral {} 717pub trait Instance: sealed::Instance + RccPeripheral {}
682pub trait SckPin<T: Instance>: sealed::SckPin<T> {} 718pub trait SckPin<T: Instance>: sealed::SckPin<T> {}
683pub trait MosiPin<T: Instance>: sealed::MosiPin<T> {} 719pub trait MosiPin<T: Instance>: sealed::MosiPin<T> {}
diff --git a/embassy-stm32/src/spi/v1.rs b/embassy-stm32/src/spi/v1.rs
index ef7e0f59c..68e5a7348 100644
--- a/embassy-stm32/src/spi/v1.rs
+++ b/embassy-stm32/src/spi/v1.rs
@@ -1,13 +1,12 @@
1#![macro_use] 1#![macro_use]
2 2
3pub use embedded_hal::blocking;
4pub use embedded_hal::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3};
5use futures::future::join; 3use futures::future::join;
6 4
7use super::*; 5use super::*;
6use crate::dma::{slice_ptr_parts, slice_ptr_parts_mut, Transfer};
8 7
9impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { 8impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
10 pub(super) async fn write_dma_u8(&mut self, write: &[u8]) -> Result<(), Error> 9 pub(super) async fn write_dma_u8(&mut self, write: *const [u8]) -> Result<(), Error>
11 where 10 where
12 Tx: TxDmaChannel<T>, 11 Tx: TxDmaChannel<T>,
13 { 12 {
@@ -18,9 +17,10 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
18 } 17 }
19 self.set_word_size(WordSize::EightBit); 18 self.set_word_size(WordSize::EightBit);
20 19
21 let request = self.txdma.request(); 20 let tx_request = self.txdma.request();
22 let dst = T::regs().tx_ptr(); 21 let tx_dst = T::regs().tx_ptr();
23 let f = crate::dma::write(&mut self.txdma, request, write, dst); 22 unsafe { self.txdma.start_write(tx_request, write, tx_dst) }
23 let tx_f = Transfer::new(&mut self.txdma);
24 24
25 unsafe { 25 unsafe {
26 T::regs().cr2().modify(|reg| { 26 T::regs().cr2().modify(|reg| {
@@ -31,14 +31,14 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
31 }); 31 });
32 } 32 }
33 33
34 f.await; 34 tx_f.await;
35 35
36 finish_dma(T::regs()); 36 finish_dma(T::regs());
37 37
38 Ok(()) 38 Ok(())
39 } 39 }
40 40
41 pub(super) async fn read_dma_u8(&mut self, read: &mut [u8]) -> Result<(), Error> 41 pub(super) async fn read_dma_u8(&mut self, read: *mut [u8]) -> Result<(), Error>
42 where 42 where
43 Tx: TxDmaChannel<T>, 43 Tx: TxDmaChannel<T>,
44 Rx: RxDmaChannel<T>, 44 Rx: RxDmaChannel<T>,
@@ -53,11 +53,12 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
53 } 53 }
54 self.set_word_size(WordSize::EightBit); 54 self.set_word_size(WordSize::EightBit);
55 55
56 let clock_byte_count = read.len(); 56 let (_, clock_byte_count) = slice_ptr_parts_mut(read);
57 57
58 let rx_request = self.rxdma.request(); 58 let rx_request = self.rxdma.request();
59 let rx_src = T::regs().rx_ptr(); 59 let rx_src = T::regs().rx_ptr();
60 let rx_f = crate::dma::read(&mut self.rxdma, rx_request, rx_src, read); 60 unsafe { self.rxdma.start_read(rx_request, rx_src, read) };
61 let rx_f = Transfer::new(&mut self.rxdma);
61 62
62 let tx_request = self.txdma.request(); 63 let tx_request = self.txdma.request();
63 let tx_dst = T::regs().tx_ptr(); 64 let tx_dst = T::regs().tx_ptr();
@@ -86,16 +87,18 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
86 Ok(()) 87 Ok(())
87 } 88 }
88 89
89 pub(super) async fn read_write_dma_u8( 90 pub(super) async fn transfer_dma_u8(
90 &mut self, 91 &mut self,
91 read: &mut [u8], 92 read: *mut [u8],
92 write: &[u8], 93 write: *const [u8],
93 ) -> Result<(), Error> 94 ) -> Result<(), Error>
94 where 95 where
95 Tx: TxDmaChannel<T>, 96 Tx: TxDmaChannel<T>,
96 Rx: RxDmaChannel<T>, 97 Rx: RxDmaChannel<T>,
97 { 98 {
98 assert!(read.len() >= write.len()); 99 let (_, rx_len) = slice_ptr_parts(read);
100 let (_, tx_len) = slice_ptr_parts(write);
101 assert_eq!(rx_len, tx_len);
99 102
100 unsafe { 103 unsafe {
101 T::regs().cr1().modify(|w| { 104 T::regs().cr1().modify(|w| {
@@ -109,16 +112,13 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
109 112
110 let rx_request = self.rxdma.request(); 113 let rx_request = self.rxdma.request();
111 let rx_src = T::regs().rx_ptr(); 114 let rx_src = T::regs().rx_ptr();
112 let rx_f = crate::dma::read( 115 unsafe { self.rxdma.start_read(rx_request, rx_src, read) };
113 &mut self.rxdma, 116 let rx_f = Transfer::new(&mut self.rxdma);
114 rx_request,
115 rx_src,
116 &mut read[0..write.len()],
117 );
118 117
119 let tx_request = self.txdma.request(); 118 let tx_request = self.txdma.request();
120 let tx_dst = T::regs().tx_ptr(); 119 let tx_dst = T::regs().tx_ptr();
121 let tx_f = crate::dma::write(&mut self.txdma, tx_request, write, tx_dst); 120 unsafe { self.txdma.start_write(tx_request, write, tx_dst) }
121 let tx_f = Transfer::new(&mut self.txdma);
122 122
123 unsafe { 123 unsafe {
124 T::regs().cr2().modify(|reg| { 124 T::regs().cr2().modify(|reg| {
diff --git a/embassy-stm32/src/spi/v2.rs b/embassy-stm32/src/spi/v2.rs
index f2ba3ac67..78bb1192b 100644
--- a/embassy-stm32/src/spi/v2.rs
+++ b/embassy-stm32/src/spi/v2.rs
@@ -1,12 +1,12 @@
1#![macro_use] 1#![macro_use]
2 2
3pub use embedded_hal::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3};
4use futures::future::join; 3use futures::future::join;
5 4
6use super::*; 5use super::*;
6use crate::dma::{slice_ptr_parts, slice_ptr_parts_mut, Transfer};
7 7
8impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { 8impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
9 pub(super) async fn write_dma_u8(&mut self, write: &[u8]) -> Result<(), Error> 9 pub(super) async fn write_dma_u8(&mut self, write: *const [u8]) -> Result<(), Error>
10 where 10 where
11 Tx: TxDmaChannel<T>, 11 Tx: TxDmaChannel<T>,
12 { 12 {
@@ -22,9 +22,10 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
22 } 22 }
23 self.set_word_size(WordSize::EightBit); 23 self.set_word_size(WordSize::EightBit);
24 24
25 let request = self.txdma.request(); 25 let tx_request = self.txdma.request();
26 let dst = T::regs().tx_ptr(); 26 let tx_dst = T::regs().tx_ptr();
27 let f = crate::dma::write(&mut self.txdma, request, write, dst); 27 unsafe { self.txdma.start_write(tx_request, write, tx_dst) }
28 let tx_f = Transfer::new(&mut self.txdma);
28 29
29 unsafe { 30 unsafe {
30 T::regs().cr2().modify(|reg| { 31 T::regs().cr2().modify(|reg| {
@@ -35,14 +36,14 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
35 }); 36 });
36 } 37 }
37 38
38 f.await; 39 tx_f.await;
39 40
40 finish_dma(T::regs()); 41 finish_dma(T::regs());
41 42
42 Ok(()) 43 Ok(())
43 } 44 }
44 45
45 pub(super) async fn read_dma_u8(&mut self, read: &mut [u8]) -> Result<(), Error> 46 pub(super) async fn read_dma_u8(&mut self, read: *mut [u8]) -> Result<(), Error>
46 where 47 where
47 Tx: TxDmaChannel<T>, 48 Tx: TxDmaChannel<T>,
48 Rx: RxDmaChannel<T>, 49 Rx: RxDmaChannel<T>,
@@ -57,11 +58,12 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
57 } 58 }
58 self.set_word_size(WordSize::EightBit); 59 self.set_word_size(WordSize::EightBit);
59 60
60 let clock_byte_count = read.len(); 61 let (_, clock_byte_count) = slice_ptr_parts_mut(read);
61 62
62 let rx_request = self.rxdma.request(); 63 let rx_request = self.rxdma.request();
63 let rx_src = T::regs().rx_ptr(); 64 let rx_src = T::regs().rx_ptr();
64 let rx_f = crate::dma::read(&mut self.rxdma, rx_request, rx_src, read); 65 unsafe { self.rxdma.start_read(rx_request, rx_src, read) };
66 let rx_f = Transfer::new(&mut self.rxdma);
65 67
66 let tx_request = self.txdma.request(); 68 let tx_request = self.txdma.request();
67 let tx_dst = T::regs().tx_ptr(); 69 let tx_dst = T::regs().tx_ptr();
@@ -90,16 +92,18 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
90 Ok(()) 92 Ok(())
91 } 93 }
92 94
93 pub(super) async fn read_write_dma_u8( 95 pub(super) async fn transfer_dma_u8(
94 &mut self, 96 &mut self,
95 read: &mut [u8], 97 read: *mut [u8],
96 write: &[u8], 98 write: *const [u8],
97 ) -> Result<(), Error> 99 ) -> Result<(), Error>
98 where 100 where
99 Tx: TxDmaChannel<T>, 101 Tx: TxDmaChannel<T>,
100 Rx: RxDmaChannel<T>, 102 Rx: RxDmaChannel<T>,
101 { 103 {
102 assert!(read.len() >= write.len()); 104 let (_, rx_len) = slice_ptr_parts(read);
105 let (_, tx_len) = slice_ptr_parts(write);
106 assert_eq!(rx_len, tx_len);
103 107
104 unsafe { 108 unsafe {
105 T::regs().cr1().modify(|w| { 109 T::regs().cr1().modify(|w| {
@@ -118,16 +122,13 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
118 122
119 let rx_request = self.rxdma.request(); 123 let rx_request = self.rxdma.request();
120 let rx_src = T::regs().rx_ptr(); 124 let rx_src = T::regs().rx_ptr();
121 let rx_f = crate::dma::read( 125 unsafe { self.rxdma.start_read(rx_request, rx_src, read) };
122 &mut self.rxdma, 126 let rx_f = Transfer::new(&mut self.rxdma);
123 rx_request,
124 rx_src,
125 &mut read[0..write.len()],
126 );
127 127
128 let tx_request = self.txdma.request(); 128 let tx_request = self.txdma.request();
129 let tx_dst = T::regs().tx_ptr(); 129 let tx_dst = T::regs().tx_ptr();
130 let tx_f = crate::dma::write(&mut self.txdma, tx_request, write, tx_dst); 130 unsafe { self.txdma.start_write(tx_request, write, tx_dst) }
131 let tx_f = Transfer::new(&mut self.txdma);
131 132
132 unsafe { 133 unsafe {
133 T::regs().cr2().modify(|reg| { 134 T::regs().cr2().modify(|reg| {
diff --git a/embassy-stm32/src/spi/v3.rs b/embassy-stm32/src/spi/v3.rs
index b42eeed89..50650da1b 100644
--- a/embassy-stm32/src/spi/v3.rs
+++ b/embassy-stm32/src/spi/v3.rs
@@ -1,12 +1,12 @@
1#![macro_use] 1#![macro_use]
2 2
3pub use embedded_hal::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3};
4use futures::future::join; 3use futures::future::join;
5 4
6use super::*; 5use super::*;
6use crate::dma::{slice_ptr_parts, slice_ptr_parts_mut, Transfer};
7 7
8impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { 8impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
9 pub(super) async fn write_dma_u8(&mut self, write: &[u8]) -> Result<(), Error> 9 pub(super) async fn write_dma_u8(&mut self, write: *const [u8]) -> Result<(), Error>
10 where 10 where
11 Tx: TxDmaChannel<T>, 11 Tx: TxDmaChannel<T>,
12 { 12 {
@@ -22,9 +22,10 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
22 } 22 }
23 } 23 }
24 24
25 let request = self.txdma.request(); 25 let tx_request = self.txdma.request();
26 let dst = T::regs().tx_ptr(); 26 let tx_dst = T::regs().tx_ptr();
27 let f = crate::dma::write(&mut self.txdma, request, write, dst); 27 unsafe { self.txdma.start_write(tx_request, write, tx_dst) }
28 let tx_f = Transfer::new(&mut self.txdma);
28 29
29 unsafe { 30 unsafe {
30 T::regs().cfg1().modify(|reg| { 31 T::regs().cfg1().modify(|reg| {
@@ -38,14 +39,14 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
38 }); 39 });
39 } 40 }
40 41
41 f.await; 42 tx_f.await;
42 43
43 finish_dma(T::regs()); 44 finish_dma(T::regs());
44 45
45 Ok(()) 46 Ok(())
46 } 47 }
47 48
48 pub(super) async fn read_dma_u8(&mut self, read: &mut [u8]) -> Result<(), Error> 49 pub(super) async fn read_dma_u8(&mut self, read: *mut [u8]) -> Result<(), Error>
49 where 50 where
50 Tx: TxDmaChannel<T>, 51 Tx: TxDmaChannel<T>,
51 Rx: RxDmaChannel<T>, 52 Rx: RxDmaChannel<T>,
@@ -60,11 +61,12 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
60 }); 61 });
61 } 62 }
62 63
63 let clock_byte_count = read.len(); 64 let (_, clock_byte_count) = slice_ptr_parts_mut(read);
64 65
65 let rx_request = self.rxdma.request(); 66 let rx_request = self.rxdma.request();
66 let rx_src = T::regs().rx_ptr(); 67 let rx_src = T::regs().rx_ptr();
67 let rx_f = crate::dma::read(&mut self.rxdma, rx_request, rx_src, read); 68 unsafe { self.rxdma.start_read(rx_request, rx_src, read) };
69 let rx_f = Transfer::new(&mut self.rxdma);
68 70
69 let tx_request = self.txdma.request(); 71 let tx_request = self.txdma.request();
70 let tx_dst = T::regs().tx_ptr(); 72 let tx_dst = T::regs().tx_ptr();
@@ -96,16 +98,18 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
96 Ok(()) 98 Ok(())
97 } 99 }
98 100
99 pub(super) async fn read_write_dma_u8( 101 pub(super) async fn transfer_dma_u8(
100 &mut self, 102 &mut self,
101 read: &mut [u8], 103 read: *mut [u8],
102 write: &[u8], 104 write: *const [u8],
103 ) -> Result<(), Error> 105 ) -> Result<(), Error>
104 where 106 where
105 Tx: TxDmaChannel<T>, 107 Tx: TxDmaChannel<T>,
106 Rx: RxDmaChannel<T>, 108 Rx: RxDmaChannel<T>,
107 { 109 {
108 assert!(read.len() >= write.len()); 110 let (_, rx_len) = slice_ptr_parts(read);
111 let (_, tx_len) = slice_ptr_parts(write);
112 assert_eq!(rx_len, tx_len);
109 113
110 self.set_word_size(WordSize::EightBit); 114 self.set_word_size(WordSize::EightBit);
111 unsafe { 115 unsafe {
@@ -124,16 +128,13 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
124 128
125 let rx_request = self.rxdma.request(); 129 let rx_request = self.rxdma.request();
126 let rx_src = T::regs().rx_ptr(); 130 let rx_src = T::regs().rx_ptr();
127 let rx_f = crate::dma::read( 131 unsafe { self.rxdma.start_read(rx_request, rx_src, read) };
128 &mut self.rxdma, 132 let rx_f = Transfer::new(&mut self.rxdma);
129 rx_request,
130 rx_src,
131 &mut read[0..write.len()],
132 );
133 133
134 let tx_request = self.txdma.request(); 134 let tx_request = self.txdma.request();
135 let tx_dst = T::regs().tx_ptr(); 135 let tx_dst = T::regs().tx_ptr();
136 let tx_f = crate::dma::write(&mut self.txdma, tx_request, write, tx_dst); 136 unsafe { self.txdma.start_write(tx_request, write, tx_dst) }
137 let tx_f = Transfer::new(&mut self.txdma);
137 138
138 unsafe { 139 unsafe {
139 T::regs().cfg1().modify(|reg| { 140 T::regs().cfg1().modify(|reg| {
diff --git a/embassy-stm32/src/subghz/mod.rs b/embassy-stm32/src/subghz/mod.rs
index 7d74569f3..87f376c40 100644
--- a/embassy-stm32/src/subghz/mod.rs
+++ b/embassy-stm32/src/subghz/mod.rs
@@ -82,14 +82,10 @@ use crate::{
82 pac, 82 pac,
83 peripherals::SUBGHZSPI, 83 peripherals::SUBGHZSPI,
84 rcc::sealed::RccPeripheral, 84 rcc::sealed::RccPeripheral,
85 spi::{BitOrder, Config as SpiConfig, MisoPin, MosiPin, SckPin, Spi}, 85 spi::{BitOrder, Config as SpiConfig, MisoPin, MosiPin, SckPin, Spi, MODE_0},
86 time::Hertz, 86 time::Hertz,
87}; 87};
88use embassy::util::Unborrow; 88use embassy::util::Unborrow;
89use embedded_hal::{
90 blocking::spi::{Transfer, Write},
91 spi::MODE_0,
92};
93 89
94/// Passthrough for SPI errors (for now) 90/// Passthrough for SPI errors (for now)
95pub type Error = crate::spi::Error; 91pub type Error = crate::spi::Error;
@@ -255,8 +251,8 @@ impl<'d> SubGhz<'d, NoDma, NoDma> {
255 self.poll_not_busy(); 251 self.poll_not_busy();
256 { 252 {
257 let _nss: Nss = Nss::new(); 253 let _nss: Nss = Nss::new();
258 self.spi.write(&[opcode as u8])?; 254 self.spi.blocking_write(&[opcode as u8])?;
259 self.spi.transfer(data)?; 255 self.spi.blocking_transfer_in_place(data)?;
260 } 256 }
261 self.poll_not_busy(); 257 self.poll_not_busy();
262 Ok(()) 258 Ok(())
@@ -280,7 +276,7 @@ impl<'d> SubGhz<'d, NoDma, NoDma> {
280 self.poll_not_busy(); 276 self.poll_not_busy();
281 { 277 {
282 let _nss: Nss = Nss::new(); 278 let _nss: Nss = Nss::new();
283 self.spi.write(data)?; 279 self.spi.blocking_write(data)?;
284 } 280 }
285 self.poll_not_busy(); 281 self.poll_not_busy();
286 Ok(()) 282 Ok(())
@@ -290,8 +286,9 @@ impl<'d> SubGhz<'d, NoDma, NoDma> {
290 self.poll_not_busy(); 286 self.poll_not_busy();
291 { 287 {
292 let _nss: Nss = Nss::new(); 288 let _nss: Nss = Nss::new();
293 self.spi.write(&[OpCode::WriteBuffer as u8, offset])?; 289 self.spi
294 self.spi.write(data)?; 290 .blocking_write(&[OpCode::WriteBuffer as u8, offset])?;
291 self.spi.blocking_write(data)?;
295 } 292 }
296 self.poll_not_busy(); 293 self.poll_not_busy();
297 294
@@ -308,9 +305,10 @@ impl<'d> SubGhz<'d, NoDma, NoDma> {
308 self.poll_not_busy(); 305 self.poll_not_busy();
309 { 306 {
310 let _nss: Nss = Nss::new(); 307 let _nss: Nss = Nss::new();
311 self.spi.write(&[OpCode::ReadBuffer as u8, offset])?; 308 self.spi
312 self.spi.transfer(&mut status_buf)?; 309 .blocking_write(&[OpCode::ReadBuffer as u8, offset])?;
313 self.spi.transfer(buf)?; 310 self.spi.blocking_transfer_in_place(&mut status_buf)?;
311 self.spi.blocking_transfer_in_place(buf)?;
314 } 312 }
315 self.poll_not_busy(); 313 self.poll_not_busy();
316 314
@@ -342,8 +340,8 @@ impl<'d> SubGhz<'d, NoDma, NoDma> {
342 { 340 {
343 let _nss: Nss = Nss::new(); 341 let _nss: Nss = Nss::new();
344 self.spi 342 self.spi
345 .write(&[OpCode::WriteRegister as u8, addr[0], addr[1]])?; 343 .blocking_write(&[OpCode::WriteRegister as u8, addr[0], addr[1]])?;
346 self.spi.write(data)?; 344 self.spi.blocking_write(data)?;
347 } 345 }
348 self.poll_not_busy(); 346 self.poll_not_busy();
349 347
diff --git a/embassy-stm32/src/usart/mod.rs b/embassy-stm32/src/usart/mod.rs
index e46e14eec..5309c6296 100644
--- a/embassy-stm32/src/usart/mod.rs
+++ b/embassy-stm32/src/usart/mod.rs
@@ -129,7 +129,7 @@ impl<'d, T: Instance, TxDma, RxDma> Uart<'d, T, TxDma, RxDma> {
129 } 129 }
130 } 130 }
131 131
132 async fn write_dma(&mut self, buffer: &[u8]) -> Result<(), Error> 132 pub async fn write(&mut self, buffer: &[u8]) -> Result<(), Error>
133 where 133 where
134 TxDma: crate::usart::TxDma<T>, 134 TxDma: crate::usart::TxDma<T>,
135 { 135 {
@@ -146,7 +146,7 @@ impl<'d, T: Instance, TxDma, RxDma> Uart<'d, T, TxDma, RxDma> {
146 Ok(()) 146 Ok(())
147 } 147 }
148 148
149 async fn read_dma(&mut self, buffer: &mut [u8]) -> Result<(), Error> 149 pub async fn read(&mut self, buffer: &mut [u8]) -> Result<(), Error>
150 where 150 where
151 RxDma: crate::usart::RxDma<T>, 151 RxDma: crate::usart::RxDma<T>,
152 { 152 {
@@ -163,7 +163,7 @@ impl<'d, T: Instance, TxDma, RxDma> Uart<'d, T, TxDma, RxDma> {
163 Ok(()) 163 Ok(())
164 } 164 }
165 165
166 pub fn read_blocking(&mut self, buffer: &mut [u8]) -> Result<(), Error> { 166 pub fn blocking_read(&mut self, buffer: &mut [u8]) -> Result<(), Error> {
167 unsafe { 167 unsafe {
168 let r = self.inner.regs(); 168 let r = self.inner.regs();
169 for b in buffer { 169 for b in buffer {
@@ -190,6 +190,25 @@ impl<'d, T: Instance, TxDma, RxDma> Uart<'d, T, TxDma, RxDma> {
190 } 190 }
191 Ok(()) 191 Ok(())
192 } 192 }
193
194 pub fn blocking_write(&mut self, buffer: &[u8]) -> Result<(), Error> {
195 unsafe {
196 let r = self.inner.regs();
197 for &b in buffer {
198 while !sr(r).read().txe() {}
199 tdr(r).write_volatile(b);
200 }
201 }
202 Ok(())
203 }
204
205 pub fn blocking_flush(&mut self) -> Result<(), Error> {
206 unsafe {
207 let r = self.inner.regs();
208 while !sr(r).read().tc() {}
209 }
210 Ok(())
211 }
193} 212}
194 213
195impl<'d, T: Instance, TxDma, RxDma> embedded_hal::serial::Read<u8> for Uart<'d, T, TxDma, RxDma> { 214impl<'d, T: Instance, TxDma, RxDma> embedded_hal::serial::Read<u8> for Uart<'d, T, TxDma, RxDma> {
@@ -224,21 +243,10 @@ impl<'d, T: Instance, TxDma, RxDma> embedded_hal::blocking::serial::Write<u8>
224{ 243{
225 type Error = Error; 244 type Error = Error;
226 fn bwrite_all(&mut self, buffer: &[u8]) -> Result<(), Self::Error> { 245 fn bwrite_all(&mut self, buffer: &[u8]) -> Result<(), Self::Error> {
227 unsafe { 246 self.blocking_write(buffer)
228 let r = self.inner.regs();
229 for &b in buffer {
230 while !sr(r).read().txe() {}
231 tdr(r).write_volatile(b);
232 }
233 }
234 Ok(())
235 } 247 }
236 fn bflush(&mut self) -> Result<(), Self::Error> { 248 fn bflush(&mut self) -> Result<(), Self::Error> {
237 unsafe { 249 self.blocking_flush()
238 let r = self.inner.regs();
239 while !sr(r).read().tc() {}
240 }
241 Ok(())
242 } 250 }
243} 251}
244 252
@@ -252,7 +260,7 @@ where
252 = impl Future<Output = Result<(), embassy_traits::uart::Error>> + 'a; 260 = impl Future<Output = Result<(), embassy_traits::uart::Error>> + 'a;
253 261
254 fn write<'a>(&'a mut self, buf: &'a [u8]) -> Self::WriteFuture<'a> { 262 fn write<'a>(&'a mut self, buf: &'a [u8]) -> Self::WriteFuture<'a> {
255 self.write_dma(buf) 263 self.write(buf)
256 .map_err(|_| embassy_traits::uart::Error::Other) 264 .map_err(|_| embassy_traits::uart::Error::Other)
257 } 265 }
258} 266}
@@ -267,7 +275,7 @@ where
267 = impl Future<Output = Result<(), embassy_traits::uart::Error>> + 'a; 275 = impl Future<Output = Result<(), embassy_traits::uart::Error>> + 'a;
268 276
269 fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Self::ReadFuture<'a> { 277 fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Self::ReadFuture<'a> {
270 self.read_dma(buf) 278 self.read(buf)
271 .map_err(|_| embassy_traits::uart::Error::Other) 279 .map_err(|_| embassy_traits::uart::Error::Other)
272 } 280 }
273} 281}
diff --git a/examples/stm32f1/src/bin/blinky.rs b/examples/stm32f1/src/bin/blinky.rs
index 1e4f2deec..0d9537453 100644
--- a/examples/stm32f1/src/bin/blinky.rs
+++ b/examples/stm32f1/src/bin/blinky.rs
@@ -8,7 +8,6 @@ use embassy::executor::Spawner;
8use embassy::time::{Duration, Timer}; 8use embassy::time::{Duration, Timer};
9use embassy_stm32::gpio::{Level, Output, Speed}; 9use embassy_stm32::gpio::{Level, Output, Speed};
10use embassy_stm32::Peripherals; 10use embassy_stm32::Peripherals;
11use embedded_hal::digital::v2::OutputPin;
12use example_common::*; 11use example_common::*;
13 12
14#[embassy::main] 13#[embassy::main]
@@ -19,11 +18,11 @@ async fn main(_spawner: Spawner, p: Peripherals) {
19 18
20 loop { 19 loop {
21 info!("high"); 20 info!("high");
22 unwrap!(led.set_high()); 21 led.set_high();
23 Timer::after(Duration::from_millis(300)).await; 22 Timer::after(Duration::from_millis(300)).await;
24 23
25 info!("low"); 24 info!("low");
26 unwrap!(led.set_low()); 25 led.set_low();
27 Timer::after(Duration::from_millis(300)).await; 26 Timer::after(Duration::from_millis(300)).await;
28 } 27 }
29} 28}
diff --git a/examples/stm32f3/src/bin/blinky.rs b/examples/stm32f3/src/bin/blinky.rs
index 321643557..e8b8dc23f 100644
--- a/examples/stm32f3/src/bin/blinky.rs
+++ b/examples/stm32f3/src/bin/blinky.rs
@@ -9,7 +9,6 @@ use embassy::executor::Spawner;
9use embassy::time::{Duration, Timer}; 9use embassy::time::{Duration, Timer};
10use embassy_stm32::gpio::{Level, Output, Speed}; 10use embassy_stm32::gpio::{Level, Output, Speed};
11use embassy_stm32::Peripherals; 11use embassy_stm32::Peripherals;
12use embedded_hal::digital::v2::OutputPin;
13use example_common::*; 12use example_common::*;
14 13
15#[embassy::main] 14#[embassy::main]
@@ -20,11 +19,11 @@ async fn main(_spawner: Spawner, p: Peripherals) {
20 19
21 loop { 20 loop {
22 info!("high"); 21 info!("high");
23 unwrap!(led.set_high()); 22 led.set_high();
24 Timer::after(Duration::from_millis(1000)).await; 23 Timer::after(Duration::from_millis(1000)).await;
25 24
26 info!("low"); 25 info!("low");
27 unwrap!(led.set_low()); 26 led.set_low();
28 Timer::after(Duration::from_millis(1000)).await; 27 Timer::after(Duration::from_millis(1000)).await;
29 } 28 }
30} 29}
diff --git a/examples/stm32f3/src/bin/button.rs b/examples/stm32f3/src/bin/button.rs
index c5fab138b..131d4af42 100644
--- a/examples/stm32f3/src/bin/button.rs
+++ b/examples/stm32f3/src/bin/button.rs
@@ -6,7 +6,6 @@
6mod example_common; 6mod example_common;
7use cortex_m_rt::entry; 7use cortex_m_rt::entry;
8use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; 8use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
9use embedded_hal::digital::v2::{InputPin, OutputPin};
10use example_common::*; 9use example_common::*;
11 10
12#[entry] 11#[entry]
@@ -20,14 +19,14 @@ fn main() -> ! {
20 let mut led2 = Output::new(p.PE15, Level::High, Speed::Low); 19 let mut led2 = Output::new(p.PE15, Level::High, Speed::Low);
21 20
22 loop { 21 loop {
23 if unwrap!(button.is_high()) { 22 if button.is_high() {
24 info!("high"); 23 info!("high");
25 unwrap!(led1.set_high()); 24 led1.set_high();
26 unwrap!(led2.set_low()); 25 led2.set_low();
27 } else { 26 } else {
28 info!("low"); 27 info!("low");
29 unwrap!(led1.set_low()); 28 led1.set_low();
30 unwrap!(led2.set_high()); 29 led2.set_high();
31 } 30 }
32 } 31 }
33} 32}
diff --git a/examples/stm32f3/src/bin/button_exti.rs b/examples/stm32f3/src/bin/button_exti.rs
index d45e4365b..b11f38ea5 100644
--- a/examples/stm32f3/src/bin/button_exti.rs
+++ b/examples/stm32f3/src/bin/button_exti.rs
@@ -8,7 +8,6 @@ use embassy::executor::Spawner;
8use embassy_stm32::exti::ExtiInput; 8use embassy_stm32::exti::ExtiInput;
9use embassy_stm32::gpio::{Input, Pull}; 9use embassy_stm32::gpio::{Input, Pull};
10use embassy_stm32::Peripherals; 10use embassy_stm32::Peripherals;
11use embassy_traits::gpio::{WaitForFallingEdge, WaitForRisingEdge};
12use example_common::*; 11use example_common::*;
13 12
14#[embassy::main] 13#[embassy::main]
diff --git a/examples/stm32f3/src/bin/usart_dma.rs b/examples/stm32f3/src/bin/usart_dma.rs
index 99530b5c0..0e67bb1f1 100644
--- a/examples/stm32f3/src/bin/usart_dma.rs
+++ b/examples/stm32f3/src/bin/usart_dma.rs
@@ -9,7 +9,6 @@ use embassy::executor::Spawner;
9use embassy_stm32::dma::NoDma; 9use embassy_stm32::dma::NoDma;
10use embassy_stm32::usart::{Config, Uart}; 10use embassy_stm32::usart::{Config, Uart};
11use embassy_stm32::Peripherals; 11use embassy_stm32::Peripherals;
12use embassy_traits::uart::Write as _;
13use example_common::*; 12use example_common::*;
14use heapless::String; 13use heapless::String;
15 14
diff --git a/examples/stm32f4/src/bin/blinky.rs b/examples/stm32f4/src/bin/blinky.rs
index c4857195f..00d67dac0 100644
--- a/examples/stm32f4/src/bin/blinky.rs
+++ b/examples/stm32f4/src/bin/blinky.rs
@@ -8,7 +8,6 @@ use embassy::executor::Spawner;
8use embassy::time::{Duration, Timer}; 8use embassy::time::{Duration, Timer};
9use embassy_stm32::gpio::{Level, Output, Speed}; 9use embassy_stm32::gpio::{Level, Output, Speed};
10use embassy_stm32::Peripherals; 10use embassy_stm32::Peripherals;
11use embedded_hal::digital::v2::OutputPin;
12use example_common::*; 11use example_common::*;
13 12
14#[embassy::main] 13#[embassy::main]
@@ -19,11 +18,11 @@ async fn main(_spawner: Spawner, p: Peripherals) {
19 18
20 loop { 19 loop {
21 info!("high"); 20 info!("high");
22 unwrap!(led.set_high()); 21 led.set_high();
23 Timer::after(Duration::from_millis(300)).await; 22 Timer::after(Duration::from_millis(300)).await;
24 23
25 info!("low"); 24 info!("low");
26 unwrap!(led.set_low()); 25 led.set_low();
27 Timer::after(Duration::from_millis(300)).await; 26 Timer::after(Duration::from_millis(300)).await;
28 } 27 }
29} 28}
diff --git a/examples/stm32f4/src/bin/button.rs b/examples/stm32f4/src/bin/button.rs
index 95dee7c74..24eef75b2 100644
--- a/examples/stm32f4/src/bin/button.rs
+++ b/examples/stm32f4/src/bin/button.rs
@@ -6,7 +6,6 @@
6mod example_common; 6mod example_common;
7use cortex_m_rt::entry; 7use cortex_m_rt::entry;
8use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; 8use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
9use embedded_hal::digital::v2::{InputPin, OutputPin};
10use example_common::*; 9use example_common::*;
11 10
12#[entry] 11#[entry]
@@ -21,14 +20,14 @@ fn main() -> ! {
21 let mut led3 = Output::new(p.PB14, Level::High, Speed::Low); 20 let mut led3 = Output::new(p.PB14, Level::High, Speed::Low);
22 21
23 loop { 22 loop {
24 if unwrap!(button.is_high()) { 23 if button.is_high() {
25 info!("high"); 24 info!("high");
26 unwrap!(led1.set_high()); 25 led1.set_high();
27 unwrap!(led3.set_low()); 26 led3.set_low();
28 } else { 27 } else {
29 info!("low"); 28 info!("low");
30 unwrap!(led1.set_low()); 29 led1.set_low();
31 unwrap!(led3.set_high()); 30 led3.set_high();
32 } 31 }
33 } 32 }
34} 33}
diff --git a/examples/stm32f4/src/bin/button_exti.rs b/examples/stm32f4/src/bin/button_exti.rs
index 2c4318d64..852fbe3c6 100644
--- a/examples/stm32f4/src/bin/button_exti.rs
+++ b/examples/stm32f4/src/bin/button_exti.rs
@@ -8,7 +8,6 @@ use embassy::executor::Spawner;
8use embassy_stm32::exti::ExtiInput; 8use embassy_stm32::exti::ExtiInput;
9use embassy_stm32::gpio::{Input, Pull}; 9use embassy_stm32::gpio::{Input, Pull};
10use embassy_stm32::Peripherals; 10use embassy_stm32::Peripherals;
11use embassy_traits::gpio::{WaitForFallingEdge, WaitForRisingEdge};
12use example_common::*; 11use example_common::*;
13 12
14#[embassy::main] 13#[embassy::main]
diff --git a/examples/stm32f4/src/bin/spi.rs b/examples/stm32f4/src/bin/spi.rs
index 0192e1865..6b04f1fed 100644
--- a/examples/stm32f4/src/bin/spi.rs
+++ b/examples/stm32f4/src/bin/spi.rs
@@ -10,8 +10,6 @@ use embassy_stm32::dma::NoDma;
10use embassy_stm32::gpio::{Level, Output, Speed}; 10use embassy_stm32::gpio::{Level, Output, Speed};
11use embassy_stm32::spi::{Config, Spi}; 11use embassy_stm32::spi::{Config, Spi};
12use embassy_stm32::time::Hertz; 12use embassy_stm32::time::Hertz;
13use embedded_hal::blocking::spi::Transfer;
14use embedded_hal::digital::v2::OutputPin;
15use example_common::*; 13use example_common::*;
16 14
17#[entry] 15#[entry]
@@ -35,9 +33,9 @@ fn main() -> ! {
35 33
36 loop { 34 loop {
37 let mut buf = [0x0Au8; 4]; 35 let mut buf = [0x0Au8; 4];
38 unwrap!(cs.set_low()); 36 cs.set_low();
39 unwrap!(spi.transfer(&mut buf)); 37 unwrap!(spi.blocking_transfer_in_place(&mut buf));
40 unwrap!(cs.set_high()); 38 cs.set_high();
41 info!("xfer {=[u8]:x}", buf); 39 info!("xfer {=[u8]:x}", buf);
42 } 40 }
43} 41}
diff --git a/examples/stm32f4/src/bin/spi_dma.rs b/examples/stm32f4/src/bin/spi_dma.rs
index b3bf6fc28..9171f7516 100644
--- a/examples/stm32f4/src/bin/spi_dma.rs
+++ b/examples/stm32f4/src/bin/spi_dma.rs
@@ -10,7 +10,6 @@ use embassy::executor::Spawner;
10use embassy_stm32::spi::{Config, Spi}; 10use embassy_stm32::spi::{Config, Spi};
11use embassy_stm32::time::Hertz; 11use embassy_stm32::time::Hertz;
12use embassy_stm32::Peripherals; 12use embassy_stm32::Peripherals;
13use embassy_traits::spi::FullDuplex;
14use example_common::*; 13use example_common::*;
15use heapless::String; 14use heapless::String;
16 15
@@ -33,7 +32,7 @@ async fn main(_spawner: Spawner, p: Peripherals) {
33 let mut write: String<128> = String::new(); 32 let mut write: String<128> = String::new();
34 let mut read = [0; 128]; 33 let mut read = [0; 128];
35 core::write!(&mut write, "Hello DMA World {}!\r\n", n).unwrap(); 34 core::write!(&mut write, "Hello DMA World {}!\r\n", n).unwrap();
36 spi.read_write(&mut read[0..write.len()], write.as_bytes()) 35 spi.transfer(&mut read[0..write.len()], write.as_bytes())
37 .await 36 .await
38 .ok(); 37 .ok();
39 info!("read via spi+dma: {}", from_utf8(&read).unwrap()); 38 info!("read via spi+dma: {}", from_utf8(&read).unwrap());
diff --git a/examples/stm32f4/src/bin/usart.rs b/examples/stm32f4/src/bin/usart.rs
index 391a8b9b0..b5ea98cca 100644
--- a/examples/stm32f4/src/bin/usart.rs
+++ b/examples/stm32f4/src/bin/usart.rs
@@ -7,7 +7,6 @@ mod example_common;
7use cortex_m_rt::entry; 7use cortex_m_rt::entry;
8use embassy_stm32::dma::NoDma; 8use embassy_stm32::dma::NoDma;
9use embassy_stm32::usart::{Config, Uart}; 9use embassy_stm32::usart::{Config, Uart};
10use embedded_hal::blocking::serial::Write;
11use example_common::*; 10use example_common::*;
12 11
13#[entry] 12#[entry]
@@ -19,12 +18,12 @@ fn main() -> ! {
19 let config = Config::default(); 18 let config = Config::default();
20 let mut usart = Uart::new(p.USART3, p.PD9, p.PD8, NoDma, NoDma, config); 19 let mut usart = Uart::new(p.USART3, p.PD9, p.PD8, NoDma, NoDma, config);
21 20
22 unwrap!(usart.bwrite_all(b"Hello Embassy World!\r\n")); 21 unwrap!(usart.blocking_write(b"Hello Embassy World!\r\n"));
23 info!("wrote Hello, starting echo"); 22 info!("wrote Hello, starting echo");
24 23
25 let mut buf = [0u8; 1]; 24 let mut buf = [0u8; 1];
26 loop { 25 loop {
27 unwrap!(usart.read_blocking(&mut buf)); 26 unwrap!(usart.blocking_read(&mut buf));
28 unwrap!(usart.bwrite_all(&buf)); 27 unwrap!(usart.blocking_write(&buf));
29 } 28 }
30} 29}
diff --git a/examples/stm32f4/src/bin/usart_dma.rs b/examples/stm32f4/src/bin/usart_dma.rs
index 0dbdd7c05..862a91ea8 100644
--- a/examples/stm32f4/src/bin/usart_dma.rs
+++ b/examples/stm32f4/src/bin/usart_dma.rs
@@ -9,7 +9,6 @@ use embassy::executor::Spawner;
9use embassy_stm32::dma::NoDma; 9use embassy_stm32::dma::NoDma;
10use embassy_stm32::usart::{Config, Uart}; 10use embassy_stm32::usart::{Config, Uart};
11use embassy_stm32::Peripherals; 11use embassy_stm32::Peripherals;
12use embassy_traits::uart::Write as _;
13use example_common::*; 12use example_common::*;
14use heapless::String; 13use heapless::String;
15 14
diff --git a/examples/stm32f7/src/bin/blinky.rs b/examples/stm32f7/src/bin/blinky.rs
index c4857195f..00d67dac0 100644
--- a/examples/stm32f7/src/bin/blinky.rs
+++ b/examples/stm32f7/src/bin/blinky.rs
@@ -8,7 +8,6 @@ use embassy::executor::Spawner;
8use embassy::time::{Duration, Timer}; 8use embassy::time::{Duration, Timer};
9use embassy_stm32::gpio::{Level, Output, Speed}; 9use embassy_stm32::gpio::{Level, Output, Speed};
10use embassy_stm32::Peripherals; 10use embassy_stm32::Peripherals;
11use embedded_hal::digital::v2::OutputPin;
12use example_common::*; 11use example_common::*;
13 12
14#[embassy::main] 13#[embassy::main]
@@ -19,11 +18,11 @@ async fn main(_spawner: Spawner, p: Peripherals) {
19 18
20 loop { 19 loop {
21 info!("high"); 20 info!("high");
22 unwrap!(led.set_high()); 21 led.set_high();
23 Timer::after(Duration::from_millis(300)).await; 22 Timer::after(Duration::from_millis(300)).await;
24 23
25 info!("low"); 24 info!("low");
26 unwrap!(led.set_low()); 25 led.set_low();
27 Timer::after(Duration::from_millis(300)).await; 26 Timer::after(Duration::from_millis(300)).await;
28 } 27 }
29} 28}
diff --git a/examples/stm32f7/src/bin/button.rs b/examples/stm32f7/src/bin/button.rs
index 95dee7c74..24eef75b2 100644
--- a/examples/stm32f7/src/bin/button.rs
+++ b/examples/stm32f7/src/bin/button.rs
@@ -6,7 +6,6 @@
6mod example_common; 6mod example_common;
7use cortex_m_rt::entry; 7use cortex_m_rt::entry;
8use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; 8use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
9use embedded_hal::digital::v2::{InputPin, OutputPin};
10use example_common::*; 9use example_common::*;
11 10
12#[entry] 11#[entry]
@@ -21,14 +20,14 @@ fn main() -> ! {
21 let mut led3 = Output::new(p.PB14, Level::High, Speed::Low); 20 let mut led3 = Output::new(p.PB14, Level::High, Speed::Low);
22 21
23 loop { 22 loop {
24 if unwrap!(button.is_high()) { 23 if button.is_high() {
25 info!("high"); 24 info!("high");
26 unwrap!(led1.set_high()); 25 led1.set_high();
27 unwrap!(led3.set_low()); 26 led3.set_low();
28 } else { 27 } else {
29 info!("low"); 28 info!("low");
30 unwrap!(led1.set_low()); 29 led1.set_low();
31 unwrap!(led3.set_high()); 30 led3.set_high();
32 } 31 }
33 } 32 }
34} 33}
diff --git a/examples/stm32f7/src/bin/button_exti.rs b/examples/stm32f7/src/bin/button_exti.rs
index 2c4318d64..852fbe3c6 100644
--- a/examples/stm32f7/src/bin/button_exti.rs
+++ b/examples/stm32f7/src/bin/button_exti.rs
@@ -8,7 +8,6 @@ use embassy::executor::Spawner;
8use embassy_stm32::exti::ExtiInput; 8use embassy_stm32::exti::ExtiInput;
9use embassy_stm32::gpio::{Input, Pull}; 9use embassy_stm32::gpio::{Input, Pull};
10use embassy_stm32::Peripherals; 10use embassy_stm32::Peripherals;
11use embassy_traits::gpio::{WaitForFallingEdge, WaitForRisingEdge};
12use example_common::*; 11use example_common::*;
13 12
14#[embassy::main] 13#[embassy::main]
diff --git a/examples/stm32f7/src/bin/usart_dma.rs b/examples/stm32f7/src/bin/usart_dma.rs
index 82af0bc22..00deae8b3 100644
--- a/examples/stm32f7/src/bin/usart_dma.rs
+++ b/examples/stm32f7/src/bin/usart_dma.rs
@@ -9,7 +9,6 @@ use embassy::executor::Spawner;
9use embassy_stm32::dma::NoDma; 9use embassy_stm32::dma::NoDma;
10use embassy_stm32::usart::{Config, Uart}; 10use embassy_stm32::usart::{Config, Uart};
11use embassy_stm32::Peripherals; 11use embassy_stm32::Peripherals;
12use embassy_traits::uart::Write as _Write;
13use example_common::*; 12use example_common::*;
14 13
15use heapless::String; 14use heapless::String;
diff --git a/examples/stm32g0/src/bin/blinky.rs b/examples/stm32g0/src/bin/blinky.rs
index c4857195f..00d67dac0 100644
--- a/examples/stm32g0/src/bin/blinky.rs
+++ b/examples/stm32g0/src/bin/blinky.rs
@@ -8,7 +8,6 @@ use embassy::executor::Spawner;
8use embassy::time::{Duration, Timer}; 8use embassy::time::{Duration, Timer};
9use embassy_stm32::gpio::{Level, Output, Speed}; 9use embassy_stm32::gpio::{Level, Output, Speed};
10use embassy_stm32::Peripherals; 10use embassy_stm32::Peripherals;
11use embedded_hal::digital::v2::OutputPin;
12use example_common::*; 11use example_common::*;
13 12
14#[embassy::main] 13#[embassy::main]
@@ -19,11 +18,11 @@ async fn main(_spawner: Spawner, p: Peripherals) {
19 18
20 loop { 19 loop {
21 info!("high"); 20 info!("high");
22 unwrap!(led.set_high()); 21 led.set_high();
23 Timer::after(Duration::from_millis(300)).await; 22 Timer::after(Duration::from_millis(300)).await;
24 23
25 info!("low"); 24 info!("low");
26 unwrap!(led.set_low()); 25 led.set_low();
27 Timer::after(Duration::from_millis(300)).await; 26 Timer::after(Duration::from_millis(300)).await;
28 } 27 }
29} 28}
diff --git a/examples/stm32g0/src/bin/button.rs b/examples/stm32g0/src/bin/button.rs
index 4ca2a43b2..e901c5750 100644
--- a/examples/stm32g0/src/bin/button.rs
+++ b/examples/stm32g0/src/bin/button.rs
@@ -6,7 +6,6 @@
6mod example_common; 6mod example_common;
7use cortex_m_rt::entry; 7use cortex_m_rt::entry;
8use embassy_stm32::gpio::{Input, Pull}; 8use embassy_stm32::gpio::{Input, Pull};
9use embedded_hal::digital::v2::InputPin;
10use example_common::*; 9use example_common::*;
11 10
12#[entry] 11#[entry]
@@ -18,7 +17,7 @@ fn main() -> ! {
18 let button = Input::new(p.PC13, Pull::Up); 17 let button = Input::new(p.PC13, Pull::Up);
19 18
20 loop { 19 loop {
21 if unwrap!(button.is_high()) { 20 if button.is_high() {
22 info!("high"); 21 info!("high");
23 } else { 22 } else {
24 info!("low"); 23 info!("low");
diff --git a/examples/stm32g0/src/bin/button_exti.rs b/examples/stm32g0/src/bin/button_exti.rs
index 0c2483ecb..848818bf2 100644
--- a/examples/stm32g0/src/bin/button_exti.rs
+++ b/examples/stm32g0/src/bin/button_exti.rs
@@ -8,7 +8,6 @@ use embassy::executor::Spawner;
8use embassy_stm32::exti::ExtiInput; 8use embassy_stm32::exti::ExtiInput;
9use embassy_stm32::gpio::{Input, Pull}; 9use embassy_stm32::gpio::{Input, Pull};
10use embassy_stm32::Peripherals; 10use embassy_stm32::Peripherals;
11use embassy_traits::gpio::{WaitForFallingEdge, WaitForRisingEdge};
12use example_common::*; 11use example_common::*;
13 12
14#[embassy::main] 13#[embassy::main]
diff --git a/examples/stm32g4/src/bin/blinky.rs b/examples/stm32g4/src/bin/blinky.rs
index a43922a63..1dc67f99e 100644
--- a/examples/stm32g4/src/bin/blinky.rs
+++ b/examples/stm32g4/src/bin/blinky.rs
@@ -8,7 +8,6 @@ use embassy::executor::Spawner;
8use embassy::time::{Duration, Timer}; 8use embassy::time::{Duration, Timer};
9use embassy_stm32::gpio::{Level, Output, Speed}; 9use embassy_stm32::gpio::{Level, Output, Speed};
10use embassy_stm32::Peripherals; 10use embassy_stm32::Peripherals;
11use embedded_hal::digital::v2::OutputPin;
12use example_common::*; 11use example_common::*;
13 12
14#[embassy::main] 13#[embassy::main]
@@ -19,11 +18,11 @@ async fn main(_spawner: Spawner, p: Peripherals) {
19 18
20 loop { 19 loop {
21 info!("high"); 20 info!("high");
22 unwrap!(led.set_high()); 21 led.set_high();
23 Timer::after(Duration::from_millis(300)).await; 22 Timer::after(Duration::from_millis(300)).await;
24 23
25 info!("low"); 24 info!("low");
26 unwrap!(led.set_low()); 25 led.set_low();
27 Timer::after(Duration::from_millis(300)).await; 26 Timer::after(Duration::from_millis(300)).await;
28 } 27 }
29} 28}
diff --git a/examples/stm32g4/src/bin/button.rs b/examples/stm32g4/src/bin/button.rs
index f0a4c8745..8c0d7d4fe 100644
--- a/examples/stm32g4/src/bin/button.rs
+++ b/examples/stm32g4/src/bin/button.rs
@@ -6,7 +6,6 @@
6mod example_common; 6mod example_common;
7use cortex_m_rt::entry; 7use cortex_m_rt::entry;
8use embassy_stm32::gpio::{Input, Pull}; 8use embassy_stm32::gpio::{Input, Pull};
9use embedded_hal::digital::v2::InputPin;
10use example_common::*; 9use example_common::*;
11 10
12#[entry] 11#[entry]
@@ -18,7 +17,7 @@ fn main() -> ! {
18 let button = Input::new(p.PC13, Pull::Down); 17 let button = Input::new(p.PC13, Pull::Down);
19 18
20 loop { 19 loop {
21 if unwrap!(button.is_high()) { 20 if button.is_high() {
22 info!("high"); 21 info!("high");
23 } else { 22 } else {
24 info!("low"); 23 info!("low");
diff --git a/examples/stm32g4/src/bin/button_exti.rs b/examples/stm32g4/src/bin/button_exti.rs
index 2c4318d64..852fbe3c6 100644
--- a/examples/stm32g4/src/bin/button_exti.rs
+++ b/examples/stm32g4/src/bin/button_exti.rs
@@ -8,7 +8,6 @@ use embassy::executor::Spawner;
8use embassy_stm32::exti::ExtiInput; 8use embassy_stm32::exti::ExtiInput;
9use embassy_stm32::gpio::{Input, Pull}; 9use embassy_stm32::gpio::{Input, Pull};
10use embassy_stm32::Peripherals; 10use embassy_stm32::Peripherals;
11use embassy_traits::gpio::{WaitForFallingEdge, WaitForRisingEdge};
12use example_common::*; 11use example_common::*;
13 12
14#[embassy::main] 13#[embassy::main]
diff --git a/examples/stm32h7/src/bin/blinky.rs b/examples/stm32h7/src/bin/blinky.rs
index 78edb5e27..7e5934239 100644
--- a/examples/stm32h7/src/bin/blinky.rs
+++ b/examples/stm32h7/src/bin/blinky.rs
@@ -8,7 +8,6 @@ use embassy::executor::Spawner;
8use embassy::time::{Duration, Timer}; 8use embassy::time::{Duration, Timer};
9use embassy_stm32::gpio::{Level, Output, Speed}; 9use embassy_stm32::gpio::{Level, Output, Speed};
10use embassy_stm32::Peripherals; 10use embassy_stm32::Peripherals;
11use embedded_hal::digital::v2::OutputPin;
12use example_common::*; 11use example_common::*;
13 12
14#[embassy::main] 13#[embassy::main]
@@ -19,11 +18,11 @@ async fn main(_spawner: Spawner, p: Peripherals) {
19 18
20 loop { 19 loop {
21 info!("high"); 20 info!("high");
22 unwrap!(led.set_high()); 21 led.set_high();
23 Timer::after(Duration::from_millis(500)).await; 22 Timer::after(Duration::from_millis(500)).await;
24 23
25 info!("low"); 24 info!("low");
26 unwrap!(led.set_low()); 25 led.set_low();
27 Timer::after(Duration::from_millis(500)).await; 26 Timer::after(Duration::from_millis(500)).await;
28 } 27 }
29} 28}
diff --git a/examples/stm32h7/src/bin/button_exti.rs b/examples/stm32h7/src/bin/button_exti.rs
index 2c4318d64..852fbe3c6 100644
--- a/examples/stm32h7/src/bin/button_exti.rs
+++ b/examples/stm32h7/src/bin/button_exti.rs
@@ -8,7 +8,6 @@ use embassy::executor::Spawner;
8use embassy_stm32::exti::ExtiInput; 8use embassy_stm32::exti::ExtiInput;
9use embassy_stm32::gpio::{Input, Pull}; 9use embassy_stm32::gpio::{Input, Pull};
10use embassy_stm32::Peripherals; 10use embassy_stm32::Peripherals;
11use embassy_traits::gpio::{WaitForFallingEdge, WaitForRisingEdge};
12use example_common::*; 11use example_common::*;
13 12
14#[embassy::main] 13#[embassy::main]
diff --git a/examples/stm32h7/src/bin/camera.rs b/examples/stm32h7/src/bin/camera.rs
index d94592071..9e8071bb3 100644
--- a/examples/stm32h7/src/bin/camera.rs
+++ b/examples/stm32h7/src/bin/camera.rs
@@ -11,7 +11,6 @@ use embassy_stm32::interrupt;
11use embassy_stm32::rcc::{Mco, Mco1Source, McoClock}; 11use embassy_stm32::rcc::{Mco, Mco1Source, McoClock};
12use embassy_stm32::time::U32Ext; 12use embassy_stm32::time::U32Ext;
13use embassy_stm32::Peripherals; 13use embassy_stm32::Peripherals;
14use embedded_hal::digital::v2::OutputPin;
15 14
16use defmt_rtt as _; // global logger 15use defmt_rtt as _; // global logger
17use panic_probe as _; 16use panic_probe as _;
@@ -114,11 +113,11 @@ async fn main(_spawner: Spawner, p: Peripherals) {
114 defmt::info!("main loop running"); 113 defmt::info!("main loop running");
115 loop { 114 loop {
116 defmt::info!("high"); 115 defmt::info!("high");
117 defmt::unwrap!(led.set_high()); 116 led.set_high();
118 Timer::after(Duration::from_millis(500)).await; 117 Timer::after(Duration::from_millis(500)).await;
119 118
120 defmt::info!("low"); 119 defmt::info!("low");
121 defmt::unwrap!(led.set_low()); 120 led.set_low();
122 Timer::after(Duration::from_millis(500)).await; 121 Timer::after(Duration::from_millis(500)).await;
123 } 122 }
124} 123}
diff --git a/examples/stm32h7/src/bin/mco.rs b/examples/stm32h7/src/bin/mco.rs
index 4cecd9b04..f27bd8ef8 100644
--- a/examples/stm32h7/src/bin/mco.rs
+++ b/examples/stm32h7/src/bin/mco.rs
@@ -9,7 +9,6 @@ use embassy::time::{Duration, Timer};
9use embassy_stm32::gpio::{Level, Output, Speed}; 9use embassy_stm32::gpio::{Level, Output, Speed};
10use embassy_stm32::rcc::{Mco, Mco1Source, McoClock}; 10use embassy_stm32::rcc::{Mco, Mco1Source, McoClock};
11use embassy_stm32::Peripherals; 11use embassy_stm32::Peripherals;
12use embedded_hal::digital::v2::OutputPin;
13use example_common::*; 12use example_common::*;
14 13
15#[embassy::main] 14#[embassy::main]
@@ -22,11 +21,11 @@ async fn main(_spawner: Spawner, p: Peripherals) {
22 21
23 loop { 22 loop {
24 info!("high"); 23 info!("high");
25 unwrap!(led.set_high()); 24 led.set_high();
26 Timer::after(Duration::from_millis(500)).await; 25 Timer::after(Duration::from_millis(500)).await;
27 26
28 info!("low"); 27 info!("low");
29 unwrap!(led.set_low()); 28 led.set_low();
30 Timer::after(Duration::from_millis(500)).await; 29 Timer::after(Duration::from_millis(500)).await;
31 } 30 }
32} 31}
diff --git a/examples/stm32h7/src/bin/rng.rs b/examples/stm32h7/src/bin/rng.rs
index d64ad9bcd..8e03861d5 100644
--- a/examples/stm32h7/src/bin/rng.rs
+++ b/examples/stm32h7/src/bin/rng.rs
@@ -10,7 +10,6 @@ use embassy::traits::rng::Random;
10use embassy_stm32::gpio::{Level, Output, Speed}; 10use embassy_stm32::gpio::{Level, Output, Speed};
11use embassy_stm32::rng::Rng; 11use embassy_stm32::rng::Rng;
12use embassy_stm32::Peripherals; 12use embassy_stm32::Peripherals;
13use embedded_hal::digital::v2::OutputPin;
14use example_common::*; 13use example_common::*;
15 14
16#[embassy::main] 15#[embassy::main]
@@ -23,11 +22,11 @@ async fn main(_spawner: Spawner, p: Peripherals) {
23 22
24 loop { 23 loop {
25 info!("high {}", unwrap!(rng.next_u8(16).await)); 24 info!("high {}", unwrap!(rng.next_u8(16).await));
26 unwrap!(led.set_high()); 25 led.set_high();
27 Timer::after(Duration::from_millis(500)).await; 26 Timer::after(Duration::from_millis(500)).await;
28 27
29 info!("low {}", unwrap!(rng.next_u8(16).await)); 28 info!("low {}", unwrap!(rng.next_u8(16).await));
30 unwrap!(led.set_low()); 29 led.set_low();
31 Timer::after(Duration::from_millis(500)).await; 30 Timer::after(Duration::from_millis(500)).await;
32 } 31 }
33} 32}
diff --git a/examples/stm32h7/src/bin/spi.rs b/examples/stm32h7/src/bin/spi.rs
index 0b375b0d0..17e64da79 100644
--- a/examples/stm32h7/src/bin/spi.rs
+++ b/examples/stm32h7/src/bin/spi.rs
@@ -10,7 +10,6 @@ use embassy::executor::Executor;
10use embassy::util::Forever; 10use embassy::util::Forever;
11use embassy_stm32::dma::NoDma; 11use embassy_stm32::dma::NoDma;
12use embassy_stm32::spi; 12use embassy_stm32::spi;
13use embedded_hal::blocking::spi::Transfer;
14use example_common::*; 13use example_common::*;
15 14
16use core::str::from_utf8; 15use core::str::from_utf8;
@@ -25,7 +24,7 @@ async fn main_task(mut spi: spi::Spi<'static, SPI3, NoDma, NoDma>) {
25 let mut write: String<128> = String::new(); 24 let mut write: String<128> = String::new();
26 core::write!(&mut write, "Hello DMA World {}!\r\n", n).unwrap(); 25 core::write!(&mut write, "Hello DMA World {}!\r\n", n).unwrap();
27 unsafe { 26 unsafe {
28 let result = spi.transfer(write.as_bytes_mut()); 27 let result = spi.blocking_transfer_in_place(write.as_bytes_mut());
29 if let Err(_) = result { 28 if let Err(_) = result {
30 defmt::panic!("crap"); 29 defmt::panic!("crap");
31 } 30 }
diff --git a/examples/stm32h7/src/bin/usart.rs b/examples/stm32h7/src/bin/usart.rs
index 95f0a8604..211e57cda 100644
--- a/examples/stm32h7/src/bin/usart.rs
+++ b/examples/stm32h7/src/bin/usart.rs
@@ -4,7 +4,6 @@
4 4
5#[path = "../example_common.rs"] 5#[path = "../example_common.rs"]
6mod example_common; 6mod example_common;
7use cortex_m::prelude::_embedded_hal_blocking_serial_Write;
8use embassy::executor::Executor; 7use embassy::executor::Executor;
9use embassy::util::Forever; 8use embassy::util::Forever;
10use embassy_stm32::dma::NoDma; 9use embassy_stm32::dma::NoDma;
@@ -20,13 +19,13 @@ async fn main_task() {
20 let config = Config::default(); 19 let config = Config::default();
21 let mut usart = Uart::new(p.UART7, p.PF6, p.PF7, NoDma, NoDma, config); 20 let mut usart = Uart::new(p.UART7, p.PF6, p.PF7, NoDma, NoDma, config);
22 21
23 unwrap!(usart.bwrite_all(b"Hello Embassy World!\r\n")); 22 unwrap!(usart.blocking_write(b"Hello Embassy World!\r\n"));
24 info!("wrote Hello, starting echo"); 23 info!("wrote Hello, starting echo");
25 24
26 let mut buf = [0u8; 1]; 25 let mut buf = [0u8; 1];
27 loop { 26 loop {
28 unwrap!(usart.read_blocking(&mut buf)); 27 unwrap!(usart.blocking_read(&mut buf));
29 unwrap!(usart.bwrite_all(&buf)); 28 unwrap!(usart.blocking_write(&buf));
30 } 29 }
31} 30}
32 31
diff --git a/examples/stm32h7/src/bin/usart_dma.rs b/examples/stm32h7/src/bin/usart_dma.rs
index d603347ac..a9221e1b6 100644
--- a/examples/stm32h7/src/bin/usart_dma.rs
+++ b/examples/stm32h7/src/bin/usart_dma.rs
@@ -9,7 +9,6 @@ use embassy::executor::Executor;
9use embassy::util::Forever; 9use embassy::util::Forever;
10use embassy_stm32::dma::NoDma; 10use embassy_stm32::dma::NoDma;
11use embassy_stm32::usart::{Config, Uart}; 11use embassy_stm32::usart::{Config, Uart};
12use embassy_traits::uart::Write as _Write;
13use example_common::*; 12use example_common::*;
14 13
15use cortex_m_rt::entry; 14use cortex_m_rt::entry;
diff --git a/examples/stm32l0/.cargo/config.toml b/examples/stm32l0/.cargo/config.toml
index 4ea047484..840faa62e 100644
--- a/examples/stm32l0/.cargo/config.toml
+++ b/examples/stm32l0/.cargo/config.toml
@@ -1,6 +1,6 @@
1[target.'cfg(all(target_arch = "arm", target_os = "none"))'] 1[target.'cfg(all(target_arch = "arm", target_os = "none"))']
2# replace your chip as listed in `probe-run --list-chips` 2# replace your chip as listed in `probe-run --list-chips`
3runner = "probe-run --chip STM32L072CZ" 3runner = "probe-run --chip STM32L072CZTx"
4 4
5[build] 5[build]
6target = "thumbv6m-none-eabi" 6target = "thumbv6m-none-eabi"
diff --git a/examples/stm32l0/Cargo.toml b/examples/stm32l0/Cargo.toml
index 7056d580a..20a2ec8d0 100644
--- a/examples/stm32l0/Cargo.toml
+++ b/examples/stm32l0/Cargo.toml
@@ -8,7 +8,7 @@ resolver = "2"
8[dependencies] 8[dependencies]
9embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt"] } 9embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt"] }
10embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] } 10embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] }
11embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "stm32l072cz", "time-driver-tim3", "exti"] } 11embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "stm32l072cz", "time-driver-tim3", "exti", "memory-x"] }
12 12
13embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["sx127x", "time", "defmt"] } 13embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["sx127x", "time", "defmt"] }
14 14
diff --git a/examples/stm32l0/build.rs b/examples/stm32l0/build.rs
index 30691aa97..8cd32d7ed 100644
--- a/examples/stm32l0/build.rs
+++ b/examples/stm32l0/build.rs
@@ -1,34 +1,4 @@
1//! This build script copies the `memory.x` file from the crate root into
2//! a directory where the linker can always find it at build time.
3//! For many projects this is optional, as the linker always searches the
4//! project root directory -- wherever `Cargo.toml` is. However, if you
5//! are using a workspace or have a more complicated build setup, this
6//! build script becomes required. Additionally, by requesting that
7//! Cargo re-run the build script whenever `memory.x` is changed,
8//! updating `memory.x` ensures a rebuild of the application with the
9//! new memory settings.
10
11use std::env;
12use std::fs::File;
13use std::io::Write;
14use std::path::PathBuf;
15
16fn main() { 1fn main() {
17 // Put `memory.x` in our output directory and ensure it's
18 // on the linker search path.
19 let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
20 File::create(out.join("memory.x"))
21 .unwrap()
22 .write_all(include_bytes!("memory.x"))
23 .unwrap();
24 println!("cargo:rustc-link-search={}", out.display());
25
26 // By default, Cargo will re-run a build script whenever
27 // any file in the project changes. By specifying `memory.x`
28 // here, we ensure the build script is only re-run when
29 // `memory.x` is changed.
30 println!("cargo:rerun-if-changed=memory.x");
31
32 println!("cargo:rustc-link-arg-bins=--nmagic"); 2 println!("cargo:rustc-link-arg-bins=--nmagic");
33 println!("cargo:rustc-link-arg-bins=-Tlink.x"); 3 println!("cargo:rustc-link-arg-bins=-Tlink.x");
34 println!("cargo:rustc-link-arg-bins=-Tdefmt.x"); 4 println!("cargo:rustc-link-arg-bins=-Tdefmt.x");
diff --git a/examples/stm32l0/memory.x b/examples/stm32l0/memory.x
deleted file mode 100644
index 67a50a5ff..000000000
--- a/examples/stm32l0/memory.x
+++ /dev/null
@@ -1,5 +0,0 @@
1MEMORY
2{
3 FLASH : ORIGIN = 0x08000000, LENGTH = 192K
4 RAM : ORIGIN = 0x20000000, LENGTH = 20K
5}
diff --git a/examples/stm32l0/src/bin/blinky.rs b/examples/stm32l0/src/bin/blinky.rs
index 1198b29da..46e29a897 100644
--- a/examples/stm32l0/src/bin/blinky.rs
+++ b/examples/stm32l0/src/bin/blinky.rs
@@ -9,7 +9,6 @@ use embassy::executor::Spawner;
9use embassy::time::{Duration, Timer}; 9use embassy::time::{Duration, Timer};
10use embassy_stm32::gpio::{Level, Output, Speed}; 10use embassy_stm32::gpio::{Level, Output, Speed};
11use embassy_stm32::Peripherals; 11use embassy_stm32::Peripherals;
12use embedded_hal::digital::v2::OutputPin;
13use example_common::*; 12use example_common::*;
14 13
15#[embassy::main] 14#[embassy::main]
@@ -20,11 +19,11 @@ async fn main(_spawner: Spawner, p: Peripherals) {
20 19
21 loop { 20 loop {
22 info!("high"); 21 info!("high");
23 unwrap!(led.set_high()); 22 led.set_high();
24 Timer::after(Duration::from_millis(300)).await; 23 Timer::after(Duration::from_millis(300)).await;
25 24
26 info!("low"); 25 info!("low");
27 unwrap!(led.set_low()); 26 led.set_low();
28 Timer::after(Duration::from_millis(300)).await; 27 Timer::after(Duration::from_millis(300)).await;
29 } 28 }
30} 29}
diff --git a/examples/stm32l0/src/bin/button.rs b/examples/stm32l0/src/bin/button.rs
index c29155302..046c43caf 100644
--- a/examples/stm32l0/src/bin/button.rs
+++ b/examples/stm32l0/src/bin/button.rs
@@ -7,7 +7,6 @@ mod example_common;
7use embassy::executor::Spawner; 7use embassy::executor::Spawner;
8use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; 8use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
9use embassy_stm32::Peripherals; 9use embassy_stm32::Peripherals;
10use embedded_hal::digital::v2::{InputPin, OutputPin};
11use example_common::*; 10use example_common::*;
12 11
13#[embassy::main] 12#[embassy::main]
@@ -19,14 +18,14 @@ async fn main(_spawner: Spawner, p: Peripherals) {
19 let mut led2 = Output::new(p.PB5, Level::High, Speed::Low); 18 let mut led2 = Output::new(p.PB5, Level::High, Speed::Low);
20 19
21 loop { 20 loop {
22 if unwrap!(button.is_high()) { 21 if button.is_high() {
23 info!("high"); 22 info!("high");
24 unwrap!(led1.set_high()); 23 led1.set_high();
25 unwrap!(led2.set_low()); 24 led2.set_low();
26 } else { 25 } else {
27 info!("low"); 26 info!("low");
28 unwrap!(led1.set_low()); 27 led1.set_low();
29 unwrap!(led2.set_high()); 28 led2.set_high();
30 } 29 }
31 } 30 }
32} 31}
diff --git a/examples/stm32l0/src/bin/button_exti.rs b/examples/stm32l0/src/bin/button_exti.rs
index 88c75ce6d..3edea3976 100644
--- a/examples/stm32l0/src/bin/button_exti.rs
+++ b/examples/stm32l0/src/bin/button_exti.rs
@@ -9,7 +9,6 @@ use embassy::executor::Spawner;
9use embassy_stm32::exti::ExtiInput; 9use embassy_stm32::exti::ExtiInput;
10use embassy_stm32::gpio::{Input, Pull}; 10use embassy_stm32::gpio::{Input, Pull};
11use embassy_stm32::Peripherals; 11use embassy_stm32::Peripherals;
12use embassy_traits::gpio::{WaitForFallingEdge, WaitForRisingEdge};
13use example_common::*; 12use example_common::*;
14 13
15fn config() -> embassy_stm32::Config { 14fn config() -> embassy_stm32::Config {
diff --git a/examples/stm32l0/src/bin/spi.rs b/examples/stm32l0/src/bin/spi.rs
index f768a5227..8d6e89d91 100644
--- a/examples/stm32l0/src/bin/spi.rs
+++ b/examples/stm32l0/src/bin/spi.rs
@@ -7,14 +7,12 @@ mod example_common;
7 7
8use embassy::executor::Spawner; 8use embassy::executor::Spawner;
9use embassy_stm32::gpio::{Level, Output, Speed}; 9use embassy_stm32::gpio::{Level, Output, Speed};
10use embedded_hal::digital::v2::OutputPin;
11use example_common::*; 10use example_common::*;
12 11
13use embassy_stm32::dma::NoDma; 12use embassy_stm32::dma::NoDma;
14use embassy_stm32::spi::{Config, Spi}; 13use embassy_stm32::spi::{Config, Spi};
15use embassy_stm32::time::Hertz; 14use embassy_stm32::time::Hertz;
16use embassy_stm32::Peripherals; 15use embassy_stm32::Peripherals;
17use embedded_hal::blocking::spi::Transfer;
18 16
19#[embassy::main] 17#[embassy::main]
20async fn main(_spawner: Spawner, p: Peripherals) { 18async fn main(_spawner: Spawner, p: Peripherals) {
@@ -35,9 +33,9 @@ async fn main(_spawner: Spawner, p: Peripherals) {
35 33
36 loop { 34 loop {
37 let mut buf = [0x0Au8; 4]; 35 let mut buf = [0x0Au8; 4];
38 unwrap!(cs.set_low()); 36 cs.set_low();
39 unwrap!(spi.transfer(&mut buf)); 37 unwrap!(spi.blocking_transfer_in_place(&mut buf));
40 unwrap!(cs.set_high()); 38 cs.set_high();
41 info!("xfer {=[u8]:x}", buf); 39 info!("xfer {=[u8]:x}", buf);
42 } 40 }
43} 41}
diff --git a/examples/stm32l0/src/bin/usart_dma.rs b/examples/stm32l0/src/bin/usart_dma.rs
index 3fe61c13d..543e66f62 100644
--- a/examples/stm32l0/src/bin/usart_dma.rs
+++ b/examples/stm32l0/src/bin/usart_dma.rs
@@ -10,7 +10,6 @@ use example_common::*;
10use embassy::executor::Spawner; 10use embassy::executor::Spawner;
11use embassy_stm32::usart::{Config, Uart}; 11use embassy_stm32::usart::{Config, Uart};
12use embassy_stm32::Peripherals; 12use embassy_stm32::Peripherals;
13use embassy_traits::uart::{Read, Write};
14 13
15#[embassy::main] 14#[embassy::main]
16async fn main(_spawner: Spawner, p: Peripherals) { 15async fn main(_spawner: Spawner, p: Peripherals) {
diff --git a/examples/stm32l1/src/bin/blinky.rs b/examples/stm32l1/src/bin/blinky.rs
index deabdddba..07c804e9f 100644
--- a/examples/stm32l1/src/bin/blinky.rs
+++ b/examples/stm32l1/src/bin/blinky.rs
@@ -9,7 +9,6 @@ use embassy::executor::Spawner;
9use embassy::time::{Duration, Timer}; 9use embassy::time::{Duration, Timer};
10use embassy_stm32::gpio::{Level, Output, Speed}; 10use embassy_stm32::gpio::{Level, Output, Speed};
11use embassy_stm32::Peripherals; 11use embassy_stm32::Peripherals;
12use embedded_hal::digital::v2::OutputPin;
13use example_common::*; 12use example_common::*;
14 13
15#[embassy::main] 14#[embassy::main]
@@ -20,11 +19,11 @@ async fn main(_spawner: Spawner, p: Peripherals) {
20 19
21 loop { 20 loop {
22 info!("high"); 21 info!("high");
23 unwrap!(led.set_high()); 22 led.set_high();
24 Timer::after(Duration::from_millis(1000)).await; 23 Timer::after(Duration::from_millis(1000)).await;
25 24
26 info!("low"); 25 info!("low");
27 unwrap!(led.set_low()); 26 led.set_low();
28 Timer::after(Duration::from_millis(1000)).await; 27 Timer::after(Duration::from_millis(1000)).await;
29 } 28 }
30} 29}
diff --git a/examples/stm32l1/src/bin/spi.rs b/examples/stm32l1/src/bin/spi.rs
index 3cfbe3fc4..e97e3ebb4 100644
--- a/examples/stm32l1/src/bin/spi.rs
+++ b/examples/stm32l1/src/bin/spi.rs
@@ -7,14 +7,12 @@ mod example_common;
7 7
8use embassy::executor::Spawner; 8use embassy::executor::Spawner;
9use embassy_stm32::gpio::{Level, Output, Speed}; 9use embassy_stm32::gpio::{Level, Output, Speed};
10use embedded_hal::digital::v2::OutputPin;
11use example_common::*; 10use example_common::*;
12 11
13use embassy_stm32::dma::NoDma; 12use embassy_stm32::dma::NoDma;
14use embassy_stm32::spi::{Config, Spi}; 13use embassy_stm32::spi::{Config, Spi};
15use embassy_stm32::time::Hertz; 14use embassy_stm32::time::Hertz;
16use embassy_stm32::Peripherals; 15use embassy_stm32::Peripherals;
17use embedded_hal::blocking::spi::Transfer;
18 16
19#[embassy::main] 17#[embassy::main]
20async fn main(_spawner: Spawner, p: Peripherals) { 18async fn main(_spawner: Spawner, p: Peripherals) {
@@ -35,9 +33,9 @@ async fn main(_spawner: Spawner, p: Peripherals) {
35 33
36 loop { 34 loop {
37 let mut buf = [0x0Au8; 4]; 35 let mut buf = [0x0Au8; 4];
38 unwrap!(cs.set_low()); 36 cs.set_low();
39 unwrap!(spi.transfer(&mut buf)); 37 unwrap!(spi.blocking_transfer_in_place(&mut buf));
40 unwrap!(cs.set_high()); 38 cs.set_high();
41 info!("xfer {=[u8]:x}", buf); 39 info!("xfer {=[u8]:x}", buf);
42 } 40 }
43} 41}
diff --git a/examples/stm32l4/src/bin/blinky.rs b/examples/stm32l4/src/bin/blinky.rs
index 8a65858f8..030283756 100644
--- a/examples/stm32l4/src/bin/blinky.rs
+++ b/examples/stm32l4/src/bin/blinky.rs
@@ -8,7 +8,6 @@ use embassy::executor::Spawner;
8use embassy::time::{Duration, Timer}; 8use embassy::time::{Duration, Timer};
9use embassy_stm32::gpio::{Level, Output, Speed}; 9use embassy_stm32::gpio::{Level, Output, Speed};
10use embassy_stm32::Peripherals; 10use embassy_stm32::Peripherals;
11use embedded_hal::digital::v2::OutputPin;
12use example_common::*; 11use example_common::*;
13 12
14#[embassy::main] 13#[embassy::main]
@@ -18,9 +17,9 @@ async fn main(_spawner: Spawner, p: Peripherals) {
18 let mut led = Output::new(p.PB14, Level::High, Speed::Low); 17 let mut led = Output::new(p.PB14, Level::High, Speed::Low);
19 18
20 loop { 19 loop {
21 unwrap!(led.set_high()); 20 led.set_high();
22 Timer::after(Duration::from_millis(300)).await; 21 Timer::after(Duration::from_millis(300)).await;
23 unwrap!(led.set_low()); 22 led.set_low();
24 Timer::after(Duration::from_millis(300)).await; 23 Timer::after(Duration::from_millis(300)).await;
25 } 24 }
26} 25}
diff --git a/examples/stm32l4/src/bin/button.rs b/examples/stm32l4/src/bin/button.rs
index fd8674549..6073c137e 100644
--- a/examples/stm32l4/src/bin/button.rs
+++ b/examples/stm32l4/src/bin/button.rs
@@ -5,7 +5,6 @@
5#[path = "../example_common.rs"] 5#[path = "../example_common.rs"]
6mod example_common; 6mod example_common;
7use embassy_stm32::gpio::{Input, Pull}; 7use embassy_stm32::gpio::{Input, Pull};
8use embedded_hal::digital::v2::InputPin;
9use example_common::*; 8use example_common::*;
10 9
11#[cortex_m_rt::entry] 10#[cortex_m_rt::entry]
@@ -17,7 +16,7 @@ fn main() -> ! {
17 let button = Input::new(p.PC13, Pull::Up); 16 let button = Input::new(p.PC13, Pull::Up);
18 17
19 loop { 18 loop {
20 if unwrap!(button.is_high()) { 19 if button.is_high() {
21 info!("high"); 20 info!("high");
22 } else { 21 } else {
23 info!("low"); 22 info!("low");
diff --git a/examples/stm32l4/src/bin/button_exti.rs b/examples/stm32l4/src/bin/button_exti.rs
index 0c2483ecb..848818bf2 100644
--- a/examples/stm32l4/src/bin/button_exti.rs
+++ b/examples/stm32l4/src/bin/button_exti.rs
@@ -8,7 +8,6 @@ use embassy::executor::Spawner;
8use embassy_stm32::exti::ExtiInput; 8use embassy_stm32::exti::ExtiInput;
9use embassy_stm32::gpio::{Input, Pull}; 9use embassy_stm32::gpio::{Input, Pull};
10use embassy_stm32::Peripherals; 10use embassy_stm32::Peripherals;
11use embassy_traits::gpio::{WaitForFallingEdge, WaitForRisingEdge};
12use example_common::*; 11use example_common::*;
13 12
14#[embassy::main] 13#[embassy::main]
diff --git a/examples/stm32l4/src/bin/i2c.rs b/examples/stm32l4/src/bin/i2c.rs
index 86215697b..615012a06 100644
--- a/examples/stm32l4/src/bin/i2c.rs
+++ b/examples/stm32l4/src/bin/i2c.rs
@@ -11,7 +11,6 @@ use embassy_stm32::i2c::I2c;
11use embassy_stm32::interrupt; 11use embassy_stm32::interrupt;
12use embassy_stm32::time::Hertz; 12use embassy_stm32::time::Hertz;
13use embassy_stm32::Peripherals; 13use embassy_stm32::Peripherals;
14use embedded_hal::blocking::i2c::WriteRead;
15use example_common::{info, unwrap}; 14use example_common::{info, unwrap};
16 15
17const ADDRESS: u8 = 0x5F; 16const ADDRESS: u8 = 0x5F;
@@ -23,6 +22,6 @@ async fn main(_spawner: Spawner, p: Peripherals) -> ! {
23 let mut i2c = I2c::new(p.I2C2, p.PB10, p.PB11, irq, NoDma, NoDma, Hertz(100_000)); 22 let mut i2c = I2c::new(p.I2C2, p.PB10, p.PB11, irq, NoDma, NoDma, Hertz(100_000));
24 23
25 let mut data = [0u8; 1]; 24 let mut data = [0u8; 1];
26 unwrap!(i2c.write_read(ADDRESS, &[WHOAMI], &mut data)); 25 unwrap!(i2c.blocking_write_read(ADDRESS, &[WHOAMI], &mut data));
27 info!("Whoami: {}", data[0]); 26 info!("Whoami: {}", data[0]);
28} 27}
diff --git a/examples/stm32l4/src/bin/i2c_dma.rs b/examples/stm32l4/src/bin/i2c_dma.rs
index b0596aab8..d77bee8c1 100644
--- a/examples/stm32l4/src/bin/i2c_dma.rs
+++ b/examples/stm32l4/src/bin/i2c_dma.rs
@@ -6,7 +6,6 @@
6mod example_common; 6mod example_common;
7 7
8use embassy::executor::Spawner; 8use embassy::executor::Spawner;
9use embassy::traits::i2c::I2c as I2cTrait;
10use embassy_stm32::i2c::I2c; 9use embassy_stm32::i2c::I2c;
11use embassy_stm32::interrupt; 10use embassy_stm32::interrupt;
12use embassy_stm32::time::Hertz; 11use embassy_stm32::time::Hertz;
diff --git a/examples/stm32l4/src/bin/spi.rs b/examples/stm32l4/src/bin/spi.rs
index 5b9ae1ce0..8567d3062 100644
--- a/examples/stm32l4/src/bin/spi.rs
+++ b/examples/stm32l4/src/bin/spi.rs
@@ -9,8 +9,6 @@ use embassy_stm32::dma::NoDma;
9use embassy_stm32::gpio::{Level, Output, Speed}; 9use embassy_stm32::gpio::{Level, Output, Speed};
10use embassy_stm32::spi::{Config, Spi}; 10use embassy_stm32::spi::{Config, Spi};
11use embassy_stm32::time::Hertz; 11use embassy_stm32::time::Hertz;
12use embedded_hal::blocking::spi::Transfer;
13use embedded_hal::digital::v2::OutputPin;
14use example_common::*; 12use example_common::*;
15 13
16#[cortex_m_rt::entry] 14#[cortex_m_rt::entry]
@@ -34,9 +32,9 @@ fn main() -> ! {
34 32
35 loop { 33 loop {
36 let mut buf = [0x0Au8; 4]; 34 let mut buf = [0x0Au8; 4];
37 unwrap!(cs.set_low()); 35 cs.set_low();
38 unwrap!(spi.transfer(&mut buf)); 36 unwrap!(spi.blocking_transfer_in_place(&mut buf));
39 unwrap!(cs.set_high()); 37 cs.set_high();
40 info!("xfer {=[u8]:x}", buf); 38 info!("xfer {=[u8]:x}", buf);
41 } 39 }
42} 40}
diff --git a/examples/stm32l4/src/bin/spi_blocking_async.rs b/examples/stm32l4/src/bin/spi_blocking_async.rs
index f092706d4..3be3f21c9 100644
--- a/examples/stm32l4/src/bin/spi_blocking_async.rs
+++ b/examples/stm32l4/src/bin/spi_blocking_async.rs
@@ -12,7 +12,6 @@ use embassy_stm32::spi::{Config, Spi};
12use embassy_stm32::time::Hertz; 12use embassy_stm32::time::Hertz;
13use embassy_stm32::Peripherals; 13use embassy_stm32::Peripherals;
14use embassy_traits::{adapter::BlockingAsync, spi::FullDuplex}; 14use embassy_traits::{adapter::BlockingAsync, spi::FullDuplex};
15use embedded_hal::digital::v2::{InputPin, OutputPin};
16use example_common::*; 15use example_common::*;
17 16
18#[embassy::main] 17#[embassy::main]
@@ -41,17 +40,17 @@ async fn main(_spawner: Spawner, p: Peripherals) {
41 let ready = Input::new(p.PE1, Pull::Up); 40 let ready = Input::new(p.PE1, Pull::Up);
42 41
43 cortex_m::asm::delay(100_000); 42 cortex_m::asm::delay(100_000);
44 unwrap!(reset.set_high()); 43 reset.set_high();
45 cortex_m::asm::delay(100_000); 44 cortex_m::asm::delay(100_000);
46 45
47 while unwrap!(ready.is_low()) { 46 while ready.is_low() {
48 info!("waiting for ready"); 47 info!("waiting for ready");
49 } 48 }
50 49
51 let write = [0x0A; 10]; 50 let write = [0x0A; 10];
52 let mut read = [0; 10]; 51 let mut read = [0; 10];
53 unwrap!(cs.set_low()); 52 cs.set_low();
54 spi.read_write(&mut read, &write).await.ok(); 53 spi.read_write(&mut read, &write).await.ok();
55 unwrap!(cs.set_high()); 54 cs.set_high();
56 info!("xfer {=[u8]:x}", read); 55 info!("xfer {=[u8]:x}", read);
57} 56}
diff --git a/examples/stm32l4/src/bin/spi_dma.rs b/examples/stm32l4/src/bin/spi_dma.rs
index 4b74c7d7d..d6464bbfa 100644
--- a/examples/stm32l4/src/bin/spi_dma.rs
+++ b/examples/stm32l4/src/bin/spi_dma.rs
@@ -11,7 +11,6 @@ use embassy_stm32::spi::{Config, Spi};
11use embassy_stm32::time::Hertz; 11use embassy_stm32::time::Hertz;
12use embassy_stm32::Peripherals; 12use embassy_stm32::Peripherals;
13use embassy_traits::spi::FullDuplex; 13use embassy_traits::spi::FullDuplex;
14use embedded_hal::digital::v2::{InputPin, OutputPin};
15use example_common::*; 14use example_common::*;
16 15
17#[embassy::main] 16#[embassy::main]
@@ -38,17 +37,17 @@ async fn main(_spawner: Spawner, p: Peripherals) {
38 let ready = Input::new(p.PE1, Pull::Up); 37 let ready = Input::new(p.PE1, Pull::Up);
39 38
40 cortex_m::asm::delay(100_000); 39 cortex_m::asm::delay(100_000);
41 unwrap!(reset.set_high()); 40 reset.set_high();
42 cortex_m::asm::delay(100_000); 41 cortex_m::asm::delay(100_000);
43 42
44 while unwrap!(ready.is_low()) { 43 while ready.is_low() {
45 info!("waiting for ready"); 44 info!("waiting for ready");
46 } 45 }
47 46
48 let write = [0x0A; 10]; 47 let write = [0x0A; 10];
49 let mut read = [0; 10]; 48 let mut read = [0; 10];
50 unwrap!(cs.set_low()); 49 cs.set_low();
51 spi.read_write(&mut read, &write).await.ok(); 50 spi.read_write(&mut read, &write).await.ok();
52 unwrap!(cs.set_high()); 51 cs.set_high();
53 info!("xfer {=[u8]:x}", read); 52 info!("xfer {=[u8]:x}", read);
54} 53}
diff --git a/examples/stm32l4/src/bin/usart.rs b/examples/stm32l4/src/bin/usart.rs
index b6decbc9d..00875c896 100644
--- a/examples/stm32l4/src/bin/usart.rs
+++ b/examples/stm32l4/src/bin/usart.rs
@@ -7,7 +7,6 @@ mod example_common;
7 7
8use embassy_stm32::dma::NoDma; 8use embassy_stm32::dma::NoDma;
9use embassy_stm32::usart::{Config, Uart}; 9use embassy_stm32::usart::{Config, Uart};
10use embedded_hal::blocking::serial::Write;
11use example_common::*; 10use example_common::*;
12 11
13#[cortex_m_rt::entry] 12#[cortex_m_rt::entry]
@@ -19,12 +18,12 @@ fn main() -> ! {
19 let config = Config::default(); 18 let config = Config::default();
20 let mut usart = Uart::new(p.UART4, p.PA1, p.PA0, NoDma, NoDma, config); 19 let mut usart = Uart::new(p.UART4, p.PA1, p.PA0, NoDma, NoDma, config);
21 20
22 unwrap!(usart.bwrite_all(b"Hello Embassy World!\r\n")); 21 unwrap!(usart.blocking_write(b"Hello Embassy World!\r\n"));
23 info!("wrote Hello, starting echo"); 22 info!("wrote Hello, starting echo");
24 23
25 let mut buf = [0u8; 1]; 24 let mut buf = [0u8; 1];
26 loop { 25 loop {
27 unwrap!(usart.read_blocking(&mut buf)); 26 unwrap!(usart.blocking_read(&mut buf));
28 unwrap!(usart.bwrite_all(&buf)); 27 unwrap!(usart.blocking_write(&buf));
29 } 28 }
30} 29}
diff --git a/examples/stm32l4/src/bin/usart_dma.rs b/examples/stm32l4/src/bin/usart_dma.rs
index b49d3d882..b3a1e3897 100644
--- a/examples/stm32l4/src/bin/usart_dma.rs
+++ b/examples/stm32l4/src/bin/usart_dma.rs
@@ -9,7 +9,6 @@ use embassy::executor::Spawner;
9use embassy_stm32::dma::NoDma; 9use embassy_stm32::dma::NoDma;
10use embassy_stm32::usart::{Config, Uart}; 10use embassy_stm32::usart::{Config, Uart};
11use embassy_stm32::Peripherals; 11use embassy_stm32::Peripherals;
12use embassy_traits::uart::Write as _;
13use example_common::*; 12use example_common::*;
14use heapless::String; 13use heapless::String;
15 14
diff --git a/examples/stm32wb55/src/bin/blinky.rs b/examples/stm32wb55/src/bin/blinky.rs
index 42522fe9b..e1dbb30de 100644
--- a/examples/stm32wb55/src/bin/blinky.rs
+++ b/examples/stm32wb55/src/bin/blinky.rs
@@ -8,7 +8,6 @@ use embassy::executor::Spawner;
8use embassy::time::{Duration, Timer}; 8use embassy::time::{Duration, Timer};
9use embassy_stm32::gpio::{Level, Output, Speed}; 9use embassy_stm32::gpio::{Level, Output, Speed};
10use embassy_stm32::Peripherals; 10use embassy_stm32::Peripherals;
11use embedded_hal::digital::v2::OutputPin;
12use example_common::*; 11use example_common::*;
13 12
14#[embassy::main] 13#[embassy::main]
@@ -19,11 +18,11 @@ async fn main(_spawner: Spawner, p: Peripherals) {
19 18
20 loop { 19 loop {
21 info!("high"); 20 info!("high");
22 unwrap!(led.set_high()); 21 led.set_high();
23 Timer::after(Duration::from_millis(500)).await; 22 Timer::after(Duration::from_millis(500)).await;
24 23
25 info!("low"); 24 info!("low");
26 unwrap!(led.set_low()); 25 led.set_low();
27 Timer::after(Duration::from_millis(500)).await; 26 Timer::after(Duration::from_millis(500)).await;
28 } 27 }
29} 28}
diff --git a/examples/stm32wb55/src/bin/button_exti.rs b/examples/stm32wb55/src/bin/button_exti.rs
index aeb7bd8a6..4592fa308 100644
--- a/examples/stm32wb55/src/bin/button_exti.rs
+++ b/examples/stm32wb55/src/bin/button_exti.rs
@@ -8,7 +8,6 @@ use embassy::executor::Spawner;
8use embassy_stm32::exti::ExtiInput; 8use embassy_stm32::exti::ExtiInput;
9use embassy_stm32::gpio::{Input, Pull}; 9use embassy_stm32::gpio::{Input, Pull};
10use embassy_stm32::Peripherals; 10use embassy_stm32::Peripherals;
11use embassy_traits::gpio::{WaitForFallingEdge, WaitForRisingEdge};
12use example_common::*; 11use example_common::*;
13 12
14#[embassy::main] 13#[embassy::main]
diff --git a/examples/stm32wl55/src/bin/blinky.rs b/examples/stm32wl55/src/bin/blinky.rs
index 3c12a79d0..9ec208c3d 100644
--- a/examples/stm32wl55/src/bin/blinky.rs
+++ b/examples/stm32wl55/src/bin/blinky.rs
@@ -8,7 +8,6 @@ use embassy::executor::Spawner;
8use embassy::time::{Duration, Timer}; 8use embassy::time::{Duration, Timer};
9use embassy_stm32::gpio::{Level, Output, Speed}; 9use embassy_stm32::gpio::{Level, Output, Speed};
10use embassy_stm32::Peripherals; 10use embassy_stm32::Peripherals;
11use embedded_hal::digital::v2::OutputPin;
12use example_common::*; 11use example_common::*;
13 12
14#[embassy::main] 13#[embassy::main]
@@ -19,11 +18,11 @@ async fn main(_spawner: Spawner, p: Peripherals) {
19 18
20 loop { 19 loop {
21 info!("high"); 20 info!("high");
22 unwrap!(led.set_high()); 21 led.set_high();
23 Timer::after(Duration::from_millis(500)).await; 22 Timer::after(Duration::from_millis(500)).await;
24 23
25 info!("low"); 24 info!("low");
26 unwrap!(led.set_low()); 25 led.set_low();
27 Timer::after(Duration::from_millis(500)).await; 26 Timer::after(Duration::from_millis(500)).await;
28 } 27 }
29} 28}
diff --git a/examples/stm32wl55/src/bin/button.rs b/examples/stm32wl55/src/bin/button.rs
index 55b688663..be8f60e26 100644
--- a/examples/stm32wl55/src/bin/button.rs
+++ b/examples/stm32wl55/src/bin/button.rs
@@ -5,7 +5,6 @@
5#[path = "../example_common.rs"] 5#[path = "../example_common.rs"]
6mod example_common; 6mod example_common;
7use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; 7use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
8use embedded_hal::digital::v2::{InputPin, OutputPin};
9use example_common::*; 8use example_common::*;
10 9
11use cortex_m_rt::entry; 10use cortex_m_rt::entry;
@@ -21,12 +20,12 @@ fn main() -> ! {
21 let mut led2 = Output::new(p.PB9, Level::High, Speed::Low); 20 let mut led2 = Output::new(p.PB9, Level::High, Speed::Low);
22 21
23 loop { 22 loop {
24 if button.is_high().unwrap() { 23 if button.is_high() {
25 led1.set_high().unwrap(); 24 led1.set_high();
26 led2.set_low().unwrap(); 25 led2.set_low();
27 } else { 26 } else {
28 led1.set_low().unwrap(); 27 led1.set_low();
29 led2.set_high().unwrap(); 28 led2.set_high();
30 } 29 }
31 } 30 }
32} 31}
diff --git a/examples/stm32wl55/src/bin/button_exti.rs b/examples/stm32wl55/src/bin/button_exti.rs
index 31adfb5d1..8d66c7258 100644
--- a/examples/stm32wl55/src/bin/button_exti.rs
+++ b/examples/stm32wl55/src/bin/button_exti.rs
@@ -8,7 +8,6 @@ use embassy::executor::Spawner;
8use embassy_stm32::exti::ExtiInput; 8use embassy_stm32::exti::ExtiInput;
9use embassy_stm32::gpio::{Input, Pull}; 9use embassy_stm32::gpio::{Input, Pull};
10use embassy_stm32::Peripherals; 10use embassy_stm32::Peripherals;
11use embassy_traits::gpio::{WaitForFallingEdge, WaitForRisingEdge};
12use example_common::*; 11use example_common::*;
13 12
14#[embassy::main] 13#[embassy::main]
diff --git a/examples/stm32wl55/src/bin/subghz.rs b/examples/stm32wl55/src/bin/subghz.rs
index 52fe6e9fa..42d4eb64c 100644
--- a/examples/stm32wl55/src/bin/subghz.rs
+++ b/examples/stm32wl55/src/bin/subghz.rs
@@ -10,14 +10,12 @@ mod example_common;
10 10
11use embassy::channel::signal::Signal; 11use embassy::channel::signal::Signal;
12use embassy::interrupt::{Interrupt, InterruptExt}; 12use embassy::interrupt::{Interrupt, InterruptExt};
13use embassy::traits::gpio::WaitForRisingEdge;
14use embassy_stm32::dma::NoDma; 13use embassy_stm32::dma::NoDma;
15use embassy_stm32::exti::ExtiInput; 14use embassy_stm32::exti::ExtiInput;
16use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; 15use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
17use embassy_stm32::interrupt; 16use embassy_stm32::interrupt;
18use embassy_stm32::subghz::*; 17use embassy_stm32::subghz::*;
19use embassy_stm32::Peripherals; 18use embassy_stm32::Peripherals;
20use embedded_hal::digital::v2::OutputPin;
21use example_common::unwrap; 19use example_common::unwrap;
22 20
23const PING_DATA: &str = "PING"; 21const PING_DATA: &str = "PING";
@@ -89,9 +87,9 @@ async fn main(_spawner: embassy::executor::Spawner, p: Peripherals) {
89 87
90 defmt::info!("Radio ready for use"); 88 defmt::info!("Radio ready for use");
91 89
92 unwrap!(led1.set_low()); 90 led1.set_low();
93 91
94 unwrap!(led2.set_high()); 92 led2.set_high();
95 93
96 unwrap!(radio.set_standby(StandbyClk::Rc)); 94 unwrap!(radio.set_standby(StandbyClk::Rc));
97 unwrap!(radio.set_tcxo_mode(&TCXO_MODE)); 95 unwrap!(radio.set_tcxo_mode(&TCXO_MODE));
@@ -110,11 +108,11 @@ async fn main(_spawner: embassy::executor::Spawner, p: Peripherals) {
110 108
111 defmt::info!("Status: {:?}", unwrap!(radio.status())); 109 defmt::info!("Status: {:?}", unwrap!(radio.status()));
112 110
113 unwrap!(led2.set_low()); 111 led2.set_low();
114 112
115 loop { 113 loop {
116 pin.wait_for_rising_edge().await; 114 pin.wait_for_rising_edge().await;
117 unwrap!(led3.set_high()); 115 led3.set_high();
118 unwrap!(radio.set_irq_cfg(&CfgIrq::new().irq_enable_all(Irq::TxDone))); 116 unwrap!(radio.set_irq_cfg(&CfgIrq::new().irq_enable_all(Irq::TxDone)));
119 unwrap!(radio.write_buffer(TX_BUF_OFFSET, PING_DATA_BYTES)); 117 unwrap!(radio.write_buffer(TX_BUF_OFFSET, PING_DATA_BYTES));
120 unwrap!(radio.set_tx(Timeout::DISABLED)); 118 unwrap!(radio.set_tx(Timeout::DISABLED));
@@ -127,6 +125,6 @@ async fn main(_spawner: embassy::executor::Spawner, p: Peripherals) {
127 defmt::info!("TX done"); 125 defmt::info!("TX done");
128 } 126 }
129 unwrap!(radio.clear_irq_status(irq_status)); 127 unwrap!(radio.clear_irq_status(irq_status));
130 unwrap!(led3.set_low()); 128 led3.set_low();
131 } 129 }
132} 130}
diff --git a/tests/stm32/src/bin/gpio.rs b/tests/stm32/src/bin/gpio.rs
index 51ede6cea..305da8d12 100644
--- a/tests/stm32/src/bin/gpio.rs
+++ b/tests/stm32/src/bin/gpio.rs
@@ -8,7 +8,6 @@ use defmt::assert;
8use embassy::executor::Spawner; 8use embassy::executor::Spawner;
9use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; 9use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
10use embassy_stm32::Peripherals; 10use embassy_stm32::Peripherals;
11use embedded_hal::digital::v2::{InputPin, OutputPin};
12use example_common::*; 11use example_common::*;
13 12
14#[embassy::main(config = "config()")] 13#[embassy::main(config = "config()")]
@@ -35,12 +34,12 @@ async fn main(_spawner: Spawner, p: Peripherals) {
35 { 34 {
36 let _a = Output::new(&mut a, Level::Low, Speed::Low); 35 let _a = Output::new(&mut a, Level::Low, Speed::Low);
37 delay(); 36 delay();
38 assert!(b.is_low().unwrap()); 37 assert!(b.is_low());
39 } 38 }
40 { 39 {
41 let _a = Output::new(&mut a, Level::High, Speed::Low); 40 let _a = Output::new(&mut a, Level::High, Speed::Low);
42 delay(); 41 delay();
43 assert!(b.is_high().unwrap()); 42 assert!(b.is_high());
44 } 43 }
45 } 44 }
46 45
@@ -51,38 +50,38 @@ async fn main(_spawner: Spawner, p: Peripherals) {
51 50
52 let mut a = Output::new(&mut a, Level::Low, Speed::Low); 51 let mut a = Output::new(&mut a, Level::Low, Speed::Low);
53 delay(); 52 delay();
54 assert!(b.is_low().unwrap()); 53 assert!(b.is_low());
55 a.set_high().unwrap(); 54 a.set_high();
56 delay(); 55 delay();
57 assert!(b.is_high().unwrap()); 56 assert!(b.is_high());
58 } 57 }
59 58
60 // Test input pulldown 59 // Test input pulldown
61 { 60 {
62 let b = Input::new(&mut b, Pull::Down); 61 let b = Input::new(&mut b, Pull::Down);
63 delay(); 62 delay();
64 assert!(b.is_low().unwrap()); 63 assert!(b.is_low());
65 64
66 let mut a = Output::new(&mut a, Level::Low, Speed::Low); 65 let mut a = Output::new(&mut a, Level::Low, Speed::Low);
67 delay(); 66 delay();
68 assert!(b.is_low().unwrap()); 67 assert!(b.is_low());
69 a.set_high().unwrap(); 68 a.set_high();
70 delay(); 69 delay();
71 assert!(b.is_high().unwrap()); 70 assert!(b.is_high());
72 } 71 }
73 72
74 // Test input pullup 73 // Test input pullup
75 { 74 {
76 let b = Input::new(&mut b, Pull::Up); 75 let b = Input::new(&mut b, Pull::Up);
77 delay(); 76 delay();
78 assert!(b.is_high().unwrap()); 77 assert!(b.is_high());
79 78
80 let mut a = Output::new(&mut a, Level::Low, Speed::Low); 79 let mut a = Output::new(&mut a, Level::Low, Speed::Low);
81 delay(); 80 delay();
82 assert!(b.is_low().unwrap()); 81 assert!(b.is_low());
83 a.set_high().unwrap(); 82 a.set_high();
84 delay(); 83 delay();
85 assert!(b.is_high().unwrap()); 84 assert!(b.is_high());
86 } 85 }
87 86
88 info!("Test OK"); 87 info!("Test OK");
diff --git a/tests/stm32/src/bin/spi.rs b/tests/stm32/src/bin/spi.rs
index 043505c7b..47d0017ac 100644
--- a/tests/stm32/src/bin/spi.rs
+++ b/tests/stm32/src/bin/spi.rs
@@ -10,7 +10,6 @@ use embassy_stm32::dma::NoDma;
10use embassy_stm32::spi::{self, Spi}; 10use embassy_stm32::spi::{self, Spi};
11use embassy_stm32::time::Hertz; 11use embassy_stm32::time::Hertz;
12use embassy_stm32::Peripherals; 12use embassy_stm32::Peripherals;
13use embedded_hal::blocking::spi::Transfer;
14use example_common::*; 13use example_common::*;
15 14
16#[embassy::main(config = "config()")] 15#[embassy::main(config = "config()")]
@@ -38,7 +37,7 @@ async fn main(_spawner: Spawner, p: Peripherals) {
38 // Arduino pins D11 and D12 (MOSI-MISO) are connected together with a 1K resistor. 37 // Arduino pins D11 and D12 (MOSI-MISO) are connected together with a 1K resistor.
39 // so we should get the data we sent back. 38 // so we should get the data we sent back.
40 let mut buf = data; 39 let mut buf = data;
41 spi.transfer(&mut buf).unwrap(); 40 spi.blocking_transfer_in_place(&mut buf).unwrap();
42 assert_eq!(buf, data); 41 assert_eq!(buf, data);
43 42
44 info!("Test OK"); 43 info!("Test OK");
diff --git a/tests/stm32/src/bin/usart.rs b/tests/stm32/src/bin/usart.rs
index f887b084a..44ee730e4 100644
--- a/tests/stm32/src/bin/usart.rs
+++ b/tests/stm32/src/bin/usart.rs
@@ -9,7 +9,6 @@ use embassy::executor::Spawner;
9use embassy_stm32::dma::NoDma; 9use embassy_stm32::dma::NoDma;
10use embassy_stm32::usart::{Config, Uart}; 10use embassy_stm32::usart::{Config, Uart};
11use embassy_stm32::Peripherals; 11use embassy_stm32::Peripherals;
12use embedded_hal::blocking::serial::Write;
13use example_common::*; 12use example_common::*;
14 13
15#[embassy::main(config = "config()")] 14#[embassy::main(config = "config()")]
@@ -42,10 +41,10 @@ async fn main(_spawner: Spawner, p: Peripherals) {
42 // This is because we aren't sending+receiving at the same time. 41 // This is because we aren't sending+receiving at the same time.
43 42
44 let data = [0xC0, 0xDE]; 43 let data = [0xC0, 0xDE];
45 usart.bwrite_all(&data).unwrap(); 44 usart.blocking_write(&data).unwrap();
46 45
47 let mut buf = [0; 2]; 46 let mut buf = [0; 2];
48 usart.read_blocking(&mut buf).unwrap(); 47 usart.blocking_read(&mut buf).unwrap();
49 assert_eq!(buf, data); 48 assert_eq!(buf, data);
50 49
51 info!("Test OK"); 50 info!("Test OK");
diff --git a/tests/stm32/src/bin/usart_dma.rs b/tests/stm32/src/bin/usart_dma.rs
index 96c6a6640..37faaf376 100644
--- a/tests/stm32/src/bin/usart_dma.rs
+++ b/tests/stm32/src/bin/usart_dma.rs
@@ -8,7 +8,6 @@ use defmt::assert_eq;
8use embassy::executor::Spawner; 8use embassy::executor::Spawner;
9use embassy_stm32::usart::{Config, Uart}; 9use embassy_stm32::usart::{Config, Uart};
10use embassy_stm32::Peripherals; 10use embassy_stm32::Peripherals;
11use embassy_traits::uart::{Read, Write};
12use example_common::*; 11use example_common::*;
13 12
14#[embassy::main(config = "config()")] 13#[embassy::main(config = "config()")]
diff --git a/tests/stm32/teleprobe.sh b/tests/stm32/teleprobe.sh
new file mode 100755
index 000000000..6eec6ca93
--- /dev/null
+++ b/tests/stm32/teleprobe.sh
@@ -0,0 +1,12 @@
1echo Running target=$1 elf=$2
2STATUSCODE=$(
3 curl \
4 -sS \
5 --output /dev/stderr \
6 --write-out "%{http_code}" \
7 -H "Authorization: Bearer $TELEPROBE_TOKEN" \
8 https://teleprobe.embassy.dev/targets/$1/run --data-binary @$2
9)
10echo
11echo HTTP Status code: $STATUSCODE
12test "$STATUSCODE" -eq 200