stm32/usart: disconnect pins of RingBufferedUartRx on drop
This commit is contained in:
parent
41711195e3
commit
ade27b7f21
@ -4,10 +4,12 @@ use core::sync::atomic::{compiler_fence, Ordering};
|
|||||||
use core::task::Poll;
|
use core::task::Poll;
|
||||||
|
|
||||||
use embassy_embedded_hal::SetConfig;
|
use embassy_embedded_hal::SetConfig;
|
||||||
|
use embassy_hal_internal::PeripheralRef;
|
||||||
use futures_util::future::{select, Either};
|
use futures_util::future::{select, Either};
|
||||||
|
|
||||||
use super::{clear_interrupt_flags, rdr, reconfigure, sr, Config, ConfigError, Error, Info, State, UartRx};
|
use super::{clear_interrupt_flags, rdr, reconfigure, sr, Config, ConfigError, Error, Info, State, UartRx};
|
||||||
use crate::dma::ReadableRingBuffer;
|
use crate::dma::ReadableRingBuffer;
|
||||||
|
use crate::gpio::{AnyPin, SealedPin as _};
|
||||||
use crate::mode::Async;
|
use crate::mode::Async;
|
||||||
use crate::time::Hertz;
|
use crate::time::Hertz;
|
||||||
use crate::usart::{Regs, Sr};
|
use crate::usart::{Regs, Sr};
|
||||||
@ -19,6 +21,8 @@ pub struct RingBufferedUartRx<'d> {
|
|||||||
info: &'static Info,
|
info: &'static Info,
|
||||||
state: &'static State,
|
state: &'static State,
|
||||||
kernel_clock: Hertz,
|
kernel_clock: Hertz,
|
||||||
|
rx: Option<PeripheralRef<'d, AnyPin>>,
|
||||||
|
rts: Option<PeripheralRef<'d, AnyPin>>,
|
||||||
ring_buf: ReadableRingBuffer<'d, u8>,
|
ring_buf: ReadableRingBuffer<'d, u8>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,6 +53,8 @@ impl<'d> UartRx<'d, Async> {
|
|||||||
let state = self.state;
|
let state = self.state;
|
||||||
let kernel_clock = self.kernel_clock;
|
let kernel_clock = self.kernel_clock;
|
||||||
let ring_buf = unsafe { ReadableRingBuffer::new(rx_dma, request, rdr(info.regs), dma_buf, opts) };
|
let ring_buf = unsafe { ReadableRingBuffer::new(rx_dma, request, rdr(info.regs), dma_buf, opts) };
|
||||||
|
let rx = unsafe { self.rx.as_ref().map(|x| x.clone_unchecked()) };
|
||||||
|
let rts = unsafe { self.rts.as_ref().map(|x| x.clone_unchecked()) };
|
||||||
|
|
||||||
// Don't disable the clock
|
// Don't disable the clock
|
||||||
mem::forget(self);
|
mem::forget(self);
|
||||||
@ -57,6 +63,8 @@ impl<'d> UartRx<'d, Async> {
|
|||||||
info,
|
info,
|
||||||
state,
|
state,
|
||||||
kernel_clock,
|
kernel_clock,
|
||||||
|
rx,
|
||||||
|
rts,
|
||||||
ring_buf,
|
ring_buf,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -221,6 +229,8 @@ impl<'d> RingBufferedUartRx<'d> {
|
|||||||
impl Drop for RingBufferedUartRx<'_> {
|
impl Drop for RingBufferedUartRx<'_> {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
self.teardown_uart();
|
self.teardown_uart();
|
||||||
|
self.rx.as_ref().map(|x| x.set_as_disconnected());
|
||||||
|
self.rts.as_ref().map(|x| x.set_as_disconnected());
|
||||||
super::drop_tx_rx(self.info, self.state);
|
super::drop_tx_rx(self.info, self.state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user