aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimo Kröger <[email protected]>2021-08-09 15:59:05 +0200
committerDario Nieuwenhuis <[email protected]>2021-08-18 21:58:50 +0200
commitdacf75d911058dd09d2a825a5b23d758f1f7a92d (patch)
tree5f4a5a26919fcecc42a9bf7ac851394109617494
parent191a589820159a69fbc72f996c4be91093dc2b44 (diff)
bxcan: Fix the flaky CAN example
-rw-r--r--examples/stm32f4/src/bin/can.rs17
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 @@
8mod example_common; 8mod example_common;
9 9
10use cortex_m_rt::entry; 10use cortex_m_rt::entry;
11use embassy_stm32::can::filter::Mask32;
11use embassy_stm32::can::{Can, Frame, StandardId}; 12use embassy_stm32::can::{Can, Frame, StandardId};
12use embassy_stm32::dbgmcu::Dbgmcu; 13use embassy_stm32::dbgmcu::Dbgmcu;
14use embassy_stm32::gpio::{Input, Pull};
13use example_common::*; 15use 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;