From 4c305439385c7be79dc9997ae8b698a3487aa819 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20Kr=C3=B6ger?= Date: Mon, 28 Feb 2022 22:42:45 +0100 Subject: [PATCH 1/4] [can] Do not use wildcard reexport for bxcan --- embassy-stm32/src/can/bxcan.rs | 3 +-- examples/stm32f4/src/bin/can.rs | 5 +++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/embassy-stm32/src/can/bxcan.rs b/embassy-stm32/src/can/bxcan.rs index 34182206f..33a729ed5 100644 --- a/embassy-stm32/src/can/bxcan.rs +++ b/embassy-stm32/src/can/bxcan.rs @@ -7,8 +7,7 @@ use embassy_hal_common::unborrow; use crate::gpio::sealed::AFType; use crate::{peripherals, rcc::RccPeripheral}; -#[doc(no_inline)] -pub use bxcan::*; +pub use bxcan; pub struct Can<'d, T: Instance + bxcan::Instance> { phantom: PhantomData<&'d mut T>, 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 @@ mod example_common; use cortex_m_rt::entry; -use embassy_stm32::can::filter::Mask32; -use embassy_stm32::can::{Can, Frame, StandardId}; +use embassy_stm32::can::bxcan::filter::Mask32; +use embassy_stm32::can::bxcan::{Frame, StandardId}; +use embassy_stm32::can::Can; use embassy_stm32::gpio::{Input, Pull}; use example_common::*; From 6929350552fcf3cc7cc830555ce09b16bb86746f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20Kr=C3=B6ger?= Date: Mon, 28 Feb 2022 22:43:21 +0100 Subject: [PATCH 2/4] [can] Update macrotable comment The chip description are corrected in: https://github.com/embassy-rs/stm32-data/pull/123 --- embassy-stm32/src/can/bxcan.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/embassy-stm32/src/can/bxcan.rs b/embassy-stm32/src/can/bxcan.rs index 33a729ed5..cb667695a 100644 --- a/embassy-stm32/src/can/bxcan.rs +++ b/embassy-stm32/src/can/bxcan.rs @@ -92,15 +92,13 @@ foreach_peripheral!( 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. + // CAN1 and CAN2 is a combination of master and slave instance. + // 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; } - }; - (can, CAN2) => { - // CAN2 is always a slave instance where CAN1 is the master instance unsafe impl bxcan::MasterInstance for peripherals::CAN1 {} }; (can, CAN3) => { 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 3/4] [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 cb667695a..4887ee143 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 { From 372b71890d658176bd78de752d92289538bbbbe3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20Kr=C3=B6ger?= Date: Sat, 5 Mar 2022 09:43:47 +0100 Subject: [PATCH 4/4] [can] Typo fix: l7 -> f7 --- embassy-stm32/src/can/bxcan.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/embassy-stm32/src/can/bxcan.rs b/embassy-stm32/src/can/bxcan.rs index 4887ee143..c1de55393 100644 --- a/embassy-stm32/src/can/bxcan.rs +++ b/embassy-stm32/src/can/bxcan.rs @@ -98,7 +98,7 @@ foreach_peripheral!( (can, CAN1) => { cfg_if::cfg_if! { if #[cfg(all( - any(stm32l4, stm32l72, stm32l73), + any(stm32l4, stm32f72, stm32f73), not(any(stm32l49, stm32l4a)) ))] { // Most L4 devices and some F7 devices use the name "CAN1"