Skip to main content
CDave.1
Associate II
December 13, 2020
Solved

Large array causing hard fault when debugging

  • December 13, 2020
  • 2 replies
  • 2147 views

Hi,

In my program (running on STM32F446RE, with 512 KB flash and 128 KB SRAM) I defined two big arrays:

int main(void)

{

 /* USER CODE BEGIN 1 */

int16_t data_in[64000];

int16_t audio_buffer[16000];

The code can run normally when the data_in array is not there. However, when the variable data_in is defined, the program will just encounter hard fault and exit abnormally.

Since these variables will be changed throughout the program I can't define them as constants. May I ask what should I do in order to fix this problem?

Thank you.

This topic has been closed for replies.
Best answer by Tesla DeLorean

The linker should catch this, check the linker script describes the amount of RAM correctly.

You need to use less memory for the buffers or pick a larger part with more RAM.

Your description doesn't suggest internal Flash is usable for transient data.​

2 replies

Uwe Bonnes
Chief
December 13, 2020

You are overflowing your ram. int16_t data_in[64000]; alone neede 128 kB, and than the other 32 kB variable and stack and local storage...

CDave.1
CDave.1Author
Associate II
December 13, 2020

does that mean I should put the array in flash instead? or is there other solution?

Tesla DeLorean
Tesla DeLoreanBest answer
Guru
December 13, 2020

The linker should catch this, check the linker script describes the amount of RAM correctly.

You need to use less memory for the buffers or pick a larger part with more RAM.

Your description doesn't suggest internal Flash is usable for transient data.​

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
CDave.1
CDave.1Author
Associate II
December 14, 2020

I reduced the size of the buffer and the issue was solved. Thank you!