cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_SPI_Abort_IT() does not call HAL_SPI_AbortCpltCallback() upon completion

AMacd.1
Senior

I have an SPI slave running on STM32L4 in DMA mode.   Here is the basic structure (simplified for this posting):

 

#define NSS (HAL_GPIO_ReadPin( SPI3_NSS_GPIO_Port, SPI3_NSS_Pin ))
#define BUFFERSIZE 32

uint8_t SpiTxBuffer[BUFFERSIZE], SpiRxBuffer[BUFFERSIZE];

typedef enum
{
  Idle,
  Wait,
  Abort,
  Done
} State_t;

State_t State = Idle;

int main(void)
{
  /*
    Usual MX boilerplate here.
  */
  while(1)
  {
    switch (State)
    {
      case Idle:
        if(!NSS)
        {
          if( HAL_SPI_TransmitReceive_DMA( &hspi, SpiTxBuffer, SpiRxBuffer,
              BUFFERSIZE ) != HAL_OK )
          {
            Error_Handler();
          }
          State = Wait;
        }
        break;

      case Wait:
        if(NSS)
        {
          if( HAL_SPI_Abort_IT(&hspi) == HAL_OK)
          {
            State = Abort;
          }
          else
          {
            Error_Handler();
          }
        }
        break;

      case Abort:
        break;

      case Done:
        DoSomethingWithTheData();
        State = Idle;
    }
    DoSomethingElse();  /*Do some task while waiting for SPI to arrive*/
  }
}

void HAL_SPI_TxRxCpltCallback(SPI_HandleTypeDef *hspi)
{
  State = Done;
}

void HAL_SPI_AbortCpltCallback(SPI_HandleTypeDef *hspi)
{
  State = Done;
}

 In this circumstance, if the host (master) sends fewer bytes than expected and deactivates NSS, I detect this and abort the SPI exchange.  However, the AbortCallback never gets called as evidenced by the fact that State never gets set to DONE.

Any ideas?

Edit: Fixed a typo

0 REPLIES 0