2025-08-10 5:34 AM
Hi all,
Recently I faced pretty bug in the HAL implementation.
I am using STM32F103 with CubeMx 6.12.1 HAL, (but inside the SPI C-code I saw 2016th year).
SPI configured as Full-Duplex slave (using HW NSS, but it's doesn't matter).
Sometimes I had to abort a transaction, and after the abort I got HardFault.
Bug repeat sequence is:
1. Start SPI Rx over Interrupt
2. Abort Rx
3. Start SPI Tx over interrupt
4. Wait for receive all bytes
After figuring out, I found, that Abort handler does not clear SPI_CR2_TXEIE and SPI_CR2_RXNEIE flags in the SPIx_CR2 reg.
Therefore, after start Tx after Rx aborted, hspi->RxISR clears to NULL, but opposite TXIE flag kept set.
Then on an any byte completion the condition on stm32f1xx_hal_cpi.c:2447 appears true, but hspi->RxISR already set to NULL, which raises HardFault.
My proposal is:
1. Clear xxIE flags during Abort (to fix exact this bug)
2. Use HAL_SPI_ErrorCallback instead of NULL everywhere when hspi->RxISR and hspi->TxISR is setting to state when the interrupt is unexpected (to make easier found some other one if appeared)
Patch that solves the issue is attached to the message
2025-08-10 6:23 AM
Are you on the latest library? I feel like the abort logic is implemented here:
RXNEIE gets cleared here: