diff options
Diffstat (limited to 'examples/stm32f1/src')
| -rw-r--r-- | examples/stm32f1/src/bin/adc.rs | 1 | ||||
| -rw-r--r-- | examples/stm32f1/src/bin/blinky.rs | 1 | ||||
| -rw-r--r-- | examples/stm32f1/src/bin/can.rs | 66 | ||||
| -rw-r--r-- | examples/stm32f1/src/bin/hello.rs | 1 | ||||
| -rw-r--r-- | examples/stm32f1/src/bin/usb_serial.rs | 1 |
5 files changed, 66 insertions, 4 deletions
diff --git a/examples/stm32f1/src/bin/adc.rs b/examples/stm32f1/src/bin/adc.rs index 1edac3d83..1440460a9 100644 --- a/examples/stm32f1/src/bin/adc.rs +++ b/examples/stm32f1/src/bin/adc.rs | |||
| @@ -1,6 +1,5 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | 3 | ||
| 5 | use defmt::*; | 4 | use defmt::*; |
| 6 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
diff --git a/examples/stm32f1/src/bin/blinky.rs b/examples/stm32f1/src/bin/blinky.rs index 3425b0536..cc43f85f4 100644 --- a/examples/stm32f1/src/bin/blinky.rs +++ b/examples/stm32f1/src/bin/blinky.rs | |||
| @@ -1,6 +1,5 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | 3 | ||
| 5 | use defmt::*; | 4 | use defmt::*; |
| 6 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
diff --git a/examples/stm32f1/src/bin/can.rs b/examples/stm32f1/src/bin/can.rs new file mode 100644 index 000000000..c1c4f8359 --- /dev/null +++ b/examples/stm32f1/src/bin/can.rs | |||
| @@ -0,0 +1,66 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | |||
| 4 | use defmt::*; | ||
| 5 | use embassy_executor::Spawner; | ||
| 6 | use embassy_stm32::can::bxcan::filter::Mask32; | ||
| 7 | use embassy_stm32::can::bxcan::{Fifo, Frame, Id, StandardId}; | ||
| 8 | use embassy_stm32::can::{Can, Rx0InterruptHandler, Rx1InterruptHandler, SceInterruptHandler, TxInterruptHandler}; | ||
| 9 | use embassy_stm32::peripherals::CAN; | ||
| 10 | use embassy_stm32::{bind_interrupts, Config}; | ||
| 11 | use {defmt_rtt as _, panic_probe as _}; | ||
| 12 | |||
| 13 | bind_interrupts!(struct Irqs { | ||
| 14 | USB_LP_CAN1_RX0 => Rx0InterruptHandler<CAN>; | ||
| 15 | CAN1_RX1 => Rx1InterruptHandler<CAN>; | ||
| 16 | CAN1_SCE => SceInterruptHandler<CAN>; | ||
| 17 | USB_HP_CAN1_TX => TxInterruptHandler<CAN>; | ||
| 18 | }); | ||
| 19 | |||
| 20 | // This example is configured to work with real CAN transceivers on B8/B9. | ||
| 21 | // See other examples for loopback. | ||
| 22 | |||
| 23 | #[embassy_executor::main] | ||
| 24 | async fn main(_spawner: Spawner) { | ||
| 25 | let p = embassy_stm32::init(Config::default()); | ||
| 26 | |||
| 27 | // Set alternate pin mapping to B8/B9 | ||
| 28 | embassy_stm32::pac::AFIO.mapr().modify(|w| w.set_can1_remap(2)); | ||
| 29 | |||
| 30 | let mut can = Can::new(p.CAN, p.PB8, p.PB9, Irqs); | ||
| 31 | |||
| 32 | can.as_mut() | ||
| 33 | .modify_filters() | ||
| 34 | .enable_bank(0, Fifo::Fifo0, Mask32::accept_all()); | ||
| 35 | |||
| 36 | can.as_mut() | ||
| 37 | .modify_config() | ||
| 38 | .set_loopback(false) | ||
| 39 | .set_silent(false) | ||
| 40 | .leave_disabled(); | ||
| 41 | |||
| 42 | can.set_bitrate(250_000); | ||
| 43 | |||
| 44 | can.enable().await; | ||
| 45 | |||
| 46 | let mut i: u8 = 0; | ||
| 47 | loop { | ||
| 48 | let tx_frame = Frame::new_data(unwrap!(StandardId::new(i as _)), [i]); | ||
| 49 | can.write(&tx_frame).await; | ||
| 50 | |||
| 51 | match can.read().await { | ||
| 52 | Ok(env) => match env.frame.id() { | ||
| 53 | Id::Extended(id) => { | ||
| 54 | defmt::println!("Extended Frame id={:x}", id.as_raw()); | ||
| 55 | } | ||
| 56 | Id::Standard(id) => { | ||
| 57 | defmt::println!("Standard Frame id={:x}", id.as_raw()); | ||
| 58 | } | ||
| 59 | }, | ||
| 60 | Err(err) => { | ||
| 61 | defmt::println!("Error {}", err); | ||
| 62 | } | ||
| 63 | } | ||
| 64 | i += 1; | ||
| 65 | } | ||
| 66 | } | ||
diff --git a/examples/stm32f1/src/bin/hello.rs b/examples/stm32f1/src/bin/hello.rs index e63bcaae0..7b761ecc1 100644 --- a/examples/stm32f1/src/bin/hello.rs +++ b/examples/stm32f1/src/bin/hello.rs | |||
| @@ -1,6 +1,5 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | 3 | ||
| 5 | use defmt::info; | 4 | use defmt::info; |
| 6 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
diff --git a/examples/stm32f1/src/bin/usb_serial.rs b/examples/stm32f1/src/bin/usb_serial.rs index 31519555f..e28381893 100644 --- a/examples/stm32f1/src/bin/usb_serial.rs +++ b/examples/stm32f1/src/bin/usb_serial.rs | |||
| @@ -1,6 +1,5 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | 3 | ||
| 5 | use defmt::{panic, *}; | 4 | use defmt::{panic, *}; |
| 6 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
