I've been struggling with a project in MCUXpresso recently, that has started to fail randomly.
I suspect it's a memory problem, but have a hard time narrowing it down.
As an example, one of the problems I've noticed, is the initialization of variables not being done correctly in the ResetISR.
double testFreq = 1000; // Variable used in actual firmware
volatile int32_t debugVar1 = 1234; // Debug purpose
volatile double debugVar2 = 1234; // Debug purpose
Without using the debug variables, I get the following readout when debugging and breaking the code just after the ResetISR routine that copies variables from flash to RAM (note, the testFreq variable is used in the code and should have been initialized):
testFreq = -nan(0xfffffffffffff)
debugVar1 = 33570816
debugVar2 = 9.2732874683871246e-312
Adding the following code to actually use the debug variables and the testFreq is also initialized correctly;
volatile int32_t dummy = (int32_t)debugVar1;
dummy = (int32_t)debugVar2;
This gives the expected initialization;
testFreq = 1000
debugVar1 = 1234
debugVar2 = 1234
It should be noted, that any random changes will cause the testFreq variable to be initialized correctly. However, other random errors or crashes will show.
So - the big question. I suspected the problems was caused by a pointer error or something similar that would corrupt random data. However, as this seems to be something that can be seen already in the ResetISR routine, I'm starting to wonder if where to look. Any good ideas ?