STM32C5 HAL SPI: CRC error not reported via error callback when using CRC
Hello,
I am facing an issue with the STM32C5 HAL SPI driver related to CRC error detection.
In my setup, CRC is enabled for SPI. When a CRC error occurs, I can observe that the CRCERR flag is set before the transfer is closed. However, the CRC error is never reported via the HAL error callback.
Looking into the HAL implementation, I noticed the following behavior:
- SPI_CloseTransfer() calls LL_SPI_Disable()
- After disabling SPI, SPI_CloseTransfer() checks LL_SPI_IsActiveFlag_CRCERR()
- When this check is performed after LL_SPI_Disable(), the CRC error is no longer detected
- If I move the LL_SPI_IsActiveFlag_CRCERR() check before LL_SPI_Disable(), the CRC error is detected correctly
Additionally, in my case SPI_CloseTransfer() is called from HAL_SPI_IRQHandler(), but:
- the return value of SPI_CloseTransfer() is not evaluated
- only the Tx/Rx complete callback is invoked
- my error callback is never called, even though a CRC error has occurred
From my understanding:
- LL_SPI_Disable() itself does not clear the CRCERR flag
- therefore, it seems the HAL state machine closes the transfer and reports completion before properly propagating CRC errors
Could you please clarify:
- What is the intended sequence for CRC error detection in the HAL SPI driver?
- Should CRC errors be detected and handled before disabling the SPI peripheral?
- Is this a known issue or limitation in the STM32C5 HAL SPI implementation?
I would appreciate guidance or confirmation whether this is a HAL bug.
Best regards
Christian
