aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embassy-stm32/src/can/bxcan.rs30
-rw-r--r--examples/stm32f4/src/bin/can.rs5
2 files changed, 23 insertions, 12 deletions
diff --git a/embassy-stm32/src/can/bxcan.rs b/embassy-stm32/src/can/bxcan.rs
index 34182206f..c1de55393 100644
--- a/embassy-stm32/src/can/bxcan.rs
+++ b/embassy-stm32/src/can/bxcan.rs
@@ -7,8 +7,7 @@ use embassy_hal_common::unborrow;
7use crate::gpio::sealed::AFType; 7use crate::gpio::sealed::AFType;
8use crate::{peripherals, rcc::RccPeripheral}; 8use crate::{peripherals, rcc::RccPeripheral};
9 9
10#[doc(no_inline)] 10pub use bxcan;
11pub use bxcan::*;
12 11
13pub struct Can<'d, T: Instance + bxcan::Instance> { 12pub struct Can<'d, T: Instance + bxcan::Instance> {
14 phantom: PhantomData<&'d mut T>, 13 phantom: PhantomData<&'d mut T>,
@@ -93,17 +92,28 @@ foreach_peripheral!(
93 const NUM_FILTER_BANKS: u8 = 14; 92 const NUM_FILTER_BANKS: u8 = 14;
94 } 93 }
95 }; 94 };
96 // Only correct when CAN2 also exists… Fix on yaml level? 95 // CAN1 and CAN2 is a combination of master and slave instance.
97 // There are only 14 filter banks when CAN2 is not available. 96 // CAN1 owns the filter bank and needs to be enabled in order
97 // for CAN2 to receive messages.
98 (can, CAN1) => { 98 (can, CAN1) => {
99 unsafe impl bxcan::FilterOwner for peripherals::CAN1 { 99 cfg_if::cfg_if! {
100 const NUM_FILTER_BANKS: u8 = 28; 100 if #[cfg(all(
101 any(stm32l4, stm32f72, stm32f73),
102 not(any(stm32l49, stm32l4a))
103 ))] {
104 // Most L4 devices and some F7 devices use the name "CAN1"
105 // even if there is no "CAN2" peripheral.
106 unsafe impl bxcan::FilterOwner for peripherals::CAN1 {
107 const NUM_FILTER_BANKS: u8 = 14;
108 }
109 } else {
110 unsafe impl bxcan::FilterOwner for peripherals::CAN1 {
111 const NUM_FILTER_BANKS: u8 = 28;
112 }
113 unsafe impl bxcan::MasterInstance for peripherals::CAN1 {}
114 }
101 } 115 }
102 }; 116 };
103 (can, CAN2) => {
104 // CAN2 is always a slave instance where CAN1 is the master instance
105 unsafe impl bxcan::MasterInstance for peripherals::CAN1 {}
106 };
107 (can, CAN3) => { 117 (can, CAN3) => {
108 unsafe impl bxcan::FilterOwner for peripherals::CAN3 { 118 unsafe impl bxcan::FilterOwner for peripherals::CAN3 {
109 const NUM_FILTER_BANKS: u8 = 14; 119 const NUM_FILTER_BANKS: u8 = 14;
diff --git a/examples/stm32f4/src/bin/can.rs b/examples/stm32f4/src/bin/can.rs
index 4c575aa87..b36e41805 100644
--- a/examples/stm32f4/src/bin/can.rs
+++ b/examples/stm32f4/src/bin/can.rs
@@ -6,8 +6,9 @@
6mod example_common; 6mod example_common;
7 7
8use cortex_m_rt::entry; 8use cortex_m_rt::entry;
9use embassy_stm32::can::filter::Mask32; 9use embassy_stm32::can::bxcan::filter::Mask32;
10use embassy_stm32::can::{Can, Frame, StandardId}; 10use embassy_stm32::can::bxcan::{Frame, StandardId};
11use embassy_stm32::can::Can;
11use embassy_stm32::gpio::{Input, Pull}; 12use embassy_stm32::gpio::{Input, Pull};
12use example_common::*; 13use example_common::*;
13 14