No need to reflash firmware, just rebooting is enough (E.reboot or holding btn1+2), firmware is in flash not ram so you cannot corrupt it by changing ram.
btw you don't need the variable to be volatile. from the sequence it looks like it is incrementing but sometimes the highest byte of the a variable is corrupted. Oh, I think I remember this bug, try to declare it with initialized value like
volatile int a = 0;
that should be safe. Uninitialized variables go to .bss section and that one is not part of the preallocated binary array in RAM so it will corrupt something after the array. It is a bug (or feature) of the compiler.
Or you can put global variables to .text segment, that will work too and will even generate a bit smaller code
__attribute__((section(".text"))) int a;
Thanks, good to know about the reset. Was using a custom build to try things, so reflashing wasn't wasted effort at least :)
Regarding initialized or not, I tried a few variations and it seems that volatile is the culprit. Without it, the counter runs to at least 2000 whether or not it was initialized during declaration. Just initializing didn't fix it. The reason why I used volatile was because I read it here http://www.espruino.com/InlineC.
I'll keep the optimization in mind :)
© Espruino, powered by microcosm.
Report a problem