STMicroelectronics/stm32l4xx_hal_driver

HAL_SPI_Receive with incorrect length/data pointer parameters renders state stuck in HAL_SPI_STATE_BUSY_RX

Closed this issue · 2 comments

Describe the set-up
Any board, compiler should be logically irrelevant, but tested with GCC 13.2.1
Tested on commit e494650

Describe the bug
When using the HAL_SPI_Receive APIs including IT and DMA derivatives, with a Size/Length of 0, the driver renders the SPI handle stuck in HAL_SPI_STATE_BUSY_RX state after returning an error, preventing further use of the handle. This should also apply if passing NULL pData parameter.

While a 0 input is incorrect, This should reasonably not block further use of the handle after returning an error.

The cause is that the state is set to HAL_SPI_STATE_BUSY_RX on lines 1023, 1689, 2022 in stm32l4xx_hal_spi.c, for the corresponding Polling/Interrupt/DMA Receive API calls, followed by a immediate return of HAL_SPI_TransmitReceive (and IT/DMA type calls).

The state is then never reset before returning an error in the TransmitReceive API on lines 1293, 1803, 2175.

How To Reproduce
Call HAL_SPI_Receive API with a length of 0 at least once, followed by any other API call dependant on the state being ready, such as another Transmit/Receive.

ST Internal Reference: 185358

Fixed in commit 41027c6