AnsweredAssumed Answered

SD SPI on K8x response error on spi_exchange

Question asked by Denis Collis on Jul 8, 2020
Latest reply on Jul 20, 2020 by Denis Collis

I am new to SD SPI, using ELM_CHAN FatFs with fsl_sdspi, interfacing with a MicroSD card.  Can anyone help figure out why I'm getting kStatus_SDSPI_ResponseError.

 

 

Traceback:

K8x_FatFS_demo JLink Debug [GDB SEGGER Interface Debugging]
K8x_FatFS_demo.axf
Thread #1 57005 (Suspended : Breakpoint)
SDSPI_SendCommand() at fsl_sdspi.c:373 0x7d8
SDSPI_GoIdle() at fsl_sdspi.c:425 0x8d0
SDSPI_Init() at fsl_sdspi.c:1,091 0x1674
sdspi_disk_initialize() at fsl_sdspi_disk.c:171 0x198e
disk_initialize() at diskio.c:127 0x5110
main() at FatFSdemo.c:50 0x528
arm-none-eabi-gdb (8.3.0.20190703)

 

Code Excerpts:

 

/* fatfs_0.11a/src/fsl_sdpi_disk/fsl_sdspi_disk.c */
:
:

status_t spi_exchange(uint8_t *in, uint8_t *out, uint32_t size)
{
dspi_transfer_t masterTransfer;

masterTransfer.txData = in;
masterTransfer.rxData = out;
masterTransfer.dataSize = size;
masterTransfer.configFlags = (kDSPI_MasterCtar0 | DSPI_MASTER_PCS_TRANSFER | kDSPI_MasterPcsContinuous);
return DSPI_MasterTransferBlocking((SPI_Type *)BOARD_SDSPI_SPI_BASE, &masterTransfer);
}

:
:

void sdspi_host_init(void)
{
/* Initializes timer to make host's callback function "timer_get_current_milliseconds" workable. */
timer_init();

/* Saves host state and callback. */
g_host.busBaudRate = DSPI_BUS_BAUDRATE;
g_host.setFrequency = spi_set_frequency;
g_host.exchange = spi_exchange;
g_host.getCurrentMilliseconds = timer_get_current_milliseconds;

/* Saves card state. */
g_card.host = &g_host;
}

:
:

 

/* sdmmc_2.1.1/src/fsl_sdspi.c */

:
:

static status_t SDSPI_SendCommand(sdspi_host_t *host, sdspi_command_t *command, uint32_t timeout)

:
:

/* Wait for the response coming, the left most bit which is transfered first in first response byte is 0 */
for (i = 0U; i < 9U; i++)
{
if (kStatus_Success != host->exchange(&timingByte, &response, 1U))
{
return kStatus_SDSPI_ExchangeFailed;
}

/* Check if response 0 coming. */
if (!(response & 0x80U))
{
break;
}
}
if (response & 0x80U) /* Max index byte is high means response comming. */
{
return kStatus_SDSPI_ResponseError; /* <<< Breakpoint Set Here <<< */
}

:
:

 

Inspecting variable: response has value 0xFF.  MSB remained 1 for the 9 exchange cycles, so clearly it never hit the break.  

 

 

Thanks,

Denis

Outcomes