I'm trying to do a basic read/write on an SD card interfaced to my KL46Z256VLL4 eval board via SPI. I'm using the fsl_sdcard and the fsl_spi components to read/write from/to the SD card.
I'm using the SDSPI_DRV_Init and SDSPI_DRV_Write functions of the fsl_sdcard component to attempt to write data to the SD card:
SDSPI_DRV_Init(&memoryCard1_spi_state, &memoryCard1_state); SDSPI_DRV_WriteBlocks(&memoryCard1_spi_state, &memoryCard1_state, "test", 0, 1); debug_getchar();
However, nothing seems to happen. Upon closer inspection with a logic analyzer, I noticed there's no activity at all on the SPI pins. I then dig into the component files and see the lower level SPI functions (spiSendWord, spiExchange, etc.) are not implemented within "spi_dspi_layer.c". Am I responsible for implementing that portion of the SPI interface?
Excerpt of spi_dspi_layer.c:
/** * Function sets required speed of SPIx/DSPI */ uint32_t SetSpiFrequency(sdspi_spi_t *spi, uint32_t frequency) { uint32_t calculatedBaudRate = 0x00; /* User Code: Calling of the SPI/DSPI method that provides setting of SPI/DSPI transfer speed */ if (calculatedBaudRate == 0x00) { return 0x01; } return 0x00; } /** * Function performs transmission of the input data buffer via SPIx/DSPI */ uint32_t spiExchange(sdspi_spi_t *spi, const uint8_t *in, uint8_t *out, uint32_t size) { uint8_t result = 0x00; /* User Code: Calling of the SPI/DSPI method that provides blocking transfer over SPI/DSPI */ return result; } /** * Function performs transmission of the input byte */ uint8_t spiSendWord(sdspi_spi_t *spi, uint8_t word) { uint8_t result = 0x00; /* User Code: Calling of the SPI/DSPI method that provides blocking transfer of 1B over SPI/DSPI */ return result; }
Original Attachment has been moved to: SDRawWrite.zip
Hello Farhan Naeem:
Yes, you need to add the SPI driver methods, but you can use the configuration and methods of the inherited fsl_spi compoment.
The next files in KSDK installation might serve you as reference on how to implement those calls:
C:\Freescale\KSDK_1.2.0\middleware\filesystem\fatfs\fsl_sd_disk\src\fsl_sdspi_disk.c
C:\Freescale\KSDK_1.2.0\platform\composite\inc\fsl_sdcard_spi.h
C:\Freescale\KSDK_1.2.0\platform\composite\src\sdcard\fsl_sdcard_spi.c
I hope this helps.
Regards!
Jorge Gonzalez