Showing results for 
Search instead for 
Did you mean: 

Problems with microSD card module and Nucleo-L432KC

Emilio Andreozzi
Associate II
Posted on May 12, 2017 at 12:49


seems that I'm having many problems using the peripherals I need for my MSc Thesis project with the Nucleo-L432KC.

Now it's time to have problems with the microSD card module.

I bought this module:



I'm using the library SDFileSystem.h from

 and I tried the example program on my Nucleo-L432KC with these connections:

SD card module  |  Nucleo-L432KC

         CS           --->         D3 (SPI1_NSS)

         SCK        --->          A4 (SPI1_SCK)

         MOSI      --->          A6 (SPI1_MOSI)

         MISO      --->          A5 (SPI1_MISO)

         VCC        --->         +3v3

         GND       --->          GND


I'm using this

 formatted as FAT32.

I got the error message ''Could not open file for write''.

I also tried other connections, using

  • {D2 (SPI1_MOSI), D10 (SPI1_MISO), A4 (SPI1_SCK), D3 (SPI1_NSS)}
  • {D11 (SPI3_MOSI), D12 (SPI3_MISO), D13 (SPI3_SCK), A3 (SPI3_NSS)}

but I continue getting the same error message.

I tried to create in the SD card the directory and file .txt, used in the example program, before running the program, but it didn't work.

I don't have any other ideas to face and solve this problem, so I would appreciate any kind of help, because I'm going crazy with it!

Thank you all in advance and have a good day!

#nucleo-l432kc #micro-sd-card #sd-card #mbed #sd #stm32l432 #sd-card
Posted on May 12, 2017 at 13:51

Adapter looks to expect 5V as it has regulator and level shifter.  Not sure I'd go that route.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on May 12, 2017 at 16:45



I asked a question on the relative amazon webpage and they answer that the supply is 5 V. I tried connecting VCC to 5V pin but nothing changed: I got the same error message.

Actually this is my program:

♯ include 'mbed.h'


♯ include 'SDFileSystem.h'

♯ define BAUDRATE 115200

♯ define MOSI A6


♯ define MISO A5


♯ define SCLK A4


♯ define CS D3


SDFileSystem sd(MOSI,MISO,SCLK,CS, 'sd'), // the pinout on the mbed Cool Components workshop board


Serial pc(USBTX, USBRX),

int main()









printf('Hello World!\n'),



mkdir('/sd/mydir', 0777),



FILE *fp = fopen('/sd/mydir/sdtest.txt', 'w'),


if(fp == NULL) {


error('Could not open file for write\n'),




fprintf(fp, 'Hello fun SD Card World!'),





printf('Goodbye World!\n'),



I don't know if there's something wrong in this program, but it's basically the example program I referred to, where I added the Serial object pc to make serial communication work and I added the instruction wait(5) to give me the time to open the serial monitor and get the messages.

Posted on May 12, 2017 at 18:45

That's all very top level code, it is dependent on a lot of code underneath to make it work, and suitable connectivity.

The sparkfun microsd board makes more sense, though you'd likely want to be sensitive to pull-ups on the pins.

Bit too far off my path for me to wade into.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Emilio Andreozzi
Associate II
Posted on May 18, 2017 at 14:50


I tried every release of 'SDFileSystem.h' available on MBED, but nothing worked.

I had the suspect that my microSD card module was not working, so I tried the other two I bought, but nothing changed.

I tried to use them with an Arduino Due Board using the SD library and I immediately succeeded in writing and reading data from my microSD card, so now I'm sure the modules are working.

I tried to use the microSD card module with a Nucleo-F401RE, using

mbed program written and used for a Nucleo-F401RE but the program didn't work at all.

I tried to format my microSD card in exFAT and in FAT16, but nothing happened: it continued failing in opening the text file on the microSD card.

Please, PLEASE, help me with this situation, I really don't know what to do


Posted on May 18, 2017 at 15:25

Sounds like the problem lies in the part that mbed hides ('abstracts') from you.

If you can't ensure the hardware works, and the SPI peripheral connection is working properly, the rest becomes pointless.

I would consider either a board supported by mbed and with onboard SD card module, including mbed examples, or scrubbing mbed all together, and go for a C/C++ based development, code examples, and FatFS sources.

Posted on May 22, 2017 at 03:58

Those modules are garbage they have buffer from 3.3v to 5v. So they will work with Arduino and most likely won't with any nucleo. My suggestion: get SDIO modules or something on SPI that won't have crappy buffers etc. SDIO is much easier to get running you need around 5 mins to get it working with fatfs. 

SPI is harder on stm32 there is a driver in BSP section under adafruit shield if you browse L4 HAL. It's obviously not plug'n play and you need to look at the code. 



It is mentioned there:

By default the PA_5 (A4) and PA_6 (A5) pins can only be used as Input floating (ADC function).

Remove SB16 and SB18 solder bridges in order to use these pins as Digital output and have access to other functions (DigitalOut, SPI, PWM, etc...).