diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/stm32/Cargo.toml | 8 | ||||
| -rw-r--r-- | tests/stm32/src/bin/can.rs | 78 |
2 files changed, 85 insertions, 1 deletions
diff --git a/tests/stm32/Cargo.toml b/tests/stm32/Cargo.toml index 487ef4626..365f631b7 100644 --- a/tests/stm32/Cargo.toml +++ b/tests/stm32/Cargo.toml | |||
| @@ -7,7 +7,7 @@ autobins = false | |||
| 7 | 7 | ||
| 8 | [features] | 8 | [features] |
| 9 | stm32f103c8 = ["embassy-stm32/stm32f103c8", "not-gpdma"] # Blue Pill | 9 | stm32f103c8 = ["embassy-stm32/stm32f103c8", "not-gpdma"] # Blue Pill |
| 10 | stm32f429zi = ["embassy-stm32/stm32f429zi", "chrono", "not-gpdma"] # Nucleo "sdmmc" | 10 | stm32f429zi = ["embassy-stm32/stm32f429zi", "chrono", "can", "not-gpdma"] # Nucleo "sdmmc" |
| 11 | stm32g071rb = ["embassy-stm32/stm32g071rb", "not-gpdma"] # Nucleo | 11 | stm32g071rb = ["embassy-stm32/stm32g071rb", "not-gpdma"] # Nucleo |
| 12 | stm32c031c6 = ["embassy-stm32/stm32c031c6", "not-gpdma"] # Nucleo | 12 | stm32c031c6 = ["embassy-stm32/stm32c031c6", "not-gpdma"] # Nucleo |
| 13 | stm32g491re = ["embassy-stm32/stm32g491re", "not-gpdma"] # Nucleo | 13 | stm32g491re = ["embassy-stm32/stm32g491re", "not-gpdma"] # Nucleo |
| @@ -18,6 +18,7 @@ stm32u585ai = ["embassy-stm32/stm32u585ai"] # IoT board | |||
| 18 | 18 | ||
| 19 | sdmmc = [] | 19 | sdmmc = [] |
| 20 | chrono = ["embassy-stm32/chrono", "dep:chrono"] | 20 | chrono = ["embassy-stm32/chrono", "dep:chrono"] |
| 21 | can = [] | ||
| 21 | ble = ["dep:embassy-stm32-wpan"] | 22 | ble = ["dep:embassy-stm32-wpan"] |
| 22 | not-gpdma = [] | 23 | not-gpdma = [] |
| 23 | 24 | ||
| @@ -53,6 +54,11 @@ path = "src/bin/tl_mbox.rs" | |||
| 53 | required-features = [ "ble",] | 54 | required-features = [ "ble",] |
| 54 | 55 | ||
| 55 | [[bin]] | 56 | [[bin]] |
| 57 | name = "can" | ||
| 58 | path = "src/bin/can.rs" | ||
| 59 | required-features = [ "can",] | ||
| 60 | |||
| 61 | [[bin]] | ||
| 56 | name = "gpio" | 62 | name = "gpio" |
| 57 | path = "src/bin/gpio.rs" | 63 | path = "src/bin/gpio.rs" |
| 58 | required-features = [] | 64 | required-features = [] |
diff --git a/tests/stm32/src/bin/can.rs b/tests/stm32/src/bin/can.rs new file mode 100644 index 000000000..33d63d546 --- /dev/null +++ b/tests/stm32/src/bin/can.rs | |||
| @@ -0,0 +1,78 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | |||
| 5 | // required-features: can | ||
| 6 | |||
| 7 | #[path = "../common.rs"] | ||
| 8 | mod common; | ||
| 9 | use common::*; | ||
| 10 | use embassy_executor::Spawner; | ||
| 11 | use embassy_stm32::bind_interrupts; | ||
| 12 | use embassy_stm32::can::bxcan::filter::Mask32; | ||
| 13 | use embassy_stm32::can::bxcan::{Fifo, Frame, StandardId}; | ||
| 14 | use embassy_stm32::can::{Can, Rx0InterruptHandler, Rx1InterruptHandler, SceInterruptHandler, TxInterruptHandler}; | ||
| 15 | use embassy_stm32::gpio::{Input, Pull}; | ||
| 16 | use embassy_stm32::peripherals::CAN1; | ||
| 17 | use {defmt_rtt as _, panic_probe as _}; | ||
| 18 | |||
| 19 | bind_interrupts!(struct Irqs { | ||
| 20 | CAN1_RX0 => Rx0InterruptHandler<CAN1>; | ||
| 21 | CAN1_RX1 => Rx1InterruptHandler<CAN1>; | ||
| 22 | CAN1_SCE => SceInterruptHandler<CAN1>; | ||
| 23 | CAN1_TX => TxInterruptHandler<CAN1>; | ||
| 24 | }); | ||
| 25 | |||
| 26 | #[embassy_executor::main] | ||
| 27 | async fn main(_spawner: Spawner) { | ||
| 28 | let mut p = embassy_stm32::init(config()); | ||
| 29 | info!("Hello World!"); | ||
| 30 | |||
| 31 | // HW is connected as follows: | ||
| 32 | // PB13 -> PD0 | ||
| 33 | // PB12 -> PD1 | ||
| 34 | |||
| 35 | // The next two lines are a workaround for testing without transceiver. | ||
| 36 | // To synchronise to the bus the RX input needs to see a high level. | ||
| 37 | // Use `mem::forget()` to release the borrow on the pin but keep the | ||
| 38 | // pull-up resistor enabled. | ||
| 39 | let rx_pin = Input::new(&mut p.PD0, Pull::Up); | ||
| 40 | core::mem::forget(rx_pin); | ||
| 41 | |||
| 42 | let mut can = Can::new(p.CAN1, p.PD0, p.PD1, Irqs); | ||
| 43 | |||
| 44 | info!("Configuring can..."); | ||
| 45 | |||
| 46 | can.modify_filters().enable_bank(0, Fifo::Fifo0, Mask32::accept_all()); | ||
| 47 | |||
| 48 | can.set_bitrate(1_000_000); | ||
| 49 | can.modify_config() | ||
| 50 | .set_loopback(true) // Receive own frames | ||
| 51 | .set_silent(true) | ||
| 52 | // .set_bit_timing(0x001c0003) | ||
| 53 | .enable(); | ||
| 54 | |||
| 55 | info!("Can configured"); | ||
| 56 | |||
| 57 | let mut i: u8 = 0; | ||
| 58 | loop { | ||
| 59 | let tx_frame = Frame::new_data(unwrap!(StandardId::new(i as _)), [i]); | ||
| 60 | |||
| 61 | info!("Transmitting frame..."); | ||
| 62 | can.write(&tx_frame).await; | ||
| 63 | |||
| 64 | info!("Receiving frame..."); | ||
| 65 | let (time, rx_frame) = can.read().await.unwrap(); | ||
| 66 | |||
| 67 | info!("loopback time {}", time); | ||
| 68 | info!("loopback frame {=u8}", rx_frame.data().unwrap()[0]); | ||
| 69 | |||
| 70 | i += 1; | ||
| 71 | if i > 10 { | ||
| 72 | break; | ||
| 73 | } | ||
| 74 | } | ||
| 75 | |||
| 76 | info!("Test OK"); | ||
| 77 | cortex_m::asm::bkpt(); | ||
| 78 | } | ||
