cancel
Showing results for 
Search instead for 
Did you mean: 

[BUG CubeMX HAL] STM32F373 CAN RxMessage->FIFONumber not set?

valentin
Senior
Posted on May 10, 2016 at 01:53

Hi,

I'm testing receiving CAN messages using FIFO #1 at the moment and it all works fine, except that the field hcan->pRxMsg->FIFONumber isn't set.

Background:

I set up can filter bank 0 in list mode using this code:

 

 

        CAN_FilterConfTypeDef sFilterConfig;

 

        sFilterConfig.FilterNumber = 0;

 

        sFilterConfig.FilterMode = CAN_FILTERMODE_IDLIST;

 

        sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;

 

        sFilterConfig.FilterIdHigh = (can_id << 21) >> 16; // place STD_ID in bits 19:31, EXT_ID in bits 3:31

 

        sFilterConfig.FilterIdLow = (can_id << 21);

 

        sFilterConfig.FilterMaskIdHigh = 0x0000; //FR2 is empty, set to 0

 

        sFilterConfig.FilterMaskIdLow = 0x0000; //FR2 is empty, set to 0

 

        sFilterConfig.FilterFIFOAssignment = CAN_FIFO1; //=1

 

        sFilterConfig.FilterActivation = ENABLE;

 

        sFilterConfig.BankNumber = 26; // irrelevant if only using one can controller.

 

 

        if (HAL_CAN_ConfigFilter(canhandle, &sFilterConfig) != HAL_OK) {

 

            static uint8_t error = 0;

 

            error++;

 

        }

 

 

And the interrupt fires up correctly (CAN_RX1_IRQHandler) but when tracing from there until HAL_CAN_RxCpltCallback() the value of hcan->pRxMsg->FIFONumber is still 0, even though it SHOULD be 1, shouldn't it?

I suggest fixing this by adding the following line to the start of

static HAL_StatusTypeDef CAN_Receive_IT(CAN_HandleTypeDef* hcan, uint8_t FIFONumber){

 

hcan->pRxMsg->FIFONumber = FIFONumber;

 

 

... rest of function

 

}

 

 

This works for me.

4 REPLIES 4
Walid FTITI_O
Senior II
Posted on May 23, 2016 at 16:37

Hi Valentin,

I don't figure out why you expect that FIFONumber should be set. As you see in the can driver, in function there is the following code which allow continue the receiving either in FIFO0 or FIFO1 :

/* Check End of reception flag for FIFO0 */ 
if((__HAL_CAN_GET_IT_SOURCE(hcan, CAN_IT_FMP0)) && 
(__HAL_CAN_MSG_PENDING(hcan, CAN_FIFO0) != 0)) 
{ 
/* Call receive function */ 
CAN_Receive_IT(hcan, CAN_FIFO0); 
} 
/* Check End of reception flag for FIFO1 */ 
if((__HAL_CAN_GET_IT_SOURCE(hcan, CAN_IT_FMP1)) && 
(__HAL_CAN_MSG_PENDING(hcan, CAN_FIFO1) != 0)) 
{ 
/* Call receive function */ 
CAN_Receive_IT(hcan, CAN_FIFO1); 
}

Otherwise, you would share the part of the generated code that you claim about. (which CubeMx version) -Hannibal-
valentin
Senior
Posted on June 07, 2016 at 04:41

Hi Hannibal,

thanks for the reply. I'm accessing FIFONumber in the Callback function to determine which fifo to re-arm:

/*
* Do this whenever a new can message has been received
*/
void HAL_CAN_RxCpltCallback(CAN_HandleTypeDef* hcan) {
// do stuff
if (hcan->pRxMsg->FIFONumber == CAN_FIFO0) {
// Re-arm interrupt
HAL_CAN_Receive_IT(hcan, CAN_FIFO0);
} else if (hcan->pRxMsg->FIFONumber == CAN_FIFO1) {
 //Re-arm interrupt
HAL_CAN_Receive_IT(hcan, CAN_FIFO1);
}
}

Is this approach wrong? What is FIFONumber being used for instead? The above code works flawlessly for me - together with my suggested code change.
Walid FTITI_O
Senior II
Posted on September 15, 2016 at 10:50

HiVantentin,

It is related to a recent reported bug in Receive function about FiFONumber. It is under fix phase. Meanwhile , add the following line into can_Receive_IT() function before FMI line :

hcan->pRxMsg->FIFONumber = FIFONumber;

Check threads related to this topic:

[DEAD LINK /public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Configure%20CAN%20to%20receive%20in%20both%20FIFOs&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&currentviews=53]thread1

-Hannibal-

valentin
Senior
Posted on September 19, 2016 at 01:06

Hi Hannibal,

thanks for the update.

That is exactly what I recommended in the very first post.