2023-10-21 10:43 PM
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?
2023-10-28 12:17 AM
how i can found it?
2023-10-28 12:42 AM
char received_string_data[4];
Look at this https://www.tutorialspoint.com/c_standard_library/c_function_strncpy.htm
Your destination array size is less.
2023-10-28 04:07 AM - edited 2023-10-28 04:08 AM
>how i can found it?
A good question, thank you ))
The compiler should give a warning : warning: 'strncpy' writing 12 bytes into a region of size 4 overflows the destination [-Wstringop-overflow=]
But I've tested with several gcc versions on godbolt and was surprised that this warning shows up only starting with gcc v.12.something. Not in 11 and below, even with explicit -Wstringop-overflow option.
So ... Update to the latest gcc. If you cannot do this, use 3rd party tools for code analysis (which may be even better and robust).
Learn to debug. Like in other computer games, your character grows stronger and opens new skills when you play long enough))
2023-10-29 08:11 PM
i remove an 60000 byte array
why compiler does not warn or error when we use huge array in local functions?
2023-10-29 08:40 PM
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.
2023-10-30 02:45 PM
The received_string_data variable is global in that code, but that doesn't change the fact that the code writes beyond that buffer.
2023-11-01 03:39 AM
2023-11-01 09:16 PM
2023-11-03 08:29 PM
can every body check my code? or help me?
2023-11-03 10:29 PM - edited 2023-11-03 10:30 PM
Everyone explained to you what is wrong with your array. Think of it this way, you have a tennis ball container (array) that can only hold 3 tennis balls (values), max. You're basically trying to fit 4 or more balls into a container. So when you try to fit 4 balls in a container, all it's going to do is burst (hard fault).
So in your instance you're trying to put 5 or more values into an array that can fit only 4 values. Get the idea what's wrong now?