2020-12-31 03:24:32 +00:00
|
|
|
#![no_std]
|
|
|
|
#![no_main]
|
|
|
|
#![feature(trait_alias)]
|
2021-03-17 01:48:16 +00:00
|
|
|
#![feature(min_type_alias_impl_trait)]
|
|
|
|
#![feature(impl_trait_in_bindings)]
|
2020-12-31 03:24:32 +00:00
|
|
|
#![feature(type_alias_impl_trait)]
|
|
|
|
|
2021-01-13 23:53:05 +00:00
|
|
|
#[path = "../example_common.rs"]
|
|
|
|
mod example_common;
|
|
|
|
use example_common::{panic, *};
|
2020-12-31 03:24:32 +00:00
|
|
|
|
|
|
|
use cortex_m::singleton;
|
|
|
|
use cortex_m_rt::entry;
|
2021-03-29 14:18:48 +00:00
|
|
|
use embassy::executor::{Executor, Spawner};
|
2021-04-02 00:05:44 +00:00
|
|
|
use embassy::traits::uart::{Read, ReadUntilIdle, Write};
|
2020-12-31 03:24:32 +00:00
|
|
|
use embassy::util::Forever;
|
2021-03-30 15:05:52 +00:00
|
|
|
use embassy_stm32::interrupt;
|
|
|
|
use embassy_stm32::serial;
|
2021-03-28 23:14:18 +00:00
|
|
|
use futures::pin_mut;
|
2021-03-04 23:20:35 +00:00
|
|
|
use stm32f4xx_hal::dma::StreamsTuple;
|
2021-02-14 00:41:36 +00:00
|
|
|
use stm32f4xx_hal::prelude::*;
|
2021-01-14 17:42:23 +00:00
|
|
|
use stm32f4xx_hal::serial::config::Config;
|
2020-12-31 03:24:32 +00:00
|
|
|
use stm32f4xx_hal::stm32;
|
|
|
|
|
2021-03-29 14:18:48 +00:00
|
|
|
#[embassy::main(use_hse = 16, sysclk = 48, pclk1 = 24)]
|
|
|
|
async fn main(spawner: Spawner) {
|
|
|
|
let (dp, clocks) = embassy_stm32::Peripherals::take().unwrap();
|
|
|
|
let cp = cortex_m::peripheral::Peripherals::take().unwrap();
|
|
|
|
|
2021-02-20 00:29:26 +00:00
|
|
|
dp.DBGMCU.cr.modify(|_, w| {
|
|
|
|
w.dbg_sleep().set_bit();
|
|
|
|
w.dbg_standby().set_bit();
|
|
|
|
w.dbg_stop().set_bit()
|
|
|
|
});
|
|
|
|
|
2020-12-31 03:24:32 +00:00
|
|
|
// https://gist.github.com/thalesfragoso/a07340c5df6eee3b04c42fdc69ecdcb1
|
|
|
|
let gpioa = dp.GPIOA.split();
|
2021-03-04 23:20:35 +00:00
|
|
|
let streams = StreamsTuple::new(dp.DMA2);
|
|
|
|
|
2021-03-19 01:23:09 +00:00
|
|
|
let _serial = unsafe {
|
2021-01-07 03:02:02 +00:00
|
|
|
serial::Serial::new(
|
2021-01-14 17:42:23 +00:00
|
|
|
dp.USART1,
|
2021-03-04 23:20:35 +00:00
|
|
|
(streams.7, streams.2),
|
2021-01-14 17:42:23 +00:00
|
|
|
(
|
|
|
|
gpioa.pa9.into_alternate_af7(),
|
|
|
|
gpioa.pa10.into_alternate_af7(),
|
|
|
|
),
|
2021-01-06 20:31:43 +00:00
|
|
|
interrupt::take!(DMA2_STREAM7),
|
|
|
|
interrupt::take!(DMA2_STREAM2),
|
|
|
|
interrupt::take!(USART1),
|
2021-01-14 17:42:23 +00:00
|
|
|
Config::default().baudrate(9600.bps()),
|
2021-01-06 20:31:43 +00:00
|
|
|
clocks,
|
2021-01-07 03:02:02 +00:00
|
|
|
)
|
|
|
|
};
|
2021-03-04 23:20:35 +00:00
|
|
|
|
|
|
|
let streams = StreamsTuple::new(dp.DMA1);
|
|
|
|
|
|
|
|
let mut serial = unsafe {
|
|
|
|
serial::Serial::new(
|
|
|
|
dp.USART2,
|
|
|
|
(streams.6, streams.5),
|
|
|
|
(
|
|
|
|
gpioa.pa2.into_alternate_af7(),
|
|
|
|
gpioa.pa3.into_alternate_af7(),
|
|
|
|
),
|
|
|
|
interrupt::take!(DMA1_STREAM6),
|
|
|
|
interrupt::take!(DMA1_STREAM5),
|
|
|
|
interrupt::take!(USART2),
|
|
|
|
Config::default().baudrate(9600.bps()),
|
|
|
|
clocks,
|
|
|
|
)
|
|
|
|
};
|
2021-03-28 23:14:18 +00:00
|
|
|
pin_mut!(serial);
|
|
|
|
|
2021-01-07 03:02:02 +00:00
|
|
|
let buf = singleton!(: [u8; 30] = [0; 30]).unwrap();
|
2020-12-31 03:24:32 +00:00
|
|
|
|
2021-01-07 03:02:02 +00:00
|
|
|
buf[5] = 0x01;
|
2021-04-02 00:03:55 +00:00
|
|
|
serial.as_mut().write(buf).await.unwrap();
|
|
|
|
serial.as_mut().read_until_idle(buf);
|
2020-12-31 03:24:32 +00:00
|
|
|
}
|