With commit F1D10CF the complete can_api.c file has been replaced with one that is targeted for the F7 family. With this implementation, the can_filter function ignores the handle argument and uses a fixed filter index of zero and calls HAL_FDCAN_ConfigFilter. The earlier implementation uses the handle argument as the filter index and calls HAL_CAN_ConfigFilter.
The consequence is that now only a single CAN message filter can be set (and probably only for CAN1!).
To regain the ability to use multiple CAN filters I derived my own class from mbed::CAN and re-implemented the filter member function with the code from the git commit for issue #5791 ( STM32 CAN: fix wrong ID and MASK filter).
class RawCAN : public mbed::CAN
{
public:
RawCAN( PinName rd, PinName td )
: CAN( rd, td )
{}
RawCAN( PinName rd, PinName td, int hz )
: CAN( rd, td, hz )
{}
virtual void lock () { /*do nothing*/ }
virtual void unlock() { /*do nothing*/ }
int filter( uint32_t id, uint32_t mask, CANFormat format, int32_t handle )
{
int retval = 0;
// filter for CANAny format cannot be configured for STM32
if ( (format == CANStandard) || (format == CANExtended) )
{
CAN_FilterConfTypeDef sFilterConfig;
sFilterConfig.FilterNumber = handle;
sFilterConfig.FilterMode = CAN_FILTERMODE_IDMASK;
sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;
if (format == CANStandard)
{
sFilterConfig.FilterIdHigh = id << 5;
sFilterConfig.FilterIdLow = 0x0;
sFilterConfig.FilterMaskIdHigh = mask << 5;
sFilterConfig.FilterMaskIdLow = 0x0; // allows both remote and data frames
}
else
{ // format == CANExtended
sFilterConfig.FilterIdHigh = id >> 13; // EXTID[28:13]
sFilterConfig.FilterIdLow = (0xFFFF & (id << 3)) | (1 << 2); // EXTID[12:0] + IDE
sFilterConfig.FilterMaskIdHigh = mask >> 13;
sFilterConfig.FilterMaskIdLow = (0xFFFF & (mask << 3)) | (1 << 2);
}
sFilterConfig.FilterFIFOAssignment = 0;
sFilterConfig.FilterActivation = ENABLE;
sFilterConfig.BankNumber = 14 + handle;
HAL_CAN_ConfigFilter( &_can.CanHandle, &sFilterConfig );
retval = handle;
}
return retval;
}
};