SD SPI on K8x response error on spi_exchange

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

SD SPI on K8x response error on spi_exchange

Jump to solution
1,847 Views
deniscollis
Contributor V

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.

pastedImage_1.png

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

Labels (1)
Tags (4)
0 Kudos
1 Solution
1,678 Views
deniscollis
Contributor V

The MicroSD slot pinouts were wired incorrectly to the MCU!  The physical board did not match the schematic! 

View solution in original post

0 Kudos
7 Replies
1,678 Views
Sabina_Bruce
NXP Employee
NXP Employee

Hope you are well.

Ok not a problem. I recommend to check the following document that uses a KL2x family device. However, the concepts are the same and you may refer to each step in case you missed anything in particular. From your schematic nothing pops out that would be a cause. It may also help if you can get the wave form of the SPI lines to see if what is being sent is also correct and make it easier to debug. 

https://community.nxp.com/docs/DOC-330958 

Best Regards,

Sabina

0 Kudos
1,678 Views
deniscollis
Contributor V

Thanks for that Sabina.

It looks like it may be a hardware design fault.  I immediately noticed that the circuit design in the document that you referenced is quite different.  It has PULL-DOWN resistors on DAT1 and DAT2 signals...

pastedImage_1.png

...while manufacturer's specify pull-ups, like this one from Kingston:

pastedImage_2.png

 

Mine has PULL-UP resistors on DAT1 and DAT2 only, and no pull-ups on any on the SPI signals at all, and so relies on the K8I's internal pad pull-ups instead.  I also notice from your reference document that the pull-ups/downs are quite strong – 10KΩ, while my pull-ups are much weaker –  100KΩ for the external pull-ups, and I think the K8x internal pull-ups are somewhere in-between – 47KΩ.

This is what happens electrically;

With and SD card inserted, if I apply the K8x pad pull-ups, with no VDD present, then the card keeps all SPI signals low.  When VDD is applied, the card releases CS, CK and  MISO, and they immediately go high, but MOSI appears to remain driven low by the SD card. 

Thanks,

Denis

0 Kudos
1,678 Views
deniscollis
Contributor V

Looks like it was a hardware issue - the internal pull-ups may not be strong enough. I soldered some 10K pull-ups on:

  • CMD/DI - SPI_MOSI
  • DAT0/DO - SPI_MISO
  • DAT3/CS - SPI_CS. 
  • DAT1 & DAT2

MicroSD_w_pullups.jpg

Now, all the pins, including MISO, are at the correct levels.

0 Kudos
1,679 Views
deniscollis
Contributor V

The MicroSD slot pinouts were wired incorrectly to the MCU!  The physical board did not match the schematic! 

0 Kudos
1,678 Views
Sabina_Bruce
NXP Employee
NXP Employee

Hello Denis,

Hope you are doing well.

Could you please confirm the version of the SDK and IDE that you are using? Are you working on a custom board? 

Are you able to reproduce this error using an evaluation board, so that I may test this on my end.

Best Regards,

Sabina

-----------------------------------------------------------------------------------------------------------------------

Note: If this post answers your question, please click the Correct Answer button. Thank you!

----------------------------------------------------------------------------------------------------------------------- 

0 Kudos
1,678 Views
deniscollis
Contributor V

Hi Sabina,

MCUXpresso IDE v11.1.1 [Build 3241] [2020-03-02]

SDK_2.x_MK81FN256xxx15, Version 2.6.0 (228 1019-06-14), Manifest Version 3.5.0

SDK_2.x_MK82FN256xxx15, Version 2.6.0 (228 1019-06-14), Manifest Version 3.5.0

This is a custom board.

I don't have an evaluation board equipped with its own MicroSD socket.  But I do have a Freedom K82F board. I'll see if I can add a MicroSD socket, using a breadboard.

Best,

Denis

0 Kudos
1,678 Views
deniscollis
Contributor V

Okay, I have this (uses SPI2, like the custom board):

FRDM_K82F_With_MicroSD.jpg

0 Kudos