Electrical – HAL Library CAN Bus interrupt sources and callback functions

canhal-library

Im using STM32F407 Discovery board and HAL library in CAN bus(CAN1)
Some receive interrupts used with callbacks
(for example receive interruptCAN_IT_RX_FIFO0_MSG_PENDING can be used
HAL_CAN_RX_FIFO0_MSG_PENDING_CALLBACK_CB_ID. CAN_IT_RX_FIFO0_FULL can be used HAL_CAN_RX_FIFO0_FULL_CALLBACK_CB_ID)

1) if i want to trigger callback with this CAN_IT_RX_FIFO0_OVERRUN interrupt. what i need to do? There is no callback function related to this interrupt

2) Can i implement own callback function? Is there a restriction with number of callback functions?

3)When i run the project. the special event occurs (more than 2 Rx message received). Callback is worked. But last if statement didn't work? Why?

uint8_t can1_RxFIFOFullCblk[] = "HAL_CAN_RxFifo0FullCallback\r\n";

void HAL_CAN_RxFifo0FullCallback(CAN_HandleTypeDef *CanHandle)
{
    TxMessage.RTR = CAN_RTR_DATA;
    TxMessage.IDE = CAN_ID_STD;
    TxMessage.DLC = 4;

    HAL_CAN_GetRxMessage(&hcan1,can1_sRxMailBox,&RxMessage,can1_Received );
    TxMessage.StdId = RxMessage.StdId; //Send received message with received message ID

    HAL_CAN_AddTxMessage(&hcan1, &TxMessage, &can1_Received[0], (uint32_t *)can1_sRxMailBox);

    if(__HAL_CAN_GET_FLAG(&hcan1,CAN_FLAG_FF0) == true) //if RX FIFO 0 Full flag is set
    {
        HAL_UART_Transmit(&huart3, (uint8_t*)&can1_RxFIFOFullCblk, sizeof(can1_RxFIFOFullCblk), 5000);
    }

}

Best Answer

  1. You need this.

    HAL_CAN_ActivateNotification(&hcan1, CAN_IT_RX_FIFO0_OVERRUN);
    
  2. I don't know, no idea what you want.

  3. Because, CAL_FLAG_FF0 clears the job before Callback.

    /* Receive FIFO 0 full interrupt management ********************************/
    
    if ((interrupts & CAN_IT_RX_FIFO0_FULL) != 0U)
    {
       if ((rf0rflags & CAN_RF0R_FULL0) != 0U)
       {
          /* Clear FIFO 0 full Flag */
          __HAL_CAN_CLEAR_FLAG(hcan, CAN_FLAG_FF0); <--------------------------- this
    
          /* Receive FIFO 0 full Callback */
    #if USE_HAL_CAN_REGISTER_CALLBACKS == 1
          /* Call registered callback*/
          hcan->RxFifo0FullCallback(hcan);
    #else
          /* Call weak (surcharged) callback */
          HAL_CAN_RxFifo0FullCallback(hcan);     <--------------------------------- Callback
    #endif /* USE_HAL_CAN_REGISTER_CALLBACKS */
       }
    }