Skip to main content
jhasa.2
Associate III
Oct 22, 2023 5:43 AM UTC
Question

stm32f4 hardfault

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

 

This topic has been closed for replies.

35 replies

SRedd.5
Senior III
Oct 22, 2023 6:04 AM UTC

At what frequency of the external signal it goes to hardware fault? Below this frequency which function you are calling when interrupt happens?

jhasa.2
jhasa.2Author
Associate III
Oct 22, 2023 6:24 AM UTC

the interrupt routine is free and i commented all the code in it.

the frequency above 3khz will be Hard Fault.

how i can see the problem detail in hard fault?

 

SRedd.5
Senior III
Oct 22, 2023 6:33 AM UTC

SRedd5_0-1697956208078.png

The sequence is step1: HAL_GPIO_EXTI_IRQHandler function is called and after that some issue happened and the hardfault handler is called. Can you show your code? In the interrupt handler can you toggle a port based on the external input signal, so both shall match for debugging purpose.

Tesla DeLorean
Guru
Oct 22, 2023 8:14 PM UTC

>>why?

These things don't need to be guessing games. Go identify what's actually faulting and work backward from there.

If you don't service interrupts in handlers, they'll keep entering.

Have a Hard Fault Handler that does something more useful that while(1), I've posted examples on multiple occasions on.

https://github.com/cturvey/RandomNinjaChef/blob/main/KeilHardFault.c

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
jhasa.2
jhasa.2Author
Associate III
Oct 23, 2023 7:42 AM UTC

this data is displayed on stm32cubeide

what i should with this data?

 

SRedd.5
Senior III
Oct 23, 2023 8:10 AM UTC

What data? 

ST Technical Moderator
Oct 23, 2023 10:13 AM UTC

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 "Best answer" on the reply which solved your issue or answered your question.Best regards,FBL
Tesla DeLorean
Guru
Oct 23, 2023 10:28 AM UTC

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 (See Profile) Up vote any posts that you find helpful, it shows what's working..
jhasa.2
jhasa.2Author
Associate III
Oct 25, 2023 10:56 AM UTC

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

 

SRedd.5
Senior III
Oct 25, 2023 11:33 AM UTC

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.
Oct 25, 2023 8:11 PM UTC

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

 

jhasa.2
jhasa.2Author
Associate III
Oct 26, 2023 3:49 AM UTC

why the stack is corrupted?

is it related to fake micro-controller?

Pavel A.
Oct 27, 2023 11:15 PM UTC

> why the stack is corrupted?

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

jhasa.2
jhasa.2Author
Associate III
Oct 28, 2023 7:17 AM UTC

how i can found it?

Shirley.Ye
ST Employee
Oct 27, 2023 2:12 AM UTC

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

Piranha
Principal III
Oct 27, 2023 2:40 AM UTC
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...

jhasa.2
jhasa.2Author
Associate III
Oct 30, 2023 3:11 AM UTC

i remove an 60000 byte array

why compiler does not warn or error when we use huge array in local functions?

Tesla DeLorean
Guru
Oct 30, 2023 3:40 AM UTC

Neither the compiler or linker track call-stacks and stack usage, most of this occurs dynamically as the code runs, not a static allocation which the linker must fulfill.

You should not have more local/auto variables that exceed the available RAM under the stack pointer.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
jhasa.2
jhasa.2Author
Associate III
Nov 2, 2023 4:16 AM UTC

the full project has been attached