AnsweredAssumed Answered

Bug in SPI_MasterTransferGetCount()   fsl_spi.c from SDK_2.2_FRDM-KL25Z

Question asked by Wolfgang Bihlmayr Employee on Jul 17, 2018
Latest reply on Jul 18, 2018 by Daniel Chen

Hi,

I'm using the SPI_MasterTransfereGetCount() function to detect when a none-blocking transfer is completed:

  

/* transfere a block of data */
SPI_MasterTransferNonBlocking(BCC_SPI_SPI_BASE, &spi_master_handle, &xfer);  

/* Wait until transfer is finished. */  
while ( (kStatus_NoTransferInProgress != SPI_MasterTransferGetCount(BCC_SPI_SPI_BASE, &spi_master_handle, &count)) && (timeout > 0U))   
{  
     timeout--;   
}

Debugging the problem I found that the following line is incorrect:

status_t SPI_MasterTransferGetCount(SPI_Type *base, spi_master_handle_t *handle, size_t *count)
{
    assert(handle);
    status_t status = kStatus_Success;

//    if (handle->state != kStatus_SPI_Busy)    /* wrong */
    if (handle->state != kSPI_Busy)    /* correct */
    {
        status = kStatus_NoTransferInProgress;   
    }
    else   
    {        /* Return remaing bytes in different cases */       
        if (handle->rxData)
        {
            *count = handle->transferSize - handle->rxRemainingBytes;
        }
        else
        {
            *count = handle->transferSize - handle->txRemainingBytes;
        }
    }
    return status;
}

Outcomes