I have a fairly large Atmel ASF (v7.0) project with composite USB and ADC that is used in a custom board with ATXmega16A4U (sensor). Everything has been working well for months, until I ran into a bizarre for me issue with a global variable. Particularly if I declare it with an initialization to non-zero, the program misbehaves randomly, and unrelated variables are flipping values "by themselves", or the MCU would even reset (I guess it does a bad jump based on some other variables).
S16 temp = 53;
There is no issue if I replace 53 with 0.
The issue reproduces even if the only use of this variable is temp++;
I have been trying to simplify the code to provide a trivial repro but it makes the problem go away.
It might be somehow related to USB, because if I don't call udc_start(); there is no problem. As soon as I start USB, even if I don't send any USB commands, the issue begins. (unrelated variables randomly changing values as verified by outputting them to the board LEDs)
I compared HEX files with and without the assignment, and things look as expected, numerous bytes have incremented by +2, the rest is the same.
I'd appreciate any pointers on how to debug this.
Program Memory Usage : 10190 bytes 49.8 % Full
Data Memory Usage : 1042 bytes 50.9 % Full