AnsweredAssumed Answered

freertos spi : wait transfer to finish problem

Question asked by Maxime Dolberg on Jul 17, 2016
Latest reply on Sep 18, 2016 by Daniel Chen



I am facing problems with  fsl_spi_freertos API lib. When I use  SPI_RTOS_Transfer() method (see detail below) with a output data length less then 4 bytes, SPI_RTOS_Transfer() stuck forever at :


/* Wait for transfer to finish */ xSemaphoreTake(handle->event, portMAX_DELAY);


portMAX_DELAY set timeout to an infinity duration. And if I change portMAX_DELAY to 100ms for example, error happen at next call of SPI_RTOS_Transfer() with an error type  kStatus_SPI_Busy. So no transfer occurred at the second call.


To resume :

//Call with timeout = portMAX_DELAY SPI_RTOS_Transfer() //Wait transfer to finish for ever  ...  //First call with timeout = 100ms. SPI_RTOS_Transfer() //Ok, no problem  //Second call and so on SPI_RTOS_Transfer() //method return error  kStatus_SPI_Busy



Now, if a I do the same thing with 4 bytes output, SPI_RTOS_Transfer() don't block at all in any case...


And this is pretty annoying because my application does a lot of quick SPI transfer with less then 4 bytes.


So why and how can I solve this ?


I am working with FRDM-KL46Z, KSDKv2, KDSv3


Here is the FreeRTOS SPI method (from fsl_spi_freertos.c)

status_t SPI_RTOS_Transfer(spi_rtos_handle_t *handle, spi_transfer_t *transfer) {     status_t status;      /* Lock resource mutex */     if (xSemaphoreTake(handle->mutex, portMAX_DELAY) != pdTRUE)     {         return kStatus_SPI_Busy;     }      status = SPI_MasterTransferNonBlocking(handle->base, &handle->drv_handle, transfer);     if (status != kStatus_Success)     {         xSemaphoreGive(handle->mutex);         return status;     }      /* Wait for transfer to finish */     xSemaphoreTake(handle->event, portMAX_DELAY);      /* Unlock resource mutex */     xSemaphoreGive(handle->mutex);      /* Return status captured by callback function */     return handle->async_status; }