cancel
Showing results for 
Search instead for 
Did you mean: 

Hard Fault Handler error in STM32F103CBT6TR

suba512
Associate II

So, when I was actually trying to work on the STM32F103CBT6TR MCU which is placed onto the custom board while I tried to toggle PA1 in it which only gave floating values then in debug, I found out it is going into Hard Fault Handler so then again I replaced them with new IC but again it is coming as same Hard Fault Handler. I also tried for pin 0 too. What can we do to solve this?

25 REPLIES 25
MGogr.1
Senior

Can you please provide some more info, such as code/pin config?

This will help in narrowing down the cause. 

I used pin PA0 to toggle and the code and i ahve used pinState because just to read the value out of the pin even with the registers we could still i just added this today before i only used the first 2 line the toggle and delay that's it.

 

HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_0);

HAL_Delay(500);

 

uint32_t pinState = HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_0);

 

 

mfgkw
Senior III

... and additionally please try to find out if it is a genuine STM32F103 or a fake.

(It sounds a bit like "blue pill".)

Its isn't the fake one though we genuinely ordered it from ST and to answer the same code worked upon the the blue pill board but not IC.

mfgkw
Senior III

BTW:

You talk about PA1.

But HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_0) toggles PA0 (which is connected to the user button on a blue pill board, if you have such a thing).

 

Ozone
Principal III

... while I tried to toggle PA1 in it which only gave floating values ...

What exactly does that mean ?

... I replaced them with new IC but again it is coming as same Hard Fault Handler ...

The bug is in your code.

One approach is to single-step through the code, and locate the line were it faults.

Another approach is to let the code run in the debugger until it faults, and then examine the fault registers in the SCB. Those will tell you were the hardfault occured, and why.

But to our surprise the same logic worked upon the blue pill board STM32F103C8T6 like all gpio where toggled and we even connected it with the led to visibly check it out. I just added this in case to your reference, thank you.

To clarify that yes i kind of tried to debug but still the value shows nothing and so u know I actually gone step by step though still nothing and to say this interrupt happens the very first immediately if i just let it run and of course i tried to similar board it worked okay so there isn't problem of code and yeah i have wrote wrong about pin configurations i kind of tried to work on both pa0 and pa1. I hope i am clear

 

> I hope i am clear

Not really. Missing punctuation and missing separation into sentences makes it a very hard read.

... i tried to similar board it worked okay so there isn't problem of code ...

A hardfault is ALWAYS a problem with the code.

> But to our surprise the same logic worked upon the blue pill board STM32F103C8T6 ...

"Blue Pill" rings a bell here.
Many of those boards have fake MCUs, that fail sooner or later, and never work according to specs.
I suspect you have populated your custom boards with fake MCUs as well.