Skip to content

Commit 064f94d

Browse files
committed
Added to return failure if filter if unsupported format
1 parent 274d8aa commit 064f94d

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

targets/TARGET_STM/can_api.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -329,10 +329,12 @@ int can_frequency(can_t *obj, int f)
329329
*/
330330
int can_filter(can_t *obj, uint32_t id, uint32_t mask, CANFormat format, int32_t handle)
331331
{
332-
UNUSED(handle); // Not supported yet (seems to be a used in read function?)
333-
334332
FDCAN_FilterTypeDef sFilterConfig = {0};
335333

334+
if(handle != 0) { // message filter handle is not supported for STM controllers
335+
return 0;
336+
}
337+
336338
if (format == CANStandard) {
337339
sFilterConfig.IdType = FDCAN_STANDARD_ID;
338340
sFilterConfig.FilterIndex = 0;
@@ -391,7 +393,7 @@ int can_write(can_t *obj, CAN_Message msg, int cc)
391393

392394
int can_read(can_t *obj, CAN_Message *msg, int handle)
393395
{
394-
UNUSED(handle); // Not supported yet (seems to be a handle to a filter configuration?)
396+
UNUSED(handle); // Not supported
395397

396398
if (HAL_FDCAN_GetRxFifoFillLevel(&obj->CanHandle, FDCAN_RX_FIFO0) == 0) {
397399
return 0; // No message arrived
@@ -1100,6 +1102,10 @@ int can_mode(can_t *obj, CanMode mode)
11001102
int can_filter(can_t *obj, uint32_t id, uint32_t mask, CANFormat format, int32_t handle)
11011103
{
11021104
int success = 0;
1105+
1106+
if(handle != 0) { // message filter handle not supported yet for STM controllers
1107+
return 0;
1108+
}
11031109

11041110
// filter for CANAny format cannot be configured for STM32
11051111
if ((format == CANStandard) || (format == CANExtended)) {
@@ -1128,6 +1134,8 @@ int can_filter(can_t *obj, uint32_t id, uint32_t mask, CANFormat format, int32_t
11281134
{
11291135
success = 1;
11301136
}
1137+
} else if (format == CANAny) {
1138+
success = 0; // filter for CANAny is not supported by STM32, return a failure
11311139
}
11321140

11331141
return success;

0 commit comments

Comments
 (0)