From f141b987418ca55500b4f137555a64ea2bbb18d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20Kr=C3=B6ger?= Date: Sat, 14 Aug 2021 23:13:50 +0200 Subject: [PATCH] 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 --- embassy-stm32/src/can/bxcan.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/embassy-stm32/src/can/bxcan.rs b/embassy-stm32/src/can/bxcan.rs index 33f3cebf..906978e8 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> { impl<'d, T: Instance + bxcan::Instance> Can<'d, T> { pub fn new( peri: impl Unborrow + 'd, - // irq: impl Unborrow + 'd, rx: impl Unborrow> + 'd, tx: impl Unborrow> + 'd, ) -> Self { @@ -30,7 +29,6 @@ impl<'d, T: Instance + bxcan::Instance> Can<'d, T> { T::enable(); T::reset(); - // TODO: CAN2 also required CAN1 clock Self { phantom: PhantomData, @@ -101,21 +99,27 @@ crate::pac::peripherals!( ); crate::pac::peripherals!( - // TODO: rename CAN to CAN1 on yaml level?? (can, CAN) => { - unsafe impl bxcan::FilterOwner for peripherals::CAN { + unsafe impl bxcan::FilterOwner for peripherals::$inst { const NUM_FILTER_BANKS: u8 = 14; } }; + // Only correct when CAN2 also exists… Fix on yaml level? + // There are only 14 filter banks when CAN2 is not available. (can, CAN1) => { unsafe impl bxcan::FilterOwner for peripherals::CAN1 { - const NUM_FILTER_BANKS: u8 = 14; + const NUM_FILTER_BANKS: u8 = 28; } }; (can, CAN2) => { - // TODO: when CAN2 existis, we have 28 filter banks + // CAN2 is always a slave instance where CAN1 is the master instance unsafe impl bxcan::MasterInstance for peripherals::CAN1 {} }; + (can, CAN3) => { + unsafe impl bxcan::FilterOwner for peripherals::$inst { + const NUM_FILTER_BANKS: u8 = 14; + } + }; ); macro_rules! impl_pin {