Skip to main content
Graduate
March 5, 2025
Solved

STM32F4 - Using two RX FIFOs on the same CAN peripheral

  • March 5, 2025
  • 1 reply
  • 986 views

New to CAN here,

Is it possible to configure the same CAN peripheral (CAN1) on an STM32F4 to receive messages from one node in RXFIFO0 and from another node in RXFIFO1?

The reason for this setup is that one of the nodes has a higher priority and I would like to separate the messages accordingly. If this is possible, how should I configure the CAN filter settings to achieve this?

    This topic has been closed for replies.
    Best answer by mƎALLEm

    No.

    The filters need to have different CAN filter settings to ensure that one FIFO will accept a set of filters and the other will accept other sets of IDs.

    1 reply

    Technical Moderator
    March 5, 2025

    Hello @GHanj and welcome to the community.

    Yes you can make that separation and configure the CAN peripheral to receive a set of CAN IDs on FIFO0 and the other set of IDs on FIFO1.

    This is done in the filter configuration:

    The message that was accepted by this filter will be received on FIFO0:

     

     sFilterConfig.FilterFIFOAssignment = CAN_RX_FIFO0;

     

    The message that was accepted by this filter will be received on FIFO1:

     

     sFilterConfig.FilterFIFOAssignment = CAN_RX_FIFO1;

     

    Hope that answers your question.

    GHanjAuthor
    Graduate
    March 6, 2025

    Thank you for your response! If I understand correctly, are you suggesting that I should configure two separate CAN_FilterTypeDef structures and assign each to a specific FIFO, like this?

     

    void CAN_Filter0_Config(void){
    
    	CAN_FilterTypeDef canFilter0;
    
    	canFilter0.FilterActivation = ENABLE;
    	canFilter0.FilterBank = 0;
    	canFilter0.FilterFIFOAssignment = CAN_RX_FIFO0;
    	canFilter0.FilterIdHigh = 0x0000;
    	canFilter0.FilterIdLow = 0x0000;
    	canFilter0.FilterMaskIdHigh = 0x0000;
    	canFilter0.FilterMaskIdLow = 0x0000;
    	canFilter0.FilterMode = CAN_FILTERMODE_IDMASK;
    	canFilter0.FilterScale = CAN_FILTERSCALE_32BIT;
    
    	if( HAL_CAN_ConfigFilter(&hcan1, &canFilter0) != HAL_OK){
    		Error_Handler();
    	}
    }
    
    void CAN_Filter1_Config(void){
    
    	CAN_FilterTypeDef canFilter1;
    
    	canFilter1.FilterActivation = ENABLE;
    	canFilter1.FilterBank = 1;
    	canFilter1.FilterFIFOAssignment = CAN_RX_FIFO1;
    	canFilter1.FilterIdHigh = 0x0000;
    	canFilter1.FilterIdLow = 0x0000;
    	canFilter1.FilterMaskIdHigh = 0x0000;
    	canFilter1.FilterMaskIdLow = 0x0000;
    	canFilter1.FilterMode = CAN_FILTERMODE_IDMASK;
    	canFilter1.FilterScale = CAN_FILTERSCALE_32BIT;
    
    	if( HAL_CAN_ConfigFilter(&hcan1, &canFilter1) != HAL_OK){
    		Error_Handler();
    	}
    }

     

    Or are you suggesting that I should configure both FIFO assignments within a single CAN_FilterTypeDef?

    mƎALLEmAnswer
    Technical Moderator
    March 6, 2025

    No.

    The filters need to have different CAN filter settings to ensure that one FIFO will accept a set of filters and the other will accept other sets of IDs.