diff options
| -rw-r--r-- | embassy-stm32/src/can/bxcan.rs | 30 | ||||
| -rw-r--r-- | examples/stm32f4/src/bin/can.rs | 5 |
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; | |||
| 7 | use crate::gpio::sealed::AFType; | 7 | use crate::gpio::sealed::AFType; |
| 8 | use crate::{peripherals, rcc::RccPeripheral}; | 8 | use crate::{peripherals, rcc::RccPeripheral}; |
| 9 | 9 | ||
| 10 | #[doc(no_inline)] | 10 | pub use bxcan; |
| 11 | pub use bxcan::*; | ||
| 12 | 11 | ||
| 13 | pub struct Can<'d, T: Instance + bxcan::Instance> { | 12 | pub 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 @@ | |||
| 6 | mod example_common; | 6 | mod example_common; |
| 7 | 7 | ||
| 8 | use cortex_m_rt::entry; | 8 | use cortex_m_rt::entry; |
| 9 | use embassy_stm32::can::filter::Mask32; | 9 | use embassy_stm32::can::bxcan::filter::Mask32; |
| 10 | use embassy_stm32::can::{Can, Frame, StandardId}; | 10 | use embassy_stm32::can::bxcan::{Frame, StandardId}; |
| 11 | use embassy_stm32::can::Can; | ||
| 11 | use embassy_stm32::gpio::{Input, Pull}; | 12 | use embassy_stm32::gpio::{Input, Pull}; |
| 12 | use example_common::*; | 13 | use example_common::*; |
| 13 | 14 | ||
