cancel
Showing results for 
Search instead for 
Did you mean: 

Configure CAN to receive in both FIFOs

Posted on June 09, 2016 at 10:58

Hello there,

I am using STM32F4. I am trying to configure can peripheral the way that when messages are received, they pass through 2 filters. If filter 0 matches they go to FIFO0, if filter 1 matches they should be stored in FIFO1. Is this possible? A for now I have a problem with can busy flag- Im am trying to turn rx interrupts to work for FIFO0 and FIFO1, like this:

HAL_CAN_Receive_IT(canHandle, 0);
HAL_CAN_Receive_IT(canHandle, 1);

The problem is that after the 1st line of code is executed, the can status is set to HAL_CAN_STATE_BUSY_RX so the second one doesnt work. What is the proper way of making this idea work? 2 different filters, 2 different FIFO's, 1 can peripheral. I would really appreciate all help.
15 REPLIES 15
Walid FTITI_O
Senior II
Posted on June 09, 2016 at 12:08

Hi Bremen,

It is already reported issue caused by the busy state of setting . until it will be fixed, as a work around try to comment the following lines in the HAL_CAN_Transmit() function after __HAL_LOCK().

if(hcan->State == HAL_CAN_STATE_BUSY_RX) 
{ 
/* Change CAN state */ 
hcan->State = HAL_CAN_STATE_BUSY_TX_RX; 
} 
else 
{ 
/* Change CAN state */ 
hcan->State = HAL_CAN_STATE_BUSY_TX; 
}

-Hannibal-
Posted on June 09, 2016 at 12:12

But the problem is within

HAL_CAN_Receive_IT();  Like this:  // Flag is not busy

HAL_CAN_Receive_IT(canHandle, 0);

// now flag is busy

// now next HAL_CAN_Receive_IT(); for FIFO1 wont work.

HAL_CAN_Receive_IT(canHandle, 1);  

Posted on June 09, 2016 at 12:29

Okay I have commented out the lines you specified in the HAL_CAN_Receive_IT() function and receiving on both fifos. I have found however more bugs.

1. The member of the stuct CanRxMsgTypeDef called FIFONumber is not used in the code at all I believe. Its comment says:

uint32_t FIFONumber; /*!< Specifies the receive FIFO number.
This parameter can be CAN_FIFO0 or CAN_FIFO1 */

But when you look into the CAN_Receive_IT function this parameter is not set before going further to the HAL_CAN_RxCpltCallback. I believe just before going to HAL_CAN_RxCpltCallback it is a good place to add something like:

hcan->pRxMsg->FIFONumber = FIFONumber;

2. Parameter FMI doesnt seem to be updated correctly. It should say which filter number worked. I am using filter 0 and 1 and even though this line in CAN_Receive_IT always sets FMI to 0:

/* Get the FMI */
hcan->pRxMsg->FMI = (uint8_t)0xFF & (hcan->Instance->sFIFOMailBox[FIFONumber].RDTR >> 8);

I would appreciate all feedback regarding this.
Walid FTITI_O
Senior II
Posted on September 01, 2016 at 15:29

Hi Bremen,

Sorry for the late response. I take your feedbacks into consideration concerninf the FIFONumber to add the missed instance configuration into the receive function. I report it to be fixed.

-Hannibal-

christoph2399
Associate II
Posted on September 02, 2016 at 08:48

i configured filters to receive it in both fifos. i want to arm both interrupts for receiving.

my workaround:

void
_CAN_Receive_ALL (CAN_HandleTypeDef * hcan)
{
HAL_CAN_Receive_IT (hcan, CAN_FIFO0); // start receiving
// make sure both fifos will be checked
__HAL_CAN_ENABLE_IT (hcan, CAN_IT_FMP1);
__HAL_CAN_ENABLE_IT (hcan, CAN_IT_FMP0);
}

Posted on November 13, 2016 at 17:41

Hello there,

I see that the FIFO number is now updated in HAL F4 version 1.1. Was the problem with FMI discussed as well? I see that in the new version the only difference is that ''unsigned'' specifiers were added in the line:

hcan->pRxMsg->FMI = (uint8_t)0xFFU & (hcan->Instance->sFIFOMailBox[FIFONumber].RDTR >> 8U);

Posted on November 13, 2016 at 18:30

I don't think the FMI issue advanced, last I remember you had several tasks to perform, so the validation guys had something to shoot at and I never heard back, so the ticket is probably dead at this point.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on November 13, 2016 at 19:00

You are right, I got buried by other stuff. I am still onto this issue as soon as I get the time to write the testing programs.