commit
28fe29fff3
2 changed files with 20 additions and 27 deletions
|
@ -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,
|
||||
)
|
||||
};
|
||||
|
|
|
@ -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<USART1, Stream7<DMA2>, Stream2<DMA2>> = ptr::
|
|||
|
||||
impl Serial<USART1, Stream7<DMA2>, Stream2<DMA2>> {
|
||||
// Leaking futures is forbidden!
|
||||
pub unsafe fn new(
|
||||
txd: PA9<Alternate<AF7>>,
|
||||
rxd: PA10<Alternate<AF7>>,
|
||||
pub unsafe fn new<PINS>(
|
||||
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<USART1>,
|
||||
{
|
||||
config.dma = SerialDmaConfig::TxRx;
|
||||
let mut serial = HalSerial::usart1(usart, pins, config, clocks).unwrap();
|
||||
|
||||
serial.listen(SerialEvent::Idle);
|
||||
// serial.listen(SerialEvent::Txe);
|
||||
|
|
Loading…
Reference in a new issue