AnsweredAssumed Answered

Hard fault error and static variable

Question asked by ghislain.olivier on Oct 15, 2014
Latest reply on Oct 22, 2014 by ghislain.olivier
Hello all,
Following some hardfault error with my code running into a STM32F415, I found a solution that leave me puzzled.
In my main, I declare a array of 600 uint8_t called data;
uint8_t data[600];
I call a function that need a pointer to an uint8_t, this function will fill the array with some datas. So I call this function like this:
As the name of an array is a pointer to that array, OK;
The function is filling the array pointed by data, and sometime a hardfault is rise with IMPRECISERR from CSR register set to 1.

I read some information on the web about this error could be solved by declaring each array with STATIC. Why ?
Normally, the cover of a variable is the all function, so when a function call another function, my data variable should be accessible to the called function (in this case a pointer). If I declare it STATIC, this variable will stay on the stack for live not only for the running function scope, so I will use more RAM than needed.

Thanks for you help.