diff options
| author | Corey Schuhen <[email protected]> | 2024-03-05 20:51:05 +1000 |
|---|---|---|
| committer | Corey Schuhen <[email protected]> | 2024-03-07 17:45:01 +1000 |
| commit | 65b38cf75504339033c56b39ce23da0b697a35a5 (patch) | |
| tree | 03390b306581c2d3b2461b7fffb0b4cc171c2765 /examples/stm32f7 | |
| parent | a9ff38003bebbb87aea2405437155d5312326803 (diff) | |
Fix examples and improve imports required.
Diffstat (limited to 'examples/stm32f7')
| -rw-r--r-- | examples/stm32f7/src/bin/can.rs | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/examples/stm32f7/src/bin/can.rs b/examples/stm32f7/src/bin/can.rs index bcfdb67a8..c3e14bbf4 100644 --- a/examples/stm32f7/src/bin/can.rs +++ b/examples/stm32f7/src/bin/can.rs | |||
| @@ -1,16 +1,18 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | 3 | ||
| 4 | use core::num::{NonZeroU16, NonZeroU8}; | ||
| 5 | |||
| 4 | use defmt::*; | 6 | use defmt::*; |
| 5 | use embassy_executor::Spawner; | 7 | use embassy_executor::Spawner; |
| 6 | use embassy_stm32::bind_interrupts; | 8 | use embassy_stm32::can::filter::Mask32; |
| 7 | use embassy_stm32::can::bxcan::filter::Mask32; | ||
| 8 | use embassy_stm32::can::bxcan::{Fifo, Frame, StandardId}; | ||
| 9 | use embassy_stm32::can::{ | 9 | use embassy_stm32::can::{ |
| 10 | Can, CanTx, Rx0InterruptHandler, Rx1InterruptHandler, SceInterruptHandler, TxInterruptHandler, | 10 | Can, CanTx, Fifo, Frame, Rx0InterruptHandler, Rx1InterruptHandler, SceInterruptHandler, StandardId, |
| 11 | TxInterruptHandler, | ||
| 11 | }; | 12 | }; |
| 12 | use embassy_stm32::gpio::{Input, Pull}; | 13 | use embassy_stm32::gpio::{Input, Pull}; |
| 13 | use embassy_stm32::peripherals::CAN3; | 14 | use embassy_stm32::peripherals::CAN3; |
| 15 | use embassy_stm32::{bind_interrupts, can}; | ||
| 14 | use static_cell::StaticCell; | 16 | use static_cell::StaticCell; |
| 15 | use {defmt_rtt as _, panic_probe as _}; | 17 | use {defmt_rtt as _, panic_probe as _}; |
| 16 | 18 | ||
| @@ -22,7 +24,7 @@ bind_interrupts!(struct Irqs { | |||
| 22 | }); | 24 | }); |
| 23 | 25 | ||
| 24 | #[embassy_executor::task] | 26 | #[embassy_executor::task] |
| 25 | pub async fn send_can_message(tx: &'static mut CanTx<'static, 'static, CAN3>) { | 27 | pub async fn send_can_message(tx: &'static mut CanTx<'static, CAN3>) { |
| 26 | loop { | 28 | loop { |
| 27 | let frame = Frame::new_data(unwrap!(StandardId::new(0 as _)), [0]); | 29 | let frame = Frame::new_data(unwrap!(StandardId::new(0 as _)), [0]); |
| 28 | tx.write(&frame).await; | 30 | tx.write(&frame).await; |
| @@ -51,13 +53,18 @@ async fn main(spawner: Spawner) { | |||
| 51 | 53 | ||
| 52 | can.as_mut() | 54 | can.as_mut() |
| 53 | .modify_config() | 55 | .modify_config() |
| 54 | .set_bit_timing(0x001c0001) // http://www.bittiming.can-wiki.info/ | 56 | .set_bit_timing(can::util::NominalBitTiming { |
| 57 | prescaler: NonZeroU16::new(2).unwrap(), | ||
| 58 | seg1: NonZeroU8::new(13).unwrap(), | ||
| 59 | seg2: NonZeroU8::new(2).unwrap(), | ||
| 60 | sync_jump_width: NonZeroU8::new(1).unwrap(), | ||
| 61 | }) // http://www.bittiming.can-wiki.info/ | ||
| 55 | .set_loopback(true) | 62 | .set_loopback(true) |
| 56 | .enable(); | 63 | .enable(); |
| 57 | 64 | ||
| 58 | let (tx, mut rx) = can.split(); | 65 | let (tx, mut rx) = can.split(); |
| 59 | 66 | ||
| 60 | static CAN_TX: StaticCell<CanTx<'static, 'static, CAN3>> = StaticCell::new(); | 67 | static CAN_TX: StaticCell<CanTx<'static, CAN3>> = StaticCell::new(); |
| 61 | let tx = CAN_TX.init(tx); | 68 | let tx = CAN_TX.init(tx); |
| 62 | spawner.spawn(send_can_message(tx)).unwrap(); | 69 | spawner.spawn(send_can_message(tx)).unwrap(); |
| 63 | 70 | ||
