2022-04-18 12:59 PM
The HAL_FDCAN_ErrorCallback is erroneously being called during every interrupt after a Protocol Error (PEA) occurs, even when no error exists during the interrupt. I believe this condition will occur for some of the other interrupts as well (ELO, WDI, PED, ARA).
The HAL_FDCAN_IRQHandler does not appear to correctly clear the Error bits of the FDCAN_HandleTypeDef between interrupt calls. Once a Protocol Error (PEA) occurs the HAL_FDCAN_ERROR_PROTOCOL_ARBT bit is set and never cleared.
Errors = hfdcan->Instance->IR & FDCAN_ERROR_MASK;
Errors &= hfdcan->Instance->IE;
if (Errors != 0U)
{
/* Clear the Error flags */
__HAL_FDCAN_CLEAR_FLAG(hfdcan, Errors);
/* Update error code */
hfdcan->ErrorCode |= Errors;
}
if (hfdcan->ErrorCode != HAL_FDCAN_ERROR_NONE)
{
#if USE_HAL_FDCAN_REGISTER_CALLBACKS == 1
/* Call registered callback*/
hfdcan->ErrorCallback(hfdcan);
#else
/* Error Callback */
HAL_FDCAN_ErrorCallback(hfdcan);
#endif /* USE_HAL_FDCAN_REGISTER_CALLBACKS */
}
I have added clearing the Protocol Error flags to the HAL_FDCAN_ErrorCallback interrupt and that appears to resolve the issue (at least for the Protocol Error issue).
void HAL_FDCAN_ErrorCallback(FDCAN_HandleTypeDef *hfdcan) {
hfdcan->ErrorCode &= ~(FDCAN_IR_ELO | FDCAN_IR_WDI | FDCAN_IR_PEA | FDCAN_IR_PED | FDCAN_IR_ARA);
}
Steps to reproduce: