diff --git a/embassy-stm32f4-examples/src/bin/serial.rs b/embassy-stm32f4-examples/src/bin/serial.rs index f3e0526c..c0c71bec 100644 --- a/embassy-stm32f4-examples/src/bin/serial.rs +++ b/embassy-stm32f4-examples/src/bin/serial.rs @@ -14,6 +14,7 @@ use embassy::uart::Uart; use embassy::util::Forever; use embassy_stm32f4::interrupt; use embassy_stm32f4::serial; +use stm32f4xx_hal::serial::config::Config; use stm32f4xx_hal::stm32; use stm32f4xx_hal::{prelude::*, serial::config}; @@ -32,15 +33,16 @@ async fn run(dp: stm32::Peripherals, cp: cortex_m::Peripherals) { let mut serial = unsafe { serial::Serial::new( - gpioa.pa9.into_alternate_af7(), - gpioa.pa10.into_alternate_af7(), + dp.USART1, + dp.DMA2, + ( + gpioa.pa9.into_alternate_af7(), + gpioa.pa10.into_alternate_af7(), + ), interrupt::take!(DMA2_STREAM7), interrupt::take!(DMA2_STREAM2), interrupt::take!(USART1), - dp.DMA2, - dp.USART1, - config::Parity::ParityNone, - 9600.bps(), + Config::default().baudrate(9600.bps()), clocks, ) }; diff --git a/embassy-stm32f4/src/serial.rs b/embassy-stm32f4/src/serial.rs index 7590fe65..f73c1b7c 100644 --- a/embassy-stm32f4/src/serial.rs +++ b/embassy-stm32f4/src/serial.rs @@ -26,6 +26,7 @@ use crate::hal::rcc::Clocks; use crate::hal::serial::config::{ Config as SerialConfig, DmaConfig as SerialDmaConfig, Parity, StopBits, WordLength, }; +use crate::hal::serial::Pins; use crate::hal::serial::{Event as SerialEvent, Serial as HalSerial}; use crate::hal::time::Bps; @@ -58,31 +59,21 @@ static mut INSTANCE: *const Serial, Stream2> = ptr:: impl Serial, Stream2> { // Leaking futures is forbidden! - pub unsafe fn new( - txd: PA9>, - rxd: PA10>, + pub unsafe fn new( + usart: USART1, + dma: DMA2, + pins: PINS, tx_int: interrupt::DMA2_STREAM7Interrupt, rx_int: interrupt::DMA2_STREAM2Interrupt, usart_int: interrupt::USART1Interrupt, - dma: DMA2, - usart: USART1, - parity: Parity, - baudrate: Bps, + mut config: SerialConfig, clocks: Clocks, - ) -> Self { - let mut serial = HalSerial::usart1( - usart, - (txd, rxd), - SerialConfig { - baudrate: baudrate, - wordlength: WordLength::DataBits8, - parity: Parity::ParityNone, - stopbits: StopBits::STOP1, - dma: SerialDmaConfig::TxRx, - }, - clocks, - ) - .unwrap(); + ) -> Self + where + PINS: Pins, + { + config.dma = SerialDmaConfig::TxRx; + let mut serial = HalSerial::usart1(usart, pins, config, clocks).unwrap(); serial.listen(SerialEvent::Idle); // serial.listen(SerialEvent::Txe);