L053R8 Nucleo SD Card HelloWorld - can't init SD card


I’m on an L053R8 Nucleo board, hence on MBed 2 version (can’t upgrade; or haven’t found an easy way to do so!), and trying to implement a basic SD-Card handling program.

I have tried this:
but I get, with a 2Gb older card:

No disk, or could not put SD card in to SPI idle state

while on a 8Gb, or another 16Gb SDHC card:

Timeout waiting for v2.x card
Fail to initialize card
Timeout waiting for v2.x card
Fail to initialize card
Could not open file for write

Having different results for the two cards makes me think the physical wiring is correct, as I get some response form the SPI. I’m using SPI1 (D4, D5, D3, D2 for mosi, miso, sclk, cs, respectively) from the board.

I also tried a different lib (following suggestions from an older similar post):

But on the 8Gb I still get

Mounting SD card...failed!

I’ve also compared code with the MBed6 version of SDBlockDevice.cpp and tried importing the init section into my SD libs:

still without success: from 2Gb card I get a response 0x00 at CMD0, from 8Gb I get 0xFF.

What else could I try?
Thanks in advance


I tried the old (your first link) one and SDFileSystem.cpp at line 127 contains a settings _init_sck = 100000; in my case it was necessary to set it to 350000.

I had issue with "Could not open file for write", but it disappeared without any change of code.

SDHC 4GB connected to Nucleo-L432KC.

BR, Jan

Hi Jan, thanks for your suggestion.
Indeed, init frequency should be set beyond 125KHz, or the spi isn’t initialized at all. Infact my tests happen @400KHz.
I’m suspecting the powering scheme, having read somewhere that the board 3.3V doesn’t provide enough current, especially if the board is powered through the USB only (as I’m doing). How did you power your L432KC?

Hello Fabio,

My board is powered only via USB and the SD card breakout board is powered from Nucleo’s 5V pin.

Br, Jan

I made a fundamental mistake: powering the adapter with 3.3V!
Thanks, for making me realize that.