2020-12-31 03:24:32 +00:00
|
|
|
#![no_std]
|
|
|
|
#![no_main]
|
|
|
|
#![feature(trait_alias)]
|
|
|
|
#![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;
|
|
|
|
use embassy::executor::{task, Executor};
|
2021-01-06 20:31:43 +00:00
|
|
|
use embassy::uart::Uart;
|
2020-12-31 03:24:32 +00:00
|
|
|
use embassy::util::Forever;
|
2020-12-31 22:59:42 +00:00
|
|
|
use embassy_stm32f4::interrupt;
|
2020-12-31 03:24:32 +00:00
|
|
|
use embassy_stm32f4::serial;
|
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;
|
|
|
|
use stm32f4xx_hal::{prelude::*, serial::config};
|
|
|
|
|
|
|
|
#[task]
|
|
|
|
async fn run(dp: stm32::Peripherals, cp: cortex_m::Peripherals) {
|
|
|
|
// https://gist.github.com/thalesfragoso/a07340c5df6eee3b04c42fdc69ecdcb1
|
|
|
|
let gpioa = dp.GPIOA.split();
|
|
|
|
let rcc = dp.RCC.constrain();
|
|
|
|
|
|
|
|
let clocks = rcc
|
|
|
|
.cfgr
|
|
|
|
.use_hse(16.mhz())
|
|
|
|
.sysclk(48.mhz())
|
|
|
|
.pclk1(24.mhz())
|
|
|
|
.freeze();
|
|
|
|
|
2021-01-07 03:02:02 +00:00
|
|
|
let mut serial = unsafe {
|
|
|
|
serial::Serial::new(
|
2021-01-14 17:42:23 +00:00
|
|
|
dp.USART1,
|
|
|
|
dp.DMA2,
|
|
|
|
(
|
|
|
|
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
|
|
|
)
|
|
|
|
};
|
|
|
|
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-01-13 23:53:05 +00:00
|
|
|
serial.send(buf).await.unwrap();
|
2020-12-31 03:24:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static EXECUTOR: Forever<Executor> = Forever::new();
|
|
|
|
|
|
|
|
#[entry]
|
|
|
|
fn main() -> ! {
|
|
|
|
let dp = stm32::Peripherals::take().unwrap();
|
|
|
|
let cp = cortex_m::peripheral::Peripherals::take().unwrap();
|
|
|
|
|
2021-02-02 04:14:52 +00:00
|
|
|
let executor = EXECUTOR.put(Executor::new());
|
|
|
|
executor.run(|spawner| {
|
|
|
|
unwrap!(spawner.spawn(run(dp, cp)));
|
|
|
|
});
|
2020-12-31 03:24:32 +00:00
|
|
|
}
|