cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4 Discovery - interfacing SD card with SPI & FatFS

alakazam36
Associate II
Posted on September 03, 2015 at 18:35

Greetings all,

recently I am struggling with interfacing my

http://www.st.com/web/catalog/tools/FM116/SC959/SS1532/PF252419

with a 2 GB SD card (via

http://i.ebayimg.com/00/s/NjAwWDYwMA==/z/CDsAAOxy-W9SNHsJ/$%28KGrHqFHJEwFIpUwwZ02BSNHsJT5EQ~~60_35.JPG

) with SPI & FatFS. I have tried to modify examples from Geoffrey Brown's

http://www.cs.indiana.edu/~geobrown/book.pdf

, as well as

http://stm32f4-discovery.com/2014/07/library-21-read-sd-card-fatfs-stm32f4xx-devices/

, but both unsuccessful (I am relatively new to embedded coding).

I would like the microcontroller to write lines of text (measurements) into a text file on the SD card. Does anyone happen to have a working example that could help me with my project, prefereably for the board I use? Thank you very much.

Kind regards,

James C

5 REPLIES 5
Posted on September 03, 2015 at 19:17

The examples, and I've posted a lot of them here, for the STM32F4-DISCO use SDIO because SPI is just a ridiculously slow way of connecting, and why you really don't see a lot of examples of it being used.

The examples include a socket wire-wrapped onto an STM32F4-DISCO, and using an STM32F4-DIS-BB breakout board.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
alakazam36
Associate II
Posted on September 03, 2015 at 20:29

Thank you for your reply. After a Google search I came across [DEAD LINK /public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/STM32%20sdio%20sdhc%204gb%20problem&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&currentviews=102]this thread and

https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=https%3a//my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/SDIO%20and%20SD%20fat%20access%20example&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&currentviews...

.

Currently I only have the before mentioned SD card SPI module at hand, with pins: gnd, vcc, miso, mosi, sck, sdcs. Is it possible to use your SDIO example with my current configuration, or will I have to wait and get myself an SDIO breakout module?

Thank you and kind regards,

James C

Posted on September 04, 2015 at 04:59

Unfortunately the image of the module gives me little insight into what you've actually got, or how the modules's PCB is wired up. Please cite something with a part number or diagram.

The SD card has very few pins, given the size of the pin header I'd have to assume most everything is connected, and at the very least you could get 1-bit SDIO functional. You'd have to decipher the pin naming/connectivity.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
tm3341
Associate II
Posted on September 04, 2015 at 08:24

Hi james.c,

you tried example from me, stm32f4-discovery.com website.

I would like to know what didn't worked for you?

If you mounted card OK but were unable to open file, that's probably because my FATFS modification (ffconf.h) uses dynamic allocation for file name using malloc, so you need enough heap. If this failed, f_open should return you FR_NOT_ENOUGH_CORE result.

alakazam36
Associate II
Posted on September 04, 2015 at 13:01

I will reply both of you in this post:

@clive1

About the module - pairs in 8x2 pin header are connected, which leaves 8 pins. And of those 2 are gnd and 2 are vcc (3,3 and 5 V). The schematic on the module suggests SPI pins correspond to SD interface as follows:

miso->dat0

gnd->gnd

sck->clk

3.3V->vcc

gnd->cmd

mosi->dat3

cs->dat2

After comparing to schematics on Wikipedia article on SD cards, I am not too confident about the accuracy of these. So I am thinking about resorting to something in the

http://cdn.instructables.com/FHX/CDNZ/FYAJCAIZ/FHXCDNZFYAJCAIZ.MEDIUM.jpg

. Can you tell, from the ''pinout,'' whether I can use the 1-bit SDIO interface and your example?

@majele.tilen

I ''placed'' LEDs after specific parts of code to monitor the code execution. And even if (f_mount(&FatFs, ''0:'', 1) == FR_OK) doesn't succed. So the execution then ends in while(1) loop. My defines were SPI1, TM_SPI_PinsPack_2 and FATFS_USE_SDIO 0.