2025-10-16 3:59 AM
I am using the HAL FDCAN driver in queue mode (STM32G431, FW_G4 V1.6.1).
The application is (intentionally) working with a high bus load (~90%), so it is expected that there will occasionally be times when there are no transmit message buffers available - so HAL_FDCAN_AddMessageToTxFifoQ() is expected to return HAL_Error, as that is what it does if this is the case.
The application code can then use HAL_FDCAN_GetError() to get the ErrorCode (though this seems a bit pointless, as instance->ErrorCode does the same, so not a lot of abstraction here).
However, it only becomes clear from looking at the HAL code that ErrorCode uses bits to represent the set of possible errors - so it is not as simple as comparing the value with HAL_FDCAN_ERROR_FIFO_FULL (the test needs to use a mask operation). The documentation does not explain that this is the case.
How should the error be cleared once it has been handled? The HAL does not provide an API for this, so it appears as if the user is expected to directly alter the device's state through its handle, using something like:
hfdcan1.ErrorCode &= ~HAL_FDCAN_ERROR_FIFO_FULL;
This seems to defeat the point of having an API, which should be abstracting hardware manipulation from the application code (though this could be argued for the whole of the HAL, as I would also have expected all device handles to be opaque pointers to prevent the application from manipulating a driver's state).
Am I missing something?