cancel
Showing results for 
Search instead for 
Did you mean: 

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

mohamadmeymandi
Associate II

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
mohamadmeymandi
Associate II

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.

View solution in original post

4 REPLIES 4
Andrew Neil
Super User

 

Debugging Hard Faults.

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.

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);
}

 

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 Venmo
Up vote any posts that you find helpful, it shows what's working..
mohamadmeymandi
Associate II

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.