Skip to content

Commit f141b98

Browse files
timokroegerDirbaio
authored andcommitted
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
1 parent 0c3bede commit f141b98

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

embassy-stm32/src/can/bxcan.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ pub struct Can<'d, T: Instance + bxcan::Instance> {
1717
impl<'d, T: Instance + bxcan::Instance> Can<'d, T> {
1818
pub fn new(
1919
peri: impl Unborrow<Target = T> + 'd,
20-
// irq: impl Unborrow<Target = T::Interrupt> + 'd,
2120
rx: impl Unborrow<Target = impl RxPin<T>> + 'd,
2221
tx: impl Unborrow<Target = impl TxPin<T>> + 'd,
2322
) -> Self {
@@ -30,7 +29,6 @@ impl<'d, T: Instance + bxcan::Instance> Can<'d, T> {
3029

3130
T::enable();
3231
T::reset();
33-
// TODO: CAN2 also required CAN1 clock
3432

3533
Self {
3634
phantom: PhantomData,
@@ -101,21 +99,27 @@ crate::pac::peripherals!(
10199
);
102100

103101
crate::pac::peripherals!(
104-
// TODO: rename CAN to CAN1 on yaml level??
105102
(can, CAN) => {
106-
unsafe impl bxcan::FilterOwner for peripherals::CAN {
103+
unsafe impl bxcan::FilterOwner for peripherals::$inst {
107104
const NUM_FILTER_BANKS: u8 = 14;
108105
}
109106
};
107+
// Only correct when CAN2 also exists… Fix on yaml level?
108+
// There are only 14 filter banks when CAN2 is not available.
110109
(can, CAN1) => {
111110
unsafe impl bxcan::FilterOwner for peripherals::CAN1 {
112-
const NUM_FILTER_BANKS: u8 = 14;
111+
const NUM_FILTER_BANKS: u8 = 28;
113112
}
114113
};
115114
(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
117116
unsafe impl bxcan::MasterInstance for peripherals::CAN1 {}
118117
};
118+
(can, CAN3) => {
119+
unsafe impl bxcan::FilterOwner for peripherals::$inst {
120+
const NUM_FILTER_BANKS: u8 = 14;
121+
}
122+
};
119123
);
120124

121125
macro_rules! impl_pin {

0 commit comments

Comments
 (0)