Unstable initialization of the SD card

Post here first, or if you can't find a relevant section!
Post Reply
p-v-n
Posts: 23
Joined: Mon Oct 06, 2025 10:34 pm
Answers: 1

Unstable initialization of the SD card

Post by p-v-n »

Hello !
I encountered an unstable initialization of the Micro SD card on the WeAct stm32h743vit6 board.
I have several brand new WeAct Studio stm32h743vit6 boards, and I'm running the same code on these boards.

Code: Select all

#include <STM32SD.h> // https://github.com/stm32duino/STM32SD

#define SD_data0 PC8
#define SD_data1 PC9
#define SD_data2 PC10
#define SD_data3 PC11
#define SD_CMD PD2
#define SD_CK PC12

// SD card
#ifndef SD_DETECT_PIN
#define SD_DETECT_PIN PD4
#endif
File myFile;

#define LED PE3

void setup() {

  pinMode(LED, OUTPUT);


  SD.setDx(SD_data0, SD_data1, SD_data2, SD_data3);
  SD.setCMD(SD_CMD);
  SD.setCK(SD_CK);

  Serial.begin(9600);

  while (!Serial && millis() < 5000) {
    ;
  }


  if (!SD.begin(SD_DETECT_PIN, HIGH)) {
    Serial.println(" Micro SD card Error!");
    digitalWrite(LED, LOW);  // LED OFF
  } else {
    Serial.println("Micro SD card OK !");
    digitalWrite(LED, HIGH);  // LED ON
  }
}

void loop() {
  // put your main code here, to run repeatedly:
}
Only on one of the MicroSD cards, the card is always initialized (100%) when power is applied or the Reset button is pressed

On other boards, initialization is very unstable, and the MicroSD card may initialize only once out of 10.

For example, when power is supplied to one of the boards, the following happens:

Code: Select all

 Micro SD card Error!
Micro SD card OK !
 Micro SD card Error!
Micro SD card OK !
Micro SD card OK !
 Micro SD card Error!
Micro SD card OK !
 Micro SD card Error!
 Micro SD card Error!
 Micro SD card Error!
 Micro SD card Error!
 Micro SD card Error!
 Micro SD card Error!
 Micro SD card Error!
 Micro SD card Error!
 Micro SD card Error!
 Micro SD card Error!
 Micro SD card Error!
 Micro SD card Error!
 Micro SD card Error!
 Micro SD card Error!
 Micro SD card Error!
 Micro SD card Error!
 Micro SD card Error!
The boards are brand new!
Arduino IDE version 2.3.10
STM32duino STM32SD version 1.4.0
Library STM32 microcontroller version 2.12.0

What could be the problem, and how can I find the cause?
by p-v-n » Tue Sep 22, 2026 3:48 am
pinMode(SD_DETECT_PIN, INPUT_PULLUP); in Setup() solves the problem of unstable detection of SD cards on Weact Studio boards with a soldered MicroSD connector.
Go to full post
p-v-n
Posts: 23
Joined: Mon Oct 06, 2025 10:34 pm
Answers: 1

Re: Unstable initialization of the SD card

Post by p-v-n »

Hmm!
On the board that always worked 100% yesterday, it is also being initialized unstable today ((( The code has not changed !

I don't understand what the problem is.
Backflip
Posts: 28
Joined: Fri Nov 14, 2025 6:09 pm
Answers: 0

Re: Unstable initialization of the SD card

Post by Backflip »

I got an issue with my SD-card, that I fixed in a similar way like this:

https://www.youtube.com/watch?v=oKrn-0jXZCU
ag123
Posts: 1987
Joined: Thu Dec 19, 2019 5:30 am
Answers: 33

Re: Unstable initialization of the SD card

Post by ag123 »

check also for loose / misaligned connections, some card connectors aren't very well made.
p-v-n
Posts: 23
Joined: Mon Oct 06, 2025 10:34 pm
Answers: 1

Re: Unstable initialization of the SD card

Post by p-v-n »

The contacts are in order, as the memory card slot is soldered by the manufacturer to the microcontroller board. And the situation is the same on different boards.

Industrial Grade microSD Memory Card from Kingston 32 GB, FAT32
fpiSTM
Posts: 2009
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 109
Location: Le Mans
Contact:

Re: Unstable initialization of the SD card

Post by fpiSTM »

Maybe the clock config is not correct for the SD or an hardware issue as mentioned before. I will check the feq used for your board.
p-v-n
Posts: 23
Joined: Mon Oct 06, 2025 10:34 pm
Answers: 1

Re: Unstable initialization of the SD card

Post by p-v-n »

fpiSTM wrote: Tue Jul 21, 2026 3:20 pm Maybe the clock config is not correct for the SD or an hardware issue as mentioned before. I will check the feq used for your board.
I checked on another SD card, also 32 GB, FAT32. The situation is the same.
Both SD cards work fine on the computer.
If possible, please check the frequencies

I found another 2 GB SD card with FAT. It also doesn't initialize on the board, but it works fine on the computer.

I also tested it a small 64 MB FAT SD card, which also doesn't work on the board but works perfectly on a PC.

I tested this on several WeAct Studio STM32H743VIT6 boards
p-v-n
Posts: 23
Joined: Mon Oct 06, 2025 10:34 pm
Answers: 1

Re: Unstable initialization of the SD card

Post by p-v-n »

Dear @fpiSTM has solved this difficult situation for me.

This inexplicable behavior occurs only when the Reset button is pressed. If you supply power, the card always initializes without errors!
@fpiSTM, thank you so much for your help!

You’re a genius!!!
p-v-n
Posts: 23
Joined: Mon Oct 06, 2025 10:34 pm
Answers: 1

Re: Unstable initialization of the SD card

Post by p-v-n »

pinMode(SD_DETECT_PIN, INPUT_PULLUP); in Setup() solves the problem of unstable detection of SD cards on Weact Studio boards with a soldered MicroSD connector.
Post Reply

Return to “General discussion”