diff options
| author | Timo Kröger <[email protected]> | 2021-08-06 00:08:24 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2021-08-18 21:58:50 +0200 |
| commit | 7c405250a77c08740524529757f8203b5b7e0a60 (patch) | |
| tree | 9b161305e5933af11cef0cd16cdad12f70bd8137 /examples | |
| parent | 0fee2b9509e54e88f31f18df1d0d2b43a86b8a33 (diff) | |
CAN support with bxcan crate
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/stm32f4/Cargo.toml | 1 | ||||
| -rw-r--r-- | examples/stm32f4/src/bin/can.rs | 39 |
2 files changed, 40 insertions, 0 deletions
diff --git a/examples/stm32f4/Cargo.toml b/examples/stm32f4/Cargo.toml index c254573f8..95c8441d9 100644 --- a/examples/stm32f4/Cargo.toml +++ b/examples/stm32f4/Cargo.toml | |||
| @@ -32,3 +32,4 @@ panic-probe = { version = "0.2.0", features= ["print-defmt"] } | |||
| 32 | futures = { version = "0.3.8", default-features = false, features = ["async-await"] } | 32 | futures = { version = "0.3.8", default-features = false, features = ["async-await"] } |
| 33 | rtt-target = { version = "0.3", features = ["cortex-m"] } | 33 | rtt-target = { version = "0.3", features = ["cortex-m"] } |
| 34 | heapless = { version = "0.7.1", default-features = false } | 34 | heapless = { version = "0.7.1", default-features = false } |
| 35 | nb = { version = "1.0" } | ||
diff --git a/examples/stm32f4/src/bin/can.rs b/examples/stm32f4/src/bin/can.rs new file mode 100644 index 000000000..d35a81d1d --- /dev/null +++ b/examples/stm32f4/src/bin/can.rs | |||
| @@ -0,0 +1,39 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(trait_alias)] | ||
| 4 | #![feature(type_alias_impl_trait)] | ||
| 5 | #![allow(incomplete_features)] | ||
| 6 | |||
| 7 | #[path = "../example_common.rs"] | ||
| 8 | mod example_common; | ||
| 9 | |||
| 10 | use cortex_m_rt::entry; | ||
| 11 | use embassy_stm32::bxcan::{Can, Frame, StandardId}; | ||
| 12 | use embassy_stm32::dbgmcu::Dbgmcu; | ||
| 13 | use example_common::*; | ||
| 14 | |||
| 15 | #[entry] | ||
| 16 | fn main() -> ! { | ||
| 17 | info!("Hello World!"); | ||
| 18 | |||
| 19 | unsafe { | ||
| 20 | Dbgmcu::enable_all(); | ||
| 21 | } | ||
| 22 | |||
| 23 | let p = embassy_stm32::init(Default::default()); | ||
| 24 | |||
| 25 | let mut can = Can::new(p.CAN1, p.PA11, p.PA12); | ||
| 26 | |||
| 27 | can.modify_config().set_loopback(true); | ||
| 28 | unwrap!(nb::block!(can.enable())); | ||
| 29 | |||
| 30 | let mut i: u8 = 0; | ||
| 31 | loop { | ||
| 32 | let tx_frame = Frame::new_data(unwrap!(StandardId::new(i as _)), [i]); | ||
| 33 | unwrap!(nb::block!(can.transmit(&tx_frame))); | ||
| 34 | while !can.is_transmitter_idle() {} | ||
| 35 | let rx_frame = unwrap!(nb::block!(can.receive())); | ||
| 36 | info!("loopback frame {=u8}", unwrap!(rx_frame.data())[0]); | ||
| 37 | i += 1; | ||
| 38 | } | ||
| 39 | } | ||
