Skip to content

Commit a906cfb

Browse files
committed
stm32/can: Clarify can_clearfilter() arguments.
The function arguments mean totally different things for Classic vs FDCAN hardware, but the argument name wasn't particularly clear for either. This commit shouldn't really change the binary firmware at all. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
1 parent 4b339ee commit a906cfb

3 files changed

Lines changed: 12 additions & 12 deletions

File tree

ports/stm32/can.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ void can_enable_rx_interrupts(CAN_HandleTypeDef *can, can_rx_fifo_t fifo, bool e
152152
((enable_msg_received ? CAN_IT_FMP1 : 0) | CAN_IT_FF1 | CAN_IT_FOV1)));
153153
}
154154

155-
void can_clearfilter(CAN_HandleTypeDef *can, uint32_t filter_num, uint8_t bank) {
155+
void can_clearfilter(CAN_HandleTypeDef *can, uint32_t filter_num, uint8_t can2_start_bank) {
156156
CAN_FilterConfTypeDef filter;
157157

158158
filter.FilterIdHigh = 0;
@@ -164,7 +164,7 @@ void can_clearfilter(CAN_HandleTypeDef *can, uint32_t filter_num, uint8_t bank)
164164
filter.FilterMode = CAN_FILTERMODE_IDMASK;
165165
filter.FilterScale = CAN_FILTERSCALE_16BIT;
166166
filter.FilterActivation = DISABLE;
167-
filter.BankNumber = bank;
167+
filter.BankNumber = can2_start_bank;
168168

169169
HAL_CAN_ConfigFilter(can, &filter);
170170
}

ports/stm32/can.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ typedef enum {
9090
bool can_init(CAN_HandleTypeDef *can, int can_id, uint32_t mode, uint32_t prescaler, uint32_t sjw, uint32_t bs1, uint32_t bs2, bool auto_restart);
9191
void can_deinit(CAN_HandleTypeDef *can);
9292

93-
void can_clearfilter(CAN_HandleTypeDef *can, uint32_t filter_num, uint8_t bank);
9493
int can_receive(CAN_HandleTypeDef *can, can_rx_fifo_t fifo, CanRxMsgTypeDef *msg, uint8_t *data, uint32_t timeout_ms);
9594
HAL_StatusTypeDef can_transmit(CAN_HandleTypeDef *hcan, CanTxMsgTypeDef *txmsg, uint8_t *data, uint32_t Timeout);
9695

@@ -111,12 +110,16 @@ static inline unsigned can_rx_pending(CAN_HandleTypeDef *can, can_rx_fifo_t fifo
111110
return HAL_FDCAN_GetRxFifoFillLevel(can, fifo == CAN_RX_FIFO0 ? FDCAN_RX_FIFO0 : FDCAN_RX_FIFO1);
112111
}
113112

113+
void can_clearfilter(CAN_HandleTypeDef *can, uint32_t filter_num, bool is_extid);
114+
114115
#else
115116

116117
static inline unsigned can_rx_pending(CAN_HandleTypeDef *can, can_rx_fifo_t fifo) {
117118
return __HAL_CAN_MSG_PENDING(can, fifo == CAN_RX_FIFO0 ? CAN_FIFO0 : CAN_FIFO1);
118119
}
119120

121+
void can_clearfilter(CAN_HandleTypeDef *can, uint32_t filter_num, uint8_t can2_start_bank);
122+
120123
#endif // MICROPY_HW_ENABLE_FDCAN
121124

122125
#endif // MICROPY_HW_ENABLE_CAN

ports/stm32/fdcan.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -248,15 +248,12 @@ void can_deinit(FDCAN_HandleTypeDef *can) {
248248
}
249249
}
250250

251-
void can_clearfilter(FDCAN_HandleTypeDef *can, uint32_t f, uint8_t extid) {
252-
FDCAN_FilterTypeDef filter = {0};
253-
if (extid == 1) {
254-
filter.IdType = FDCAN_EXTENDED_ID;
255-
} else {
256-
filter.IdType = FDCAN_STANDARD_ID;
257-
}
258-
filter.FilterIndex = f;
259-
filter.FilterConfig = FDCAN_FILTER_DISABLE;
251+
void can_clearfilter(FDCAN_HandleTypeDef *can, uint32_t f, bool is_extid) {
252+
FDCAN_FilterTypeDef filter = {
253+
.IdType = is_extid ? FDCAN_EXTENDED_ID : FDCAN_STANDARD_ID,
254+
.FilterIndex = f,
255+
.FilterConfig = FDCAN_FILTER_DISABLE,
256+
};
260257
HAL_FDCAN_ConfigFilter(can, &filter);
261258
}
262259

0 commit comments

Comments
 (0)