Skip to main content
CDave.1
Associate II
Dec 13, 2020 1:29 PM UTC
Solved

Large array causing hard fault when debugging

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.
Tesla DeLorean
Tesla DeLoreanBest answer
Guru
Dec 13, 2020 3:01 PM UTC

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

4 replies

Uwe Bonnes
Chief
Dec 13, 2020 2:36 PM UTC

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
Dec 13, 2020 2:48 PM UTC

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

Tesla DeLorean
Tesla DeLoreanBest answer
Guru
Dec 13, 2020 3:01 PM UTC

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 (See Profile) Up vote any posts that you find helpful, it shows what's working..
CDave.1
CDave.1Author
Associate II
Dec 14, 2020 1:45 PM UTC

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