Skip to content

Commit 5049b51

Browse files
committed
Added working functionality to the can_filter api to accept IDs for filtering in both bxCAN and FDCAN
1 parent 064f94d commit 5049b51

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

targets/TARGET_STM/can_api.c

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,23 @@ static void _can_init_freq_direct(can_t *obj, const can_pinmap_t *pinmap, int hz
163163
obj->CanHandle.Init.DataSyncJumpWidth = 0x1; // Not used - only in FDCAN
164164
obj->CanHandle.Init.DataTimeSeg1 = 0x1; // Not used - only in FDCAN
165165
obj->CanHandle.Init.DataTimeSeg2 = 0x1; // Not used - only in FDCAN
166-
#ifndef TARGET_STM32G4
166+
#ifdef TARGET_STM32H7
167+
/* Message RAM offset is only supported in STM32H7 platforms of supported FDCAN platforms */
167168
obj->CanHandle.Init.MessageRAMOffset = 0;
169+
170+
/* The number of Standard and Extended ID filters are initialized to the maximum possile extent
171+
* for STM32H7 platforms
172+
*/
173+
obj->CanHandle.Init.StdFiltersNbr = 128; // to be aligned with the handle parameter in can_filter
174+
obj->CanHandle.Init.ExtFiltersNbr = 128; // to be aligned with the handle parameter in can_filter
175+
#else
176+
/* The number of Standard and Extended ID filters are initialized to the maximum possile extent
177+
* for STM32G0x1, STM32G4 and STM32L5 platforms
178+
*/
179+
obj->CanHandle.Init.StdFiltersNbr = 28; // to be aligned with the handle parameter in can_filter
180+
obj->CanHandle.Init.ExtFiltersNbr = 8; // to be aligned with the handle parameter in can_filter
168181
#endif
169-
obj->CanHandle.Init.StdFiltersNbr = 1; // to be aligned with the handle parameter in can_filter
170-
obj->CanHandle.Init.ExtFiltersNbr = 1; // to be aligned with the handle parameter in can_filter
171-
#ifndef TARGET_STM32G4
182+
#ifdef TARGET_STM32H7
172183
obj->CanHandle.Init.RxFifo0ElmtsNbr = 8;
173184
obj->CanHandle.Init.RxFifo0ElmtSize = FDCAN_DATA_BYTES_8;
174185
obj->CanHandle.Init.RxFifo1ElmtsNbr = 0;
@@ -180,7 +191,7 @@ static void _can_init_freq_direct(can_t *obj, const can_pinmap_t *pinmap, int hz
180191
obj->CanHandle.Init.TxFifoQueueElmtsNbr = 3;
181192
#endif
182193
obj->CanHandle.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION;
183-
#ifndef TARGET_STM32G4
194+
#ifdef TARGET_STM32H7
184195
obj->CanHandle.Init.TxElmtSize = FDCAN_DATA_BYTES_8;
185196
#endif
186197
can_internal_init(obj);
@@ -331,20 +342,16 @@ int can_filter(can_t *obj, uint32_t id, uint32_t mask, CANFormat format, int32_t
331342
{
332343
FDCAN_FilterTypeDef sFilterConfig = {0};
333344

334-
if(handle != 0) { // message filter handle is not supported for STM controllers
335-
return 0;
336-
}
337-
338345
if (format == CANStandard) {
339346
sFilterConfig.IdType = FDCAN_STANDARD_ID;
340-
sFilterConfig.FilterIndex = 0;
347+
sFilterConfig.FilterIndex = handle;
341348
sFilterConfig.FilterType = FDCAN_FILTER_MASK;
342349
sFilterConfig.FilterConfig = FDCAN_FILTER_TO_RXFIFO0;
343350
sFilterConfig.FilterID1 = id;
344351
sFilterConfig.FilterID2 = mask;
345352
} else if (format == CANExtended) {
346353
sFilterConfig.IdType = FDCAN_EXTENDED_ID;
347-
sFilterConfig.FilterIndex = 0;
354+
sFilterConfig.FilterIndex = handle;
348355
sFilterConfig.FilterType = FDCAN_FILTER_MASK;
349356
sFilterConfig.FilterConfig = FDCAN_FILTER_TO_RXFIFO0;
350357
sFilterConfig.FilterID1 = id;

0 commit comments

Comments
 (0)