Skip to main content
Associate
November 25, 2025
Solved

STM32G4 SD Card works at 80MHz CPU clock; Hard Faults at anything higher

  • November 25, 2025
  • 2 replies
  • 231 views

Hello,

I am currently working with STM32G431RB, and I have an SD card connector on my board. When the CPU clock is below 80MHz, everything works fine. However, when I increase the clock frequency and insert the SD card into the slot, the program crashes and gives different hard fault errors (stack overflow, bus hard fault, etc.).

 

This is the SD card slot schematic.

mohamadmeymandi_0-1764091409212.png

 

Best answer by mohamadmeymandi

The problem was that when I inserted the SD card, it drew a huge current, which caused the microcontroller to act randomly. I changed the SD card capacitor to 1µF, and the problem was solved.

2 replies

Andrew Neil
Super User
November 25, 2025
A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
Associate
November 25, 2025

mohamadmeymandi_0-1764093620493.png

 This is one example of the error. I'm using IAR Workbench, and no peripheral is activated, and the only code that I'm running is

 while (1) {
 
 if (! SD_DET)
 HAL_GPIO_WritePin(led_GPIO_Port, led_Pin, GPIO_PIN_RESET);
 else
 HAL_GPIO_WritePin(led_GPIO_Port, led_Pin, GPIO_PIN_SET);
}

 

Tesla DeLorean
Guru
November 25, 2025

Almost certainly not that code. Looks at a disassembly for the addresses reported in the registers.

Check Flashwait states.

Check voltage and capacitors on VCAP pins.

Check interrupt handlers and callbacks.

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
mohamadmeymandiAuthorBest answer
Associate
November 26, 2025

The problem was that when I inserted the SD card, it drew a huge current, which caused the microcontroller to act randomly. I changed the SD card capacitor to 1µF, and the problem was solved.