STM32G4 FDCAN HAL Driver Issue (v1.5.0)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
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:
- Setup the STM32G4 with a working CAN bus (any bit rate, properly terminated, at least one other device to acknowledge frames).
- Use the HAL to Configure and Activate the interrupt for the ARB_PROTOCOL_ERROR.
- Remove termination from the CAN bus.
- Attempt to transmit a CAN frame onto the bus using the HAL, this should cause a Protocol Error to occur.
- Observe that the HAL_FDCAN_ErrorCallback is correctly called for each Protocol Error.
- Replace the termination on the CAN bus.
- Transmit another frame on the CAN bus, this should result in a successful transmission.
- Observe that the HAL_FDCAN_ErrorCallback is erroneously called during every other CAN interrupt even when there are no Protocol Errors.
