Skip to main content
Senior
April 18, 2025
Solved

Going in HardFault

  • April 18, 2025
  • 4 replies
  • 701 views

I plan to transmit stream of approx 10k characters by uart every second. For that purpose, I have definer global char array of 10.5k length. After working for few second, the MCU goes in HardFault.

I tried with array of 1000 bytes only, it works fine. But as I increased to 10k bytes array, problem start coming.

Should I change stack sizes in linker file. ? please suggest and where to change. 

 

Best answer by TDK

Global arrays don't use the stack.

Possibly a write out of bounds causing issues. Definitely a bug in the code somewhere. I suggesting finding and fixing the bug.

4 replies

MM..1
Chief III
April 18, 2025

show code 

TDK
TDKBest answer
Super User
April 18, 2025

Global arrays don't use the stack.

Possibly a write out of bounds causing issues. Definitely a bug in the code somewhere. I suggesting finding and fixing the bug.

"If you feel a post has answered your question, please click ""Accept as Solution""."
Andrew Neil
Super User
April 18, 2025

@Nico3 wrote:

I plan to transmit stream of approx 10k characters by uart every second.


So, with 10 bits/character, about 100kbit/s.

Certainly, the UART hardware can cope with that.

But can your code keep up?

 


@Nico3 wrote:

I tried with array of 1000 bytes only, it works fine. But as I increased to 10k bytes array, problem start coming.


So narrow it down some more - try sizes between 1k and 10k

 


@Nico3 wrote:

the MCU goes in HardFault.


So you need to find what's causing the Hard Fault:

https://community.st.com/t5/community-guidelines/how-to-write-your-question-to-maximize-your-chances-to-find-a/tac-p/708193/highlight/true#M51

 

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.
Nico3Author
Senior
April 18, 2025

I found the fault. Increased the size of array and not crashing anymore. 

 

Andrew Neil
Super User
April 18, 2025

@Nico3 wrote:

I found the fault.


Good to hear - so what, exactly, was the problem?

please mark that post as the solution.

See: https://community.st.com/t5/community-guidelines/help-others-to-solve-their-issues/ta-p/575256

 


@Nico3 wrote:

But i see another problem now. .


Please start a new thread for that.

 

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.
Nico3Author
Senior
April 18, 2025

Hi andrew,  

The array length was insufficient...