Skip to main content
Associate
Question

How to communicate STM32F429 discovery with SD card using SPI communication?

I'm working on a project on STM32F429 discovery board, because of the small size of the internal flash I have used SD card module with SPI communication standard to store the images

For the STM32F429 Discovery board, I have developed functional code to read data from an SD card via the SPI4 interface.
The failure encountered while working with the SD card was not due to a single bug, but rather a chain of five architectural and software-related mismatches between FatFs, FreeRTOS, the HAL SPI4 driver, and the hardware
protocol for microSD initialization.

Errors occur consistently during SD card initialization.

14 replies

Associate

Here is a working, verified example for the STM32F4 Discovery board.

ST Technical Moderator

Hi ​@AVKrobotics 

Thanks for sharing the setup. From the files provided, we don’t have enough information yet to identify the exact initialization failure. A waveform capture of CS, SCK, MOSI, and MISO around CMD0, CMD8, and ACMD41 would help distinguish a wiring/configuration problem from a command response or timeout problem.

To narrow down the failure, share the last diagnostic step, the SPI4 and GPIO initialization (including SPI mode, bit order, and clock), and the relevant signal capture or raw command responses. 

The driver uses byte addressing but does not issue CMD16 to set a 512 byte block length.

For your information, USER_ioctl() reports a fixed capacity of 32,768 sectors (16 MiB) and a fixed block size of 128 sectors. Those values are not derived from the card, so they can make FatFs report incorrect capacity or use an unsuitable format alignment. 

        case GET_SECTOR_COUNT:
*(DWORD *)buff = 32768UL;
res = RES_OK;
break;

case GET_BLOCK_SIZE:
*(DWORD *)buff = 128UL;
res = RES_OK;
break;

 

To give better visibility on the answered topics, please click on "Best answer" on the reply which solved your issue or answered your question.Best regards,FBL