Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
Hello,
it is good to see that the CAN bus support is now included in mbed for STM32 and is seems to be working fine (on an STM32F303K8).
However, trying to set a reception filter did not work as I expected, so I changed the can_filter function in can_api.c to make it work for me.
Cheers,
Max
Changes to can_api.c
int can_filter(can_t *obj, uint32_t id, uint32_t mask, CANFormat format, int32_t handle) { CanHandle.Instance = (CAN_TypeDef *)(obj->can); CAN_FilterConfTypeDef sFilterConfig; sFilterConfig.FilterNumber = handle; sFilterConfig.FilterMode = CAN_FILTERMODE_IDMASK; sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT; sFilterConfig.FilterFIFOAssignment = 0; sFilterConfig.FilterActivation = ENABLE; sFilterConfig.BankNumber = 14 + handle; switch (format) { case CANStandard: sFilterConfig.FilterIdHigh = (uint16_t) (id << 5); sFilterConfig.FilterIdLow = 0; sFilterConfig.FilterMaskIdHigh = (uint16_t) (mask << 5); sFilterConfig.FilterMaskIdLow = CAN_ID_EXT; break; case CANExtended: sFilterConfig.FilterIdLow = (uint16_t) (id << 3); sFilterConfig.FilterIdLow |= CAN_ID_EXT; sFilterConfig.FilterIdHigh = (uint16_t) (id >> 13); sFilterConfig.FilterMaskIdLow = (uint16_t) (mask << 3); sFilterConfig.FilterMaskIdLow |= CAN_ID_EXT; sFilterConfig.FilterMaskIdHigh = (uint16_t) (mask >> 13); break; } HAL_CAN_ConfigFilter(&CanHandle, &sFilterConfig); return 0; }