cancel
Showing results for 
Search instead for 
Did you mean: 

Large array causing hard fault when debugging

CDave.1
Associate II

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.

1 ACCEPTED SOLUTION

Accepted Solutions

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 Venmo
Up vote any posts that you find helpful, it shows what's working..

View solution in original post

4 REPLIES 4
Uwe Bonnes
Principal III

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...

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

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 Venmo
Up vote any posts that you find helpful, it shows what's working..

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