spi_hal.c has potential problem

In looking at spi_hal.c they have the following (see below).
There should never be a while condition like this inside a call. Should the SPI device fail it would lock up the rest of the code who called this from continuing. They should instead add another parameter to pass along a timeout value to the call. So when called if nothing returns after this timout value passed it can let the caller know it failed with say a -1 value.

uint16_t HAL_SPI_Send_Receive_Data(HAL_SPI_Interface spi, uint16_t data)
{
  /* Wait for SPI1 Tx buffer empty */
  while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);
  /* Send SPI1 data */
  SPI_I2S_SendData(SPI1, data);

  /* Wait for SPI1 data reception */
  while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET);
  /* Read and return SPI1 received data */
  return SPI_I2S_ReceiveData(SPI1);
}
2 Likes