cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_SPI_TransmitReceive_IT() issue in STM32Cube_FW_F4_V1.11.0

vincent
Associate II
Posted on March 02, 2016 at 16:16

Hello,

We are facing to an issue when we test HAL_SPI_TransmitReceive_IT() function with SPI high speed.

We can observe that, when SPI global interrupts occur and HAL_SPI_IRQHandler() is called, the process Tx->Rx - Tx>Rx is not respected and sometimes Overrun error is notified.

Indeed,we can observe the following scenario:

- HAL_SPI_TransmitReceive_IT() is called to transmit/receive few bytes

- HAL_SPI_IRQHandler() is called : SPI TXE Interrupt is detected. Consequently, SPI_2linesTxISR_16BIT() function is called. In this function, next byte to transmit is setting directly in the 'hspi->Instance->DR' register without wait for Rx data

- HAL_SPI_IRQHandler() is called : SPI TXE Interrupt is detected but not the SPI RXNE Interrupt. For this reason, we have lost the Rx data on the SPI peripheral. 

In order to solve this issue, we have added code in the SPI_2linesRxISR_16BIT() and SPI_2linesTxISR_16BIT() functions

static void SPI_2linesTxISR_16BIT(struct __SPI_HandleTypeDef *hspi)

{

  /* Transmit data in 16 Bit mode */

  hspi->Instance->DR = *((uint16_t *)hspi->pTxBuffPtr);

  hspi->pTxBuffPtr += sizeof(uint16_t);

  hspi->TxXferCount--;

  /* Enable CRC Transmission */

  if(hspi->TxXferCount == 0U)

  {

&sharpifdef USE_SPI_CRC

    if(hspi->Init.CRCCalculation == SPI_CRCCALCULATION_ENABLE)

    {

      SET_BIT(hspi->Instance->CR1, SPI_CR1_CRCNEXT);

    }

&sharpendif

    /* Disable TXE interrupt */

    __HAL_SPI_DISABLE_IT(hspi, SPI_IT_TXE);

    if(hspi->RxXferCount == 0U)

    {

      SPI_CloseRxTx_ISR(hspi);

    }

  }

 else {

  __HAL_SPI_DISABLE_IT(hspi, (SPI_IT_TXE )); // Code added to fix the issue

 }

}

static void SPI_2linesRxISR_16BIT(struct __SPI_HandleTypeDef *hspi)

{

  /* Receive data in 16 Bit mode */

  *((uint16_t*)hspi->pRxBuffPtr) = hspi->Instance->DR;

  hspi->pRxBuffPtr += sizeof(uint16_t);

  hspi->RxXferCount--;

  if(hspi->RxXferCount == 0U)

  {

&sharpifdef USE_SPI_CRC

    if(hspi->Init.CRCCalculation == SPI_CRCCALCULATION_ENABLE)

    {

      hspi->RxISR =  SPI_2linesRxISR_16BITCRC;

      return;

    }

&sharpendif

    /* Disable RXNE interrupt */

    __HAL_SPI_DISABLE_IT(hspi, SPI_IT_RXNE);

    if(hspi->TxXferCount == 0U)

    {

      SPI_CloseRxTx_ISR(hspi);

    }

  }

 else {

  __HAL_SPI_ENABLE_IT(hspi, (SPI_IT_TXE ));// Code added to fix the issue

 }

}

#hal-spi-stm32cube
2 REPLIES 2
Walid FTITI_O
Senior II
Posted on March 07, 2016 at 11:40

Hi tardy.vincent,

Thanks for your feedback and contribution. I will report you input to our team for verification.

-Hannibal-

Imen.D
ST Employee
Posted on January 19, 2017 at 18:41

Hello @

 ,

This issue is fixed in the HAL driver v1.5.0.

Please update your firmware version to use the last one with fix defects.

Thank you for highlighting the issue, and Sorry for any inconvenience it may bring for you.

Best Regards

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen