7 years, 6 months ago.

Problems with Nucleo L152RE / F401RE and SD Card Library

Hello everybody, I'm experiencing a lot of problems interfacing my nucleo boards with the sd breakout module to perform read/write actions. Here i report the steps i took and what i've tried. Imported the SD Card library from : https://developer.mbed.org/cookbook/SD-Card-File-System into Mbed Online Compiler.

Wiring scheme :

  • SCLK->SCLK
  • MOSI->MOSI
  • MISO->MISO
  • SS-->SS

SD card interfaces that i've tried: 

Nucleo Boards tested:

  • F401RE
  • L152RE

SD CARDs:

  • Sandisk Class 4, 2 Gb
  • Sandisk SDHC class 10, 8Gb

Sd card formatting:

  • Fat16
  • Fat32

Onboard SPI Interfaces :

  • Both the 2 available interfaces on both the boards.

Moreover:

  • Removed Xnucleo Expansion board ( previously present at project start)
  • Tried to power-up the SD breakout board  through Nucleo 5V pin, than with an external power source.
  • Used default code to test ( the one inside the library)

Every combination of the previously reported materials and schemes is giving:

"Could not open file for read" or "Set 512-byte block timed out."

Is someone experiencing the same problems? is someone aware of some buggy code in the library?

2 Answers

7 years, 6 months ago.

Yes, I was not able to get the SD library to work on an F446 despite multiple attempts. The ST stock example code for IAR worked fine but the Cube software export has a bug in it. Then I found this https://developer.mbed.org/users/neilt6/code/SDFileSystem_HelloWorld/

My changes for my F446 were as follows

Timer timer;
DigitalIn button(PC_13, PullUp);

SDFileSystem sd(PC_12, PC_11, PC_10, PC_8, "sd", PA_8, SDFileSystem::SWITCH_NONE, 25000000);
char buffer[4096];


and all was good!

Pinout on my board to micro SD was as follows

  • PIN# SDIO SPI3
  • PIN1 DAT2 GND
  • PIN2 DAT3 CSn
  • PIN3 CMD MOSI
  • PIN4 VDD
  • PIN5 CLK SCK
  • PIN6 GND
  • PIN7 DAT0 MISO
  • PIN8 DAT1 RSV

7 years, 6 months ago.

Several months ago I used an SD library with mbed 2 on an F401RE board and it worked first time I powered it on. Also used it successfully with mbed 5. The Arduino board has a level shifting interface which you don't need. Might even cause issues if it's expecting 5V spi input. You can just run card pins right to the micro. I used this thing:

https://www.sparkfun.com/products/12941

Then something like this:

SDFileSystem sd(D11, D12, D13, D10, "sd", NC, SDFileSystem::SWITCH_NONE, 1400000);