AnsweredAssumed Answered

STM32F4 config CAN Filters

Question asked by Lukasz Przenioslo on Jul 26, 2016
Latest reply on Aug 3, 2016 by Clive One
Hello there,
For a while now I am trying to configure the CAN filter system to work properly in STM32F407. I have managed to make the system work the way that I have 2 mask filters. Depending on which the CAN ID message is received through FIFO0 or FIFO1. So it seems to be working properly. But not quite... In the HAL CAN RX interrupt routine the filter hit is checked (FMI part from CAN_RDTxR register). Even though messages come to the proper FIFO, the FMI part is always 0. I started playing with the filter ID configuration and FMI started to change, but still it didnt reflect my configured filter number at any point. This is my configuration code:

/**
 * @brief   Configures the Can receiving filter.
 *          Filter should cover the lower part of upper 16 bit mask and filter.
 * @param   canData: Pointer to a can conf struct, preconfigured.
 * @return  HAL_OK if all ok.
 */
HAL_StatusTypeDef can_ConfigRxFilter(canData_t* canData)
{
    assert_param(canData);
    assert_param(canData->canHandle);
 
    HAL_StatusTypeDef retVal = HAL_OK;
    CAN_FilterConfTypeDef sFilterConfig;
 
    // First config unicast filter
    sFilterConfig.FilterNumber = canData->objectId;
    sFilterConfig.FilterMode = CAN_FILTERMODE_IDMASK;
    sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;
 
    // TML CAN
    uint32_t EXID  = canData->canAxisId << 13;
    uint32_t STID  = EXID & 0x7FF;
    uint32_t EXMASK = 0xFF << 13;
    uint32_t STMASK  = EXMASK & 0x7FF;
 
    sFilterConfig.FilterIdHigh = (uint16_t)(((STID << 5) & 0xFFE0) | ((EXID >> 13) & 0x001F));
    sFilterConfig.FilterIdLow = (uint16_t)(((EXID << 3) & 0xFFF8));
 
    sFilterConfig.FilterMaskIdHigh = (uint16_t)(((STMASK << 5) & 0xFFE0) | ((EXMASK >> 13) & 0x001F));
    sFilterConfig.FilterMaskIdLow = (uint16_t)(((EXMASK << 3) & 0xFFF8));
 
    sFilterConfig.FilterFIFOAssignment = canData->canRxFifo;
    sFilterConfig.FilterActivation = ENABLE;
    sFilterConfig.BankNumber = 0;
 
    retVal += HAL_CAN_ConfigFilter(canData->canHandle, &sFilterConfig);
 
    assert_param(!retVal);
    return retVal;
}

This function is run twice. Once for canData->objectId = 0 (received message should have FMI = 0) and once for canData->objectId = 1 (FMI should be 1). Maybe it has something to do with the BankNumber, this is not very clear for me.

I would appreciate all help regarding the configuration.

Outcomes