Skip to main content
Lukasz Przenioslo
Associate III
July 26, 2016
Question

STM32F4 config CAN Filters

  • July 26, 2016
  • 23 replies
  • 4355 views
Posted on July 26, 2016 at 14:35

Hello there,

For a while now I am trying to configure the CAN filter system to work properly in STM32F4 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.
    This topic has been closed for replies.

    23 replies

    Tesla DeLorean
    Guru
    August 2, 2016
    Posted on August 02, 2016 at 22:34

    https://www.emis.com/php/company-profile/PL/Stmicroelectronics_Sa_SA_Oddzial_W_Polsce_en_3530693.html

    http://www.masters.com.pl/en%2chome

    Nowogrodzka, 11

    WARSZAWA

    ,

    00-513

    , 

    Poland

    Phone:+48 22 5290529

    Fax: +48 22 5290520

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    Lukasz Przenioslo
    Associate III
    August 3, 2016
    Posted on August 03, 2016 at 08:08

    Thank you for this, I didnt know ST had a department in Poland. I aked them to tell technical support about the problem and contact me. If I get any feedback with solution ill post it here.

    Tesla DeLorean
    Guru
    August 3, 2016
    Posted on August 03, 2016 at 23:40

    Got some feedback on my ticket, but it mostly deals with how to filter, now why the FMI isn't working. I'll copy you on the current response if you email me at sourcer32@gmail.com

    I've pushed back asking for something dealing with FMI or the bxCAN IP

    What would be a good demonstration from your side would be an RX app that has six unique filters on each of the FIFOs, which outputs/enumerates the responses it gets. And a TX application that sends each of the filtered messages, one per second, in a loop.

    This would be a lot harder to ignore as an issue and allow for the issue to be elevated within ST.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..