Skip to main content
Param sivan
Associate III
February 20, 2018
Question

Example code for stm32f4 SD card read via SPI

  • February 20, 2018
  • 5 replies
  • 4696 views
Posted on February 20, 2018 at 11:27

Hi,

Kindly help me to find out the example code for read/write the SD card via SPI. I am trying to write or copy the files both USB disk and/or SD card. Please advice.

https://community.st.com/tags♯/?tags=stm32f4%20debug%20systemworkbench

4spi &sharpstm32f4 hal driver 

https://community.st.com/tags♯/?tags=iar%20embedded%20workbench

‌

#stm32f4-debug-systemworkbench #sd-card-mmc-stm32cubemx #iar-embedded-workbench #sd-spi-sdio
This topic has been closed for replies.

5 replies

Andrew Neil
Super User
February 20, 2018
Posted on February 20, 2018 at 11:29

http://www.lmgtfy.com?q=SD+Card+SPI+STM32

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
Tesla DeLorean
Guru
February 20, 2018
Posted on February 20, 2018 at 12:28

There should be the AdaFruit shield code under the HAL BSP directories, and some FatFs code in the Application directories.

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
Tesla DeLorean
Guru
February 20, 2018
Posted on February 20, 2018 at 15:38

Command level SPI SD routine

STM32Cube_FW_F4_V1.16.0\Drivers\BSP\Adafruit_Shield\stm32_adafruit_sd.c

Board level SPI SD support routines

STM32Cube_FW_F4_V1.16.0\Drivers\BSP\STM32F4xx-Nucleo\stm32f4xx_nucleo.c

Relatively portable across a number of STM32 platforms/families.

Pretty low performance, I recommend 4-bit SDIO to deliver any sort of usable speed.

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
Param sivan
Associate III
February 28, 2018
Posted on February 28, 2018 at 15:58

Thanks for the link. I had ported the code, but Icouldn't put the SD in the idle state (SD_GoIdleState). I am using SanDisk16 GBmicro sd card. I have tested the data signals of command bytes, it is sending perfectly. The response of sendSD_ANSWER_R1_EXPECTED is 224 not 0x Kindly help to troubleshoot this bug.

Please confirm,

SD_IO_CSState(1) means just HIGH the CS line , Is it? Since most of the data are written to the SD while the CS line is HIGH.

Thanks.

#stm32 spi

#sd%20card%20mmc%20stm32cubemx

#sd%20spi%20sdio

Andrew Neil
Super User
February 20, 2018
Posted on February 20, 2018 at 12:38

http://elm-chan.org/fsw/ff/00index_e.html

 
A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
Daniel Koster
Visitor II
May 9, 2018
Posted on May 09, 2018 at 19:07

I wrote this program (Atollic Studio) for an STM32L4 and it worked for me (tested on 4GB and 16GB cards only).

Hope it helps!

https://embdev.net/topic/451203#5417501

BMora.14
Visitor II
February 25, 2019

I can help you.

Contact me:

behnammoradi026@gmail.com

Andrew Neil
Super User
February 25, 2019

That's nice of you, but a bit late!

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.