aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/stm32/Cargo.toml8
-rw-r--r--tests/stm32/src/bin/can.rs78
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]
9stm32f103c8 = ["embassy-stm32/stm32f103c8", "not-gpdma"] # Blue Pill 9stm32f103c8 = ["embassy-stm32/stm32f103c8", "not-gpdma"] # Blue Pill
10stm32f429zi = ["embassy-stm32/stm32f429zi", "chrono", "not-gpdma"] # Nucleo "sdmmc" 10stm32f429zi = ["embassy-stm32/stm32f429zi", "chrono", "can", "not-gpdma"] # Nucleo "sdmmc"
11stm32g071rb = ["embassy-stm32/stm32g071rb", "not-gpdma"] # Nucleo 11stm32g071rb = ["embassy-stm32/stm32g071rb", "not-gpdma"] # Nucleo
12stm32c031c6 = ["embassy-stm32/stm32c031c6", "not-gpdma"] # Nucleo 12stm32c031c6 = ["embassy-stm32/stm32c031c6", "not-gpdma"] # Nucleo
13stm32g491re = ["embassy-stm32/stm32g491re", "not-gpdma"] # Nucleo 13stm32g491re = ["embassy-stm32/stm32g491re", "not-gpdma"] # Nucleo
@@ -18,6 +18,7 @@ stm32u585ai = ["embassy-stm32/stm32u585ai"] # IoT board
18 18
19sdmmc = [] 19sdmmc = []
20chrono = ["embassy-stm32/chrono", "dep:chrono"] 20chrono = ["embassy-stm32/chrono", "dep:chrono"]
21can = []
21ble = ["dep:embassy-stm32-wpan"] 22ble = ["dep:embassy-stm32-wpan"]
22not-gpdma = [] 23not-gpdma = []
23 24
@@ -53,6 +54,11 @@ path = "src/bin/tl_mbox.rs"
53required-features = [ "ble",] 54required-features = [ "ble",]
54 55
55[[bin]] 56[[bin]]
57name = "can"
58path = "src/bin/can.rs"
59required-features = [ "can",]
60
61[[bin]]
56name = "gpio" 62name = "gpio"
57path = "src/bin/gpio.rs" 63path = "src/bin/gpio.rs"
58required-features = [] 64required-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"]
8mod common;
9use common::*;
10use embassy_executor::Spawner;
11use embassy_stm32::bind_interrupts;
12use embassy_stm32::can::bxcan::filter::Mask32;
13use embassy_stm32::can::bxcan::{Fifo, Frame, StandardId};
14use embassy_stm32::can::{Can, Rx0InterruptHandler, Rx1InterruptHandler, SceInterruptHandler, TxInterruptHandler};
15use embassy_stm32::gpio::{Input, Pull};
16use embassy_stm32::peripherals::CAN1;
17use {defmt_rtt as _, panic_probe as _};
18
19bind_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]
27async 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}