make stm32f4 example work

This commit is contained in:
Philipp Scheff 2023-07-04 00:21:08 +02:00
parent e3e8d82933
commit 1869fe02ba

View File

@ -2,8 +2,8 @@
#![no_main] #![no_main]
#![feature(type_alias_impl_trait)] #![feature(type_alias_impl_trait)]
use cortex_m_rt::entry;
use defmt::*; use defmt::*;
use embassy_executor::Spawner;
use embassy_stm32::bind_interrupts; use embassy_stm32::bind_interrupts;
use embassy_stm32::can::bxcan::filter::Mask32; use embassy_stm32::can::bxcan::filter::Mask32;
use embassy_stm32::can::bxcan::{Fifo, Frame, StandardId}; use embassy_stm32::can::bxcan::{Fifo, Frame, StandardId};
@ -19,8 +19,8 @@ bind_interrupts!(struct Irqs {
CAN1_TX => TxInterruptHandler<CAN1>; CAN1_TX => TxInterruptHandler<CAN1>;
}); });
#[entry] #[embassy_executor::main]
fn main() -> ! { async fn main(_spawner: Spawner) {
info!("Hello World!"); info!("Hello World!");
let mut p = embassy_stm32::init(Default::default()); let mut p = embassy_stm32::init(Default::default());
@ -34,9 +34,12 @@ fn main() -> ! {
let mut can = Can::new(p.CAN1, p.PA11, p.PA12, Irqs); let mut can = Can::new(p.CAN1, p.PA11, p.PA12, Irqs);
can.modify_filters().enable_bank(0, Fifo::Fifo0, Mask32::accept_all()); can.as_mut()
.modify_filters()
.enable_bank(0, Fifo::Fifo0, Mask32::accept_all());
can.modify_config() can.as_mut()
.modify_config()
.set_bit_timing(0x001c0003) // http://www.bittiming.can-wiki.info/ .set_bit_timing(0x001c0003) // http://www.bittiming.can-wiki.info/
.set_loopback(true) // Receive own frames .set_loopback(true) // Receive own frames
.set_silent(true) .set_silent(true)
@ -45,9 +48,8 @@ fn main() -> ! {
let mut i: u8 = 0; let mut i: u8 = 0;
loop { loop {
let tx_frame = Frame::new_data(unwrap!(StandardId::new(i as _)), [i]); let tx_frame = Frame::new_data(unwrap!(StandardId::new(i as _)), [i]);
unwrap!(nb::block!(can.transmit(&tx_frame))); can.write(&tx_frame).await;
while !can.is_transmitter_idle() {} let (_, rx_frame) = can.read().await.unwrap();
let rx_frame = unwrap!(nb::block!(can.receive()));
info!("loopback frame {=u8}", unwrap!(rx_frame.data())[0]); info!("loopback frame {=u8}", unwrap!(rx_frame.data())[0]);
i += 1; i += 1;
} }