cancel
Showing results for 
Search instead for 
Did you mean: 

stm32f4 hardfault

jhasa.2
Associate III

hi

I use stm32f4 micro but an external interrupt pin

when i increase frequency of the external signal connected to interrupt pin, the micro jump to hardfault

why? how I can detect the solution?

jhasa2_0-1697953350580.png

jhasa2_1-1697953356273.pngjhasa2_2-1697953358673.png

 

35 REPLIES 35

registers like r0,r1, ....

 

FBL
ST Employee

Hello @jhasa.2 

 

In general, you can use the fault analyzer to dump registers content during the exception. 

 

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

You're trying to understand what the MCU is objecting too based on instructions and context it is executing in.

Memory issues, alignment, stack corruption, etc. Is it consistently faulting in the same places or after certain events.

The MCU provides a bunch of data, you can use that to find the cause in your code, or significantly narrow the search to specific functions, pointers or structures.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

most of the time my code faults in EXT Interrupt

but i can not check which section trig this section.

?

 

this is the fault analyzer.

jhasa2_0-1698231355514.pngjhasa2_1-1698231357130.png

 

Frankly your code is not organized properly, you have written everything in one main.c file which is not recommended, you can split into multiple files and enable one feature after other. I can see SPI communication, DAC etc. I recommend you disable all features and use verify only external interrupt code and proceed. Once you fix external interrupt you can add the modules step by step.

Pavel A.
Evangelist III

In the stack trace 20011540 is a RAM address. How you've got there? This looks like stack corruption (overwrite).

 

jhasa.2
Associate III

why the stack is corrupted?

is it related to fake micro-controller?

Shirley.Ye
ST Employee

you can check the disassembly file or use fromelf tool to analyze the stack data 0x20011540, what data is stored there?

Piranha
Chief II
char received_string_data[4];


strncpy(received_string_data , RxData,12);

for (int i = 5; i < (5+2); i++) {if(received_string_data[i]!='\0') k = 10 * k + (received_string_data[i]-48);}

for (int i = 8; i < (8+4); i++) {if(received_string_data[i]!=0) k = 10 * k + (received_string_data[i]-48);}
//	else k = 10 * k + (received_string_data[i]);

The array size...

> why the stack is corrupted?

As @Piranha wrote - because someone overwrites an object on stack!