STMicroelectronics / stm32l4xx_hal_driver

Provides the STM32Cube MCU Component "hal_driver" of the STM32L4 series.
BSD 3-Clause "New" or "Revised" License
30 stars 14 forks source link

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

Open mmarciniewski opened 6 days ago

mmarciniewski commented 6 days ago

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

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.

KRASTM commented 4 days ago

ST Internal Reference: 185358