uarte: Enable peripheral with first poll

This fixes a lockup when a future is dropped before it was polled.
This commit is contained in:
Timo Kröger 2021-01-03 13:31:33 +01:00
parent 85ec9dd16f
commit 9b1f7b8a17

View File

@ -219,7 +219,6 @@ impl<T: Instance> embassy::uart::Uart for Uarte<T> {
assert!(!self.tx_started()); assert!(!self.tx_started());
T::state().tx_done.reset(); T::state().tx_done.reset();
self.enable();
SendFuture { SendFuture {
uarte: self, uarte: self,
@ -243,7 +242,6 @@ impl<T: Instance> embassy::uart::Uart for Uarte<T> {
assert!(!self.rx_started()); assert!(!self.rx_started());
T::state().rx_done.reset(); T::state().rx_done.reset();
self.enable();
ReceiveFuture { ReceiveFuture {
uarte: self, uarte: self,
@ -257,7 +255,7 @@ pub struct SendFuture<'a, T>
where where
T: Instance, T: Instance,
{ {
uarte: &'a Uarte<T>, uarte: &'a mut Uarte<T>,
buf: &'a [u8], buf: &'a [u8],
} }
@ -295,6 +293,8 @@ where
assert!(len <= EASY_DMA_SIZE); assert!(len <= EASY_DMA_SIZE);
// TODO: panic if buffer is not in SRAM // TODO: panic if buffer is not in SRAM
uarte.enable();
compiler_fence(Ordering::SeqCst); compiler_fence(Ordering::SeqCst);
uarte uarte
.instance .instance
@ -323,7 +323,7 @@ pub struct ReceiveFuture<'a, T>
where where
T: Instance, T: Instance,
{ {
uarte: &'a Uarte<T>, uarte: &'a mut Uarte<T>,
buf: &'a mut [u8], buf: &'a mut [u8],
} }
@ -360,6 +360,8 @@ where
let len = buf.len(); let len = buf.len();
assert!(len <= EASY_DMA_SIZE); assert!(len <= EASY_DMA_SIZE);
uarte.enable();
compiler_fence(Ordering::SeqCst); compiler_fence(Ordering::SeqCst);
uarte uarte
.instance .instance