Merge branch 'implement-uart' of ssh://github.com/xoviat/embassy into implement-uart

This commit is contained in:
xoviat 2021-01-12 14:00:39 -06:00
commit c07f7467a0
2 changed files with 53 additions and 57 deletions

View File

@ -28,8 +28,8 @@ async fn run(dp: stm32::Peripherals, cp: cortex_m::Peripherals) {
.pclk1(24.mhz()) .pclk1(24.mhz())
.freeze(); .freeze();
unsafe { let mut serial = unsafe {
let mut serial = serial::Serial::new( serial::Serial::new(
gpioa.pa9.into_alternate_af7(), gpioa.pa9.into_alternate_af7(),
gpioa.pa10.into_alternate_af7(), gpioa.pa10.into_alternate_af7(),
interrupt::take!(DMA2_STREAM7), interrupt::take!(DMA2_STREAM7),
@ -40,13 +40,13 @@ async fn run(dp: stm32::Peripherals, cp: cortex_m::Peripherals) {
config::Parity::ParityNone, config::Parity::ParityNone,
9600.bps(), 9600.bps(),
clocks, clocks,
); )
};
let buf = singleton!(: [u8; 30] = [0; 30]).unwrap(); let buf = singleton!(: [u8; 30] = [0; 30]).unwrap();
buf[5] = 0x01; buf[5] = 0x01;
serial.send(buf).await; serial.send(buf).await;
} }
}
static EXECUTOR: Forever<Executor> = Forever::new(); static EXECUTOR: Forever<Executor> = Forever::new();

View File

@ -152,8 +152,7 @@ impl Uart for Serial<USART1, Stream7<DMA2>, Stream2<DMA2>> {
fn send<'a>(&'a mut self, buf: &'a [u8]) -> Self::SendFuture<'a> { fn send<'a>(&'a mut self, buf: &'a [u8]) -> Self::SendFuture<'a> {
unsafe { INSTANCE = self }; unsafe { INSTANCE = self };
unsafe { let static_buf = unsafe { core::mem::transmute::<&'a [u8], &'static mut [u8]>(buf) };
let static_buf = core::mem::transmute::<&'a [u8], &'static mut [u8]>(buf);
let tx_stream = self.tx_stream.take().unwrap(); let tx_stream = self.tx_stream.take().unwrap();
let usart = self.usart.take().unwrap(); let usart = self.usart.take().unwrap();
@ -184,7 +183,6 @@ impl Uart for Serial<USART1, Stream7<DMA2>, Stream2<DMA2>> {
Ok(()) Ok(())
} }
} }
}
/// Receives serial data. /// Receives serial data.
/// ///
@ -199,8 +197,7 @@ impl Uart for Serial<USART1, Stream7<DMA2>, Stream2<DMA2>> {
fn receive<'a>(&'a mut self, buf: &'a mut [u8]) -> Self::ReceiveFuture<'a> { fn receive<'a>(&'a mut self, buf: &'a mut [u8]) -> Self::ReceiveFuture<'a> {
unsafe { INSTANCE = self }; unsafe { INSTANCE = self };
unsafe { let static_buf = unsafe { core::mem::transmute::<&'a mut [u8], &'static mut [u8]>(buf) };
let static_buf = core::mem::transmute::<&'a mut [u8], &'static mut [u8]>(buf);
let rx_stream = self.rx_stream.take().unwrap(); let rx_stream = self.rx_stream.take().unwrap();
let usart = self.usart.take().unwrap(); let usart = self.usart.take().unwrap();
STATE.rx_int.reset(); STATE.rx_int.reset();
@ -219,11 +216,10 @@ impl Uart for Serial<USART1, Stream7<DMA2>, Stream2<DMA2>> {
self.rx_int.enable(); self.rx_int.enable();
rx_transfer.start(|_usart| {}); rx_transfer.start(|_usart| {});
STATE.rx_int.wait().await; STATE.rx_int.wait().await;
let (rx_stream, usart, buf, _) = rx_transfer.free(); let (rx_stream, usart, _, _) = rx_transfer.free();
self.rx_stream.replace(rx_stream); self.rx_stream.replace(rx_stream);
self.usart.replace(usart); self.usart.replace(usart);
Ok(()) Ok(())
} }
} }
} }
}