Skip to main content
cagibomber
Associate II
August 7, 2012
Question

SPI configuration problem on STM32F4 Discovery

  • August 7, 2012
  • 33 replies
  • 6297 views
Posted on August 07, 2012 at 18:55

Hi everyone,

I am trying to send some bytes of data on a sd-card (8GB) using SPI.

I started with wiring the sd slot and configuring the spi but I have nothing, not even the clock...

I have followed what's explained in the file spi.h and seen other post about spi but I still don't see where I am wrong.

I'd really appreciate if you can help me with it ! Thank you.

#spi-sd-card-stm32-discovery
This topic has been closed for replies.

33 replies

Tesla DeLorean
Guru
August 8, 2012
Posted on August 08, 2012 at 19:45

I wrote the file to the SD card, so the file can be examined when the card is later plugged into a PC. I'm not sure of the merit of loading the file? I read the MESSAGE.TXT to demonstrate reading and computing a file length.

It was done this way so the board could be run head-less (ie without an LCD or serial output), but you could still tell if it accessed the card and used FATFs successfully.

I have a serial port connected to my STM32F4-Discovery, many people do not.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
cagibomber
Associate II
August 8, 2012
Posted on August 09, 2012 at 00:29

Ok I see, but in your code I didn't see any SDIO initialization nor GPIO. I guess you just didn't put this bit in the fatfs example, right ?

Ok I'll try this tomorrow now ! 

Thanks a lot for your help !

Tesla DeLorean
Guru
August 8, 2012
Posted on August 09, 2012 at 00:47

The SDIO and GPIO are initialized from diskio.c disk_init()

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
cagibomber
Associate II
August 9, 2012
Posted on August 09, 2012 at 13:28

cagibomber
Associate II
August 9, 2012
Posted on August 09, 2012 at 13:35

cagibomber
Associate II
August 9, 2012
Posted on August 09, 2012 at 13:56

Ok, I found it in discovery.c and discovery_sdio.c !!! I'll take a look at that !! :)

cagibomber
Associate II
August 9, 2012
Posted on August 09, 2012 at 14:50

I plugged it and launched it, I can observe the command signal sent by the stm32 to the sd card but when I try to read it from my computer, There is nothing ! I reated the 3 txt files in the card and nothing is modified in them ! 

cagibomber
Associate II
August 9, 2012
Posted on August 09, 2012 at 16:53

More investigation showed that res gets FR_DISK_ERR.

res = f_mount(0, &fs32); <<<<<<<<<<<<<<<< Returns FR_OK 

res = f_open(&fil, ''MESSAGE.TXT'', FA_READ); <<< Returns FR_DISK_ERR

I guess it can only come from '&fil' since the file is in the card.

Or, could it be because of the card type ?

I use a Transcend SDHC card (8GB) class 6.

After the simulation, all fil's arguments are equals to 0, even if I put FA_CREAT_NEW.

Thanks.
Tesla DeLorean
Guru
August 9, 2012
Posted on August 09, 2012 at 17:45

Or, could it be because of the card type ? I use a Transcend SDHC card (8GB) class 6.

That or how you have the socket wired up. You'll get errors if the SD card initialization fails, suggest you instrument the code and look at the initialization and card reading code.

I'm using assorted Micro SDHC cards, and I'm using 33K pull-ups based on what was in my parts draw. It is a bit hackish, I have a custom STM32F2 based board with a built-in socket that I do my primary development on, which has a far more considered design.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
cagibomber
Associate II
August 9, 2012
Posted on August 09, 2012 at 19:19

Thanks,

I just check my wiring, it's correct.

Here is my main code :

int main(void){

SD_LowLevel_Init();

err = SD_Init(); // Returns OK

  

NVIC_Configuration(); /* Interrupt Config */

memset(&fs32, 0, sizeof(FATFS));

res = f_mount(0, &fs32); // Ret FR_OK

res = f_open(&fil, ''MESSAGE.TXT'', FA_CREATE_NEW); // Ret FR_DISK_ERR

  while(1){}

}

Since SD_Init returns OK, I guess the SD card initialization is alright. 

What do you mean by ''card reading code'' ?

Thanks again.