diff options
| author | Timo Kröger <[email protected]> | 2021-08-09 15:59:05 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2021-08-18 21:58:50 +0200 |
| commit | dacf75d911058dd09d2a825a5b23d758f1f7a92d (patch) | |
| tree | 5f4a5a26919fcecc42a9bf7ac851394109617494 /examples | |
| parent | 191a589820159a69fbc72f996c4be91093dc2b44 (diff) | |
bxcan: Fix the flaky CAN example
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/stm32f4/src/bin/can.rs | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/examples/stm32f4/src/bin/can.rs b/examples/stm32f4/src/bin/can.rs index 04f3417c6..2bb24f045 100644 --- a/examples/stm32f4/src/bin/can.rs +++ b/examples/stm32f4/src/bin/can.rs | |||
| @@ -8,8 +8,10 @@ | |||
| 8 | mod example_common; | 8 | mod example_common; |
| 9 | 9 | ||
| 10 | use cortex_m_rt::entry; | 10 | use cortex_m_rt::entry; |
| 11 | use embassy_stm32::can::filter::Mask32; | ||
| 11 | use embassy_stm32::can::{Can, Frame, StandardId}; | 12 | use embassy_stm32::can::{Can, Frame, StandardId}; |
| 12 | use embassy_stm32::dbgmcu::Dbgmcu; | 13 | use embassy_stm32::dbgmcu::Dbgmcu; |
| 14 | use embassy_stm32::gpio::{Input, Pull}; | ||
| 13 | use example_common::*; | 15 | use example_common::*; |
| 14 | 16 | ||
| 15 | #[entry] | 17 | #[entry] |
| @@ -20,11 +22,22 @@ fn main() -> ! { | |||
| 20 | Dbgmcu::enable_all(); | 22 | Dbgmcu::enable_all(); |
| 21 | } | 23 | } |
| 22 | 24 | ||
| 23 | let p = embassy_stm32::init(Default::default()); | 25 | let mut p = embassy_stm32::init(Default::default()); |
| 26 | |||
| 27 | // The next two lines are a workaround for testing without transceiver. | ||
| 28 | // To synchronise to the bus the RX input needs to see a high level. | ||
| 29 | // Use `mem::forget()` to release the borrow on the pin but keep the | ||
| 30 | // pull-up resistor enabled. | ||
| 31 | let rx_pin = Input::new(&mut p.PA11, Pull::Up); | ||
| 32 | core::mem::forget(rx_pin); | ||
| 24 | 33 | ||
| 25 | let mut can = Can::new(p.CAN1, p.PA11, p.PA12); | 34 | let mut can = Can::new(p.CAN1, p.PA11, p.PA12); |
| 26 | 35 | ||
| 27 | can.modify_config().set_loopback(true); | 36 | can.modify_config() |
| 37 | .set_bit_timing(0x001c0003) // http://www.bittiming.can-wiki.info/ | ||
| 38 | .set_loopback(true) // Receive own frames | ||
| 39 | .set_silent(true); | ||
| 40 | can.modify_filters().enable_bank(0, Mask32::accept_all()); | ||
| 28 | unwrap!(nb::block!(can.enable())); | 41 | unwrap!(nb::block!(can.enable())); |
| 29 | 42 | ||
| 30 | let mut i: u8 = 0; | 43 | let mut i: u8 = 0; |
