2016-05-09 04:53 PM
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 ofstatic HAL_StatusTypeDef CAN_Receive_IT(CAN_HandleTypeDef* hcan, uint8_t FIFONumber){
hcan->pRxMsg->FIFONumber = FIFONumber;
... rest of function
}
This works for me.
2016-05-23 07:37 AM
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-
2016-06-06 07:41 PM
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.
2016-09-15 01:50 AM
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¤tviews=53]thread1-Hannibal-
2016-09-18 04:06 PM
Hi Hannibal,
thanks for the update. That is exactly what I recommended in the very first post.