AnsweredAssumed Answered

STM32F04 CAN RX Interrupt hits twice then stops

Question asked by Jean Paul Talledo Vilela on Oct 13, 2017
Latest reply on Oct 13, 2017 by Jean Paul Talledo Vilela

I migrated the HAL libraries to the latest one. I had been working on my CAN TX Queue but not it looks like my CAN1_RX0_IRQHandler is called twice. The first one gets a good CAN packet, the second time looks like it detects an error and then it never gets called again.

 

During my migration to the new HAL library, I need to made this change to my code:

 

void HAL_CAN_RxCpltCallback(CAN_HandleTypeDef* CanHandle)
{
    if(CanHandle == NULL)
        return;
    
    CCanBus *pCanBus = (CCanBus*) CanHandle->pObject;
    
    // call the aplication callback function
    if (pCanBus->canEventCallback != NULL)
        pCanBus->canEventCallback(pCanBus->pCallbackObject, Callback_RX);

 

    if (CanHandle->State == HAL_CAN_STATE_BUSY_TX)
       // CanHandle->State = HAL_CAN_STATE_BUSY_TX_RX;
       CanHandle->State = HAL_CAN_STATE_BUSY_TX_RX0;
    else
    {
        //CanHandle->State = HAL_CAN_STATE_BUSY_RX;
        CanHandle->State = HAL_CAN_STATE_BUSY_RX0;

 

        /* Set CAN error code to none */
        CanHandle->ErrorCode = HAL_CAN_ERROR_NONE;

 

        /* Enable Error warning Interrupt */
        __HAL_CAN_ENABLE_IT(CanHandle, CAN_IT_EWG);

 

        /* Enable Error passive Interrupt */
        __HAL_CAN_ENABLE_IT(CanHandle, CAN_IT_EPV);

 

        /* Enable Bus-off Interrupt */
        __HAL_CAN_ENABLE_IT(CanHandle, CAN_IT_BOF);

 

        /* Enable Last error code Interrupt */
        __HAL_CAN_ENABLE_IT(CanHandle, CAN_IT_LEC);

 

        /* Enable Error Interrupt */
        __HAL_CAN_ENABLE_IT(CanHandle, CAN_IT_ERR);
    }

 

    if(pCanBus->fifoNumber == 0)
        // Enable FIFO 0 message pending Interrupt
        __HAL_CAN_ENABLE_IT(CanHandle, CAN_IT_FMP0);
    else
        // Enable FIFO 1 message pending Interrupt
        __HAL_CAN_ENABLE_IT(CanHandle, CAN_IT_FMP1);      
}

 


Where I replaced:

 

// CanHandle->State = HAL_CAN_STATE_BUSY_TX_RX;   by


  CanHandle->State = HAL_CAN_STATE_BUSY_TX_RX0;

 

 

So when the CAN1_RX0_IRQHandler gets called for the first time there is a FIFO overrun flag which it is clear by the HAL library and I am able to process a received CAN message.

 

In the Second time, my callback for CAN error is get called but I am reading the error only. Should I do something else?

 

Which I dont understand is why the Interrupt stops get called? does the HAL library somehow disabling it?

Outcomes