aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embassy-stm32f4-examples/src/bin/serial.rs14
-rw-r--r--embassy-stm32f4/src/serial.rs33
2 files changed, 20 insertions, 27 deletions
diff --git a/embassy-stm32f4-examples/src/bin/serial.rs b/embassy-stm32f4-examples/src/bin/serial.rs
index f3e0526c4..c0c71bece 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;
14use embassy::util::Forever; 14use embassy::util::Forever;
15use embassy_stm32f4::interrupt; 15use embassy_stm32f4::interrupt;
16use embassy_stm32f4::serial; 16use embassy_stm32f4::serial;
17use stm32f4xx_hal::serial::config::Config;
17use stm32f4xx_hal::stm32; 18use stm32f4xx_hal::stm32;
18use stm32f4xx_hal::{prelude::*, serial::config}; 19use stm32f4xx_hal::{prelude::*, serial::config};
19 20
@@ -32,15 +33,16 @@ async fn run(dp: stm32::Peripherals, cp: cortex_m::Peripherals) {
32 33
33 let mut serial = unsafe { 34 let mut serial = unsafe {
34 serial::Serial::new( 35 serial::Serial::new(
35 gpioa.pa9.into_alternate_af7(), 36 dp.USART1,
36 gpioa.pa10.into_alternate_af7(), 37 dp.DMA2,
38 (
39 gpioa.pa9.into_alternate_af7(),
40 gpioa.pa10.into_alternate_af7(),
41 ),
37 interrupt::take!(DMA2_STREAM7), 42 interrupt::take!(DMA2_STREAM7),
38 interrupt::take!(DMA2_STREAM2), 43 interrupt::take!(DMA2_STREAM2),
39 interrupt::take!(USART1), 44 interrupt::take!(USART1),
40 dp.DMA2, 45 Config::default().baudrate(9600.bps()),
41 dp.USART1,
42 config::Parity::ParityNone,
43 9600.bps(),
44 clocks, 46 clocks,
45 ) 47 )
46 }; 48 };
diff --git a/embassy-stm32f4/src/serial.rs b/embassy-stm32f4/src/serial.rs
index 7590fe65a..f73c1b7c9 100644
--- a/embassy-stm32f4/src/serial.rs
+++ b/embassy-stm32f4/src/serial.rs
@@ -26,6 +26,7 @@ use crate::hal::rcc::Clocks;
26use crate::hal::serial::config::{ 26use crate::hal::serial::config::{
27 Config as SerialConfig, DmaConfig as SerialDmaConfig, Parity, StopBits, WordLength, 27 Config as SerialConfig, DmaConfig as SerialDmaConfig, Parity, StopBits, WordLength,
28}; 28};
29use crate::hal::serial::Pins;
29use crate::hal::serial::{Event as SerialEvent, Serial as HalSerial}; 30use crate::hal::serial::{Event as SerialEvent, Serial as HalSerial};
30use crate::hal::time::Bps; 31use crate::hal::time::Bps;
31 32
@@ -58,31 +59,21 @@ static mut INSTANCE: *const Serial<USART1, Stream7<DMA2>, Stream2<DMA2>> = ptr::
58 59
59impl Serial<USART1, Stream7<DMA2>, Stream2<DMA2>> { 60impl Serial<USART1, Stream7<DMA2>, Stream2<DMA2>> {
60 // Leaking futures is forbidden! 61 // Leaking futures is forbidden!
61 pub unsafe fn new( 62 pub unsafe fn new<PINS>(
62 txd: PA9<Alternate<AF7>>, 63 usart: USART1,
63 rxd: PA10<Alternate<AF7>>, 64 dma: DMA2,
65 pins: PINS,
64 tx_int: interrupt::DMA2_STREAM7Interrupt, 66 tx_int: interrupt::DMA2_STREAM7Interrupt,
65 rx_int: interrupt::DMA2_STREAM2Interrupt, 67 rx_int: interrupt::DMA2_STREAM2Interrupt,
66 usart_int: interrupt::USART1Interrupt, 68 usart_int: interrupt::USART1Interrupt,
67 dma: DMA2, 69 mut config: SerialConfig,
68 usart: USART1,
69 parity: Parity,
70 baudrate: Bps,
71 clocks: Clocks, 70 clocks: Clocks,
72 ) -> Self { 71 ) -> Self
73 let mut serial = HalSerial::usart1( 72 where
74 usart, 73 PINS: Pins<USART1>,
75 (txd, rxd), 74 {
76 SerialConfig { 75 config.dma = SerialDmaConfig::TxRx;
77 baudrate: baudrate, 76 let mut serial = HalSerial::usart1(usart, pins, config, clocks).unwrap();
78 wordlength: WordLength::DataBits8,
79 parity: Parity::ParityNone,
80 stopbits: StopBits::STOP1,
81 dma: SerialDmaConfig::TxRx,
82 },
83 clocks,
84 )
85 .unwrap();
86 77
87 serial.listen(SerialEvent::Idle); 78 serial.listen(SerialEvent::Idle);
88 // serial.listen(SerialEvent::Txe); 79 // serial.listen(SerialEvent::Txe);