diff options
| author | Timo Kröger <[email protected]> | 2021-08-14 23:13:50 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2021-08-18 21:58:50 +0200 |
| commit | f141b987418ca55500b4f137555a64ea2bbb18d4 (patch) | |
| tree | 17984bf849141d6b172fa3b4e029505f1115435d | |
| parent | 0c3bede64f990daafb87ae8841261b754c885ddb (diff) | |
bxcan: Cleanup
Older families like F1 and F4 have a consistent naming for the CAN
peripherals: CAN when there is only one instance, CAN1/CAN2/CAN2 if
there are multiple instances.
Newer families like L4 and F7 use the name CAN1 even if there is only
one instance. The number of filter banks is incorrect for those.
Affected chips:
* STM32F722
* STM32F723
* STM32F730
* STM32F732
* STM32F733
* STM32L4P5
* STM32L4Q5
* STM32L4R5
* STM32L4R7
* STM32L4R9
* STM32L4S5
* STM32L4S7
* STM32L4S9
* STM32L431
* STM32L432
* STM32L433
* STM32L442
* STM32L443
* STM32L451
* STM32L452
* STM32L462
* STM32L471
* STM32L475
* STM32L476
* STM32L485
* STM32L486
| -rw-r--r-- | embassy-stm32/src/can/bxcan.rs | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/embassy-stm32/src/can/bxcan.rs b/embassy-stm32/src/can/bxcan.rs index 33f3cebff..906978e8b 100644 --- a/embassy-stm32/src/can/bxcan.rs +++ b/embassy-stm32/src/can/bxcan.rs | |||
| @@ -17,7 +17,6 @@ pub struct Can<'d, T: Instance + bxcan::Instance> { | |||
| 17 | impl<'d, T: Instance + bxcan::Instance> Can<'d, T> { | 17 | impl<'d, T: Instance + bxcan::Instance> Can<'d, T> { |
| 18 | pub fn new( | 18 | pub fn new( |
| 19 | peri: impl Unborrow<Target = T> + 'd, | 19 | peri: impl Unborrow<Target = T> + 'd, |
| 20 | // irq: impl Unborrow<Target = T::Interrupt> + 'd, | ||
| 21 | rx: impl Unborrow<Target = impl RxPin<T>> + 'd, | 20 | rx: impl Unborrow<Target = impl RxPin<T>> + 'd, |
| 22 | tx: impl Unborrow<Target = impl TxPin<T>> + 'd, | 21 | tx: impl Unborrow<Target = impl TxPin<T>> + 'd, |
| 23 | ) -> Self { | 22 | ) -> Self { |
| @@ -30,7 +29,6 @@ impl<'d, T: Instance + bxcan::Instance> Can<'d, T> { | |||
| 30 | 29 | ||
| 31 | T::enable(); | 30 | T::enable(); |
| 32 | T::reset(); | 31 | T::reset(); |
| 33 | // TODO: CAN2 also required CAN1 clock | ||
| 34 | 32 | ||
| 35 | Self { | 33 | Self { |
| 36 | phantom: PhantomData, | 34 | phantom: PhantomData, |
| @@ -101,21 +99,27 @@ crate::pac::peripherals!( | |||
| 101 | ); | 99 | ); |
| 102 | 100 | ||
| 103 | crate::pac::peripherals!( | 101 | crate::pac::peripherals!( |
| 104 | // TODO: rename CAN to CAN1 on yaml level?? | ||
| 105 | (can, CAN) => { | 102 | (can, CAN) => { |
| 106 | unsafe impl bxcan::FilterOwner for peripherals::CAN { | 103 | unsafe impl bxcan::FilterOwner for peripherals::$inst { |
| 107 | const NUM_FILTER_BANKS: u8 = 14; | 104 | const NUM_FILTER_BANKS: u8 = 14; |
| 108 | } | 105 | } |
| 109 | }; | 106 | }; |
| 107 | // Only correct when CAN2 also exists… Fix on yaml level? | ||
| 108 | // There are only 14 filter banks when CAN2 is not available. | ||
| 110 | (can, CAN1) => { | 109 | (can, CAN1) => { |
| 111 | unsafe impl bxcan::FilterOwner for peripherals::CAN1 { | 110 | unsafe impl bxcan::FilterOwner for peripherals::CAN1 { |
| 112 | const NUM_FILTER_BANKS: u8 = 14; | 111 | const NUM_FILTER_BANKS: u8 = 28; |
| 113 | } | 112 | } |
| 114 | }; | 113 | }; |
| 115 | (can, CAN2) => { | 114 | (can, CAN2) => { |
| 116 | // TODO: when CAN2 existis, we have 28 filter banks | 115 | // CAN2 is always a slave instance where CAN1 is the master instance |
| 117 | unsafe impl bxcan::MasterInstance for peripherals::CAN1 {} | 116 | unsafe impl bxcan::MasterInstance for peripherals::CAN1 {} |
| 118 | }; | 117 | }; |
| 118 | (can, CAN3) => { | ||
| 119 | unsafe impl bxcan::FilterOwner for peripherals::$inst { | ||
| 120 | const NUM_FILTER_BANKS: u8 = 14; | ||
| 121 | } | ||
| 122 | }; | ||
| 119 | ); | 123 | ); |
| 120 | 124 | ||
| 121 | macro_rules! impl_pin { | 125 | macro_rules! impl_pin { |
