diff options
| author | Corey Schuhen <[email protected]> | 2024-01-25 17:10:25 +1000 |
|---|---|---|
| committer | Corey Schuhen <[email protected]> | 2024-01-31 05:40:05 +1000 |
| commit | 1698f4dbc3b5f4e561c3edd20246af63c22da507 (patch) | |
| tree | 460771503272bd12d19b18c443f3606a141d5f9c /examples/stm32g4/src/bin | |
| parent | 1de78d049017b7d21946a2e64d94c990f1bf4e7e (diff) | |
Add FDCAN examples for STM32G4, STM32H5 and STM32H7
Fix examples
Fix examples
Fix examples.
Diffstat (limited to 'examples/stm32g4/src/bin')
| -rw-r--r-- | examples/stm32g4/src/bin/can.rs | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/examples/stm32g4/src/bin/can.rs b/examples/stm32g4/src/bin/can.rs new file mode 100644 index 000000000..727921fba --- /dev/null +++ b/examples/stm32g4/src/bin/can.rs | |||
| @@ -0,0 +1,56 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | use defmt::*; | ||
| 4 | use embassy_executor::Spawner; | ||
| 5 | use embassy_stm32::peripherals::*; | ||
| 6 | use embassy_stm32::{bind_interrupts, can, Config}; | ||
| 7 | use embassy_time::Timer; | ||
| 8 | use {defmt_rtt as _, panic_probe as _}; | ||
| 9 | |||
| 10 | bind_interrupts!(struct Irqs { | ||
| 11 | FDCAN1_IT0 => can::IT0InterruptHandler<FDCAN1>; | ||
| 12 | FDCAN1_IT1 => can::IT1InterruptHandler<FDCAN1>; | ||
| 13 | }); | ||
| 14 | |||
| 15 | #[embassy_executor::main] | ||
| 16 | async fn main(_spawner: Spawner) { | ||
| 17 | let config = Config::default(); | ||
| 18 | |||
| 19 | let peripherals = embassy_stm32::init(config); | ||
| 20 | |||
| 21 | let mut can = can::Fdcan::new(peripherals.FDCAN1, peripherals.PA11, peripherals.PA12, Irqs); | ||
| 22 | |||
| 23 | // 250k bps | ||
| 24 | can.set_bitrate(250_000); | ||
| 25 | |||
| 26 | info!("Configured"); | ||
| 27 | |||
| 28 | //let mut can = can.into_external_loopback_mode(); | ||
| 29 | let mut can = can.into_normal_mode(); | ||
| 30 | |||
| 31 | let mut i = 0; | ||
| 32 | loop { | ||
| 33 | let frame = can::TxFrame::new( | ||
| 34 | can::TxFrameHeader { | ||
| 35 | len: 1, | ||
| 36 | frame_format: can::FrameFormat::Standard, | ||
| 37 | id: can::StandardId::new(0x123).unwrap().into(), | ||
| 38 | bit_rate_switching: false, | ||
| 39 | marker: None, | ||
| 40 | }, | ||
| 41 | &[i], | ||
| 42 | ) | ||
| 43 | .unwrap(); | ||
| 44 | info!("Writing frame"); | ||
| 45 | _ = can.write(&frame).await; | ||
| 46 | |||
| 47 | match can.read().await { | ||
| 48 | Ok(rx_frame) => info!("Rx: {}", rx_frame.data()[0]), | ||
| 49 | Err(_err) => error!("Error in frame"), | ||
| 50 | } | ||
| 51 | |||
| 52 | Timer::after_millis(250).await; | ||
| 53 | |||
| 54 | i += 1; | ||
| 55 | } | ||
| 56 | } | ||
