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 | |
| parent | a9ff38003bebbb87aea2405437155d5312326803 (diff) | |
Fix examples and improve imports required.
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/stm32f1/src/bin/can.rs | 9 | ||||
| -rw-r--r-- | examples/stm32f4/src/bin/can.rs | 7 | ||||
| -rw-r--r-- | examples/stm32f7/src/bin/can.rs | 21 |
3 files changed, 23 insertions, 14 deletions
diff --git a/examples/stm32f1/src/bin/can.rs b/examples/stm32f1/src/bin/can.rs index 130b3905a..00d61096f 100644 --- a/examples/stm32f1/src/bin/can.rs +++ b/examples/stm32f1/src/bin/can.rs | |||
| @@ -3,9 +3,10 @@ | |||
| 3 | 3 | ||
| 4 | use defmt::*; | 4 | use defmt::*; |
| 5 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 6 | use embassy_stm32::can::bx::filter::Mask32; | 6 | use embassy_stm32::can::{ |
| 7 | use embassy_stm32::can::bx::{Fifo, Frame, Id, StandardId}; | 7 | filter, Can, Fifo, Frame, Id, Rx0InterruptHandler, Rx1InterruptHandler, SceInterruptHandler, StandardId, |
| 8 | use embassy_stm32::can::{Can, Rx0InterruptHandler, Rx1InterruptHandler, SceInterruptHandler, TxInterruptHandler}; | 8 | TxInterruptHandler, |
| 9 | }; | ||
| 9 | use embassy_stm32::peripherals::CAN; | 10 | use embassy_stm32::peripherals::CAN; |
| 10 | use embassy_stm32::{bind_interrupts, Config}; | 11 | use embassy_stm32::{bind_interrupts, Config}; |
| 11 | use {defmt_rtt as _, panic_probe as _}; | 12 | use {defmt_rtt as _, panic_probe as _}; |
| @@ -31,7 +32,7 @@ async fn main(_spawner: Spawner) { | |||
| 31 | 32 | ||
| 32 | can.as_mut() | 33 | can.as_mut() |
| 33 | .modify_filters() | 34 | .modify_filters() |
| 34 | .enable_bank(0, Fifo::Fifo0, Mask32::accept_all()); | 35 | .enable_bank(0, Fifo::Fifo0, filter::Mask32::accept_all()); |
| 35 | 36 | ||
| 36 | can.as_mut() | 37 | can.as_mut() |
| 37 | .modify_config() | 38 | .modify_config() |
diff --git a/examples/stm32f4/src/bin/can.rs b/examples/stm32f4/src/bin/can.rs index d074b4265..b20af8cf1 100644 --- a/examples/stm32f4/src/bin/can.rs +++ b/examples/stm32f4/src/bin/can.rs | |||
| @@ -4,9 +4,10 @@ | |||
| 4 | use defmt::*; | 4 | use defmt::*; |
| 5 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 6 | use embassy_stm32::bind_interrupts; | 6 | use embassy_stm32::bind_interrupts; |
| 7 | use embassy_stm32::can::bxcan::filter::Mask32; | 7 | use embassy_stm32::can::filter::Mask32; |
| 8 | use embassy_stm32::can::bxcan::{Fifo, Frame, StandardId}; | 8 | use embassy_stm32::can::{ |
| 9 | use embassy_stm32::can::{Can, Rx0InterruptHandler, Rx1InterruptHandler, SceInterruptHandler, TxInterruptHandler}; | 9 | Can, Fifo, Frame, Rx0InterruptHandler, Rx1InterruptHandler, SceInterruptHandler, StandardId, TxInterruptHandler, |
| 10 | }; | ||
| 10 | use embassy_stm32::gpio::{Input, Pull}; | 11 | use embassy_stm32::gpio::{Input, Pull}; |
| 11 | use embassy_stm32::peripherals::CAN1; | 12 | use embassy_stm32::peripherals::CAN1; |
| 12 | use embassy_time::Instant; | 13 | use embassy_time::Instant; |
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 | ||
