2022-04-07 01:39 AM
I have made a for loop that produces the data of a sine wave and stores the values in an array. The loop is set to execute in the main(). However this seems to break whatever board i use, i have tested on L47RG and the H745i. Any help would be appreciated.
Below is the for loop that is executed in the main.c, main().
N is a defined constant of 100, and TMAX is a defined constant of 1.0
double t[N];
double y[N];
/*data to be fitted*/
for (int i = 0; i < N; i++)
{
double ti = i * TMAX / 100;
double yi = sin(5 * ti + 0.6);
t[i] = ti;
y[i] = yi;
}
2022-04-07 02:06 AM
If t and y are declared inside main() or any other functin, they are created on the stack, occupying 1600 bytes. That's possibly dangerous - don't use stack fro big data structures. Double type is not handled by hardware on L476 - that may be another problem.
2022-04-08 02:57 PM
Which runtime fault? CubeIDE and other decent IDEs have a fault analyzer to help you understand what happened.
1600 bytes on stack by itself is not dangerous. It should be something else.
2022-04-08 04:31 PM
Do some proper debugging...
Understand the mechanics of the failure.
Have a proper Hard Fault Handler so you can understand if and why it ends up there.
Use the debugger, look at the registers, inspect the stack, see where it's hung up.
2022-04-08 08:09 PM
Replace double with float as debug trial.