cancel
Showing results for 
Search instead for 
Did you mean: 

STM32-NUCLEO-L432KC - I am able to detect my SD card, but not write to it.

Raphael716
Associate

LINK TO THE CODE

Hello everyone,

I'm working on a data logging project using a NUCLEO-L432KC board and a standard Micro-SD card module.

I have a very frustrating issue: Reading from the SD card works perfectly, but Writing fails immediately.

Hardware Setup:

  • MCU: STM32L432KC (Nucleo-32 board)

  • SD Module: Generic MicroSD Card Module (with 5V to 3.3V regulator and level shifter).

  • Power: Module is powered via the 5V rail from the Nucleo. I added a 1000µF / 25V electrolytic capacitor in parallel on the breadboard to prevent any power drops (brown-outs) during write operations.

  • Pinout: * SCK: PB3

    • MISO: PB4

    • MOSI: PA7

    • CS: PB6 (Software managed)

Software / CubeMX Setup:

  • Library: FatFS R0.12c (via STM32CubeIDE).

  • FatFS Config: _FS_READONLY = 0 (Disabled), _FS_LOCK = 0.

  • SPI Config: MSB First, CPOL Low, CPHA 1 Edge, Baud Rate 125.0 Kbits/s for init.

  • GPIO: SPI pins are set to "High" output speed.

The Problem:

My code successfully initializes the SD card. f_mount returns FR_OK, and f_getfree correctly reports the total and free space (approx. 1.18 GB).

However, when I try to write:

  1. f_open works (FR_OK).

  2. f_puts immediately returns EOF (-1).

  3. f_sync fails with Error Code 9 (FR_INVALID_OBJECT).

Here is my debug log:

Plaintext
 
DEBUG: CMD0 sent. Reponse = 0x01
SD Card Mounted Successfully!!!
TotalSpace : 1185923072 bytes, FreeSpace = 1185906688 bytes
Writing data!!!
ERREUR: f_puts KO. sd card full or lock.
ERREUR CRITIQUE f_sync (9) : Voltage drop or spi crash.
Erreur fermeture fichier : (9)
Read Data :
            Closing File!!!

What I have already tried:

  • Formatted the SD card to FAT32 (MBR) using the official SD Memory Card Formatter.

  • Kept the SPI speed slow (SPI_Fast(); is commented out).

  • Added the 1000µF capacitor to the 5V line.

My Question:

Some people suggested this could be a MISO line issue (missing pull-up resistor, or the 5V logic level shifter messing with the "Data Accepted" token during the write process). Since reading works, MISO works for general data, but maybe not for the write confirmation token?

Has anyone experienced this specific "Read OK / Write Fail" behavior with these 5V modules? Should I add a pull-up on PB4?

Any help would be greatly appreciated! Thank you.

 

More info:

IMG_0224 (1).jpgIMG_0225 (1).jpgCapture d’écran 2026-02-03 160708.pngCapture d’écran 2026-02-03 160653.pngCapture d’écran 2026-02-03 160619.pngCapture d’écran 2026-02-03 160608.pngCapture d’écran 2026-02-03 160543.png

1 REPLY 1
Raphael716
Associate

I just tried to change SCK to PA5 and add pull-up on MISO, not working ...