From 31ba052f14b9573cfa5669a06b04da451c091ff6 Mon Sep 17 00:00:00 2001 From: xoviat Date: Wed, 6 Jan 2021 14:31:43 -0600 Subject: [PATCH] mark new unsafe --- embassy-stm32f4-examples/src/serial.rs | 35 +++++++++++++------------- embassy-stm32f4/src/serial.rs | 3 ++- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/embassy-stm32f4-examples/src/serial.rs b/embassy-stm32f4-examples/src/serial.rs index baed2e52..11a5b890 100644 --- a/embassy-stm32f4-examples/src/serial.rs +++ b/embassy-stm32f4-examples/src/serial.rs @@ -8,6 +8,7 @@ use cortex_m::singleton; use cortex_m_rt::entry; use embassy::executor::{task, Executor}; +use embassy::uart::Uart; use embassy::util::Forever; use embassy_stm32f4::interrupt; use embassy_stm32f4::serial; @@ -27,24 +28,24 @@ async fn run(dp: stm32::Peripherals, cp: cortex_m::Peripherals) { .pclk1(24.mhz()) .freeze(); - let mut serial = serial::Serial::new( - 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(), - clocks, - ); + unsafe { + let mut serial = serial::Serial::new( + 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(), + clocks, + ); + let buf = singleton!(: [u8; 30] = [0; 30]).unwrap(); - let buf = singleton!(: [u8; 30] = [0; 30]).unwrap(); - - buf[5] = 0x01; - - serial.send(buf).await; + buf[5] = 0x01; + serial.send(buf).await; + } } static EXECUTOR: Forever = Forever::new(); diff --git a/embassy-stm32f4/src/serial.rs b/embassy-stm32f4/src/serial.rs index a34db9de..b1343827 100644 --- a/embassy-stm32f4/src/serial.rs +++ b/embassy-stm32f4/src/serial.rs @@ -57,7 +57,8 @@ static STATE: State = State { static mut INSTANCE: *const Serial, Stream2> = ptr::null_mut(); impl Serial, Stream2> { - pub fn new( + // Leaking futures is forbidden! + pub unsafe fn new( txd: PA9>, rxd: PA10>, tx_int: interrupt::DMA2_STREAM7Interrupt,