From d6d25e6470b533dbdcc0fe1f521dd8311fa0adc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20Kr=C3=B6ger?= Date: Thu, 3 Mar 2022 20:51:34 +0100 Subject: [PATCH] [can] `cfgs` for naming inconsistencies Approach is similar to USB OTG. STM32L49x and STML4Ax have CAN1 and CAN2. All others STM32L4xx do only have CAN1. STM32F72x and STM32F73x are the only F7 devices with only CAN1. --- embassy-stm32/src/can/bxcan.rs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/embassy-stm32/src/can/bxcan.rs b/embassy-stm32/src/can/bxcan.rs index cb667695..4887ee14 100644 --- a/embassy-stm32/src/can/bxcan.rs +++ b/embassy-stm32/src/can/bxcan.rs @@ -96,10 +96,23 @@ foreach_peripheral!( // CAN1 owns the filter bank and needs to be enabled in order // for CAN2 to receive messages. (can, CAN1) => { - unsafe impl bxcan::FilterOwner for peripherals::CAN1 { - const NUM_FILTER_BANKS: u8 = 28; + cfg_if::cfg_if! { + if #[cfg(all( + any(stm32l4, stm32l72, stm32l73), + not(any(stm32l49, stm32l4a)) + ))] { + // Most L4 devices and some F7 devices use the name "CAN1" + // even if there is no "CAN2" peripheral. + unsafe impl bxcan::FilterOwner for peripherals::CAN1 { + const NUM_FILTER_BANKS: u8 = 14; + } + } else { + unsafe impl bxcan::FilterOwner for peripherals::CAN1 { + const NUM_FILTER_BANKS: u8 = 28; + } + unsafe impl bxcan::MasterInstance for peripherals::CAN1 {} + } } - unsafe impl bxcan::MasterInstance for peripherals::CAN1 {} }; (can, CAN3) => { unsafe impl bxcan::FilterOwner for peripherals::CAN3 {