cancel
Showing results for 
Search instead for 
Did you mean: 

[Solution] STM32 HAL SPI Slave HardFault if using Abort

remixoff
Visitor

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

1 REPLY 1
TDK
Super User

Are you on the latest library? I feel like the abort logic is implemented here:

https://github.com/STMicroelectronics/stm32f1xx-hal-driver/blob/18074e3e5ecad0b380a5cf5a9131fe4b5ed1b2b7/Src/stm32f1xx_hal_spi.c#L2088

RXNEIE gets cleared here:

https://github.com/STMicroelectronics/stm32f1xx-hal-driver/blob/18074e3e5ecad0b380a5cf5a9131fe4b5ed1b2b7/Src/stm32f1xx_hal_spi.c#L3957

 

If you feel a post has answered your question, please click "Accept as Solution".