-
• #2
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;
-
• #3
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 :)
-
• #4
Oh, forgot that initialization to zero goes to bss segment too, so either the attribute or try
=1
. volatile should not matter in that code you wrote, you don't accessa
variable from interrupts. That example possibly uses it because ofsetWatch
withirq:true
(?). -
• #5
You are right, and I was wrong. When I removed volatile in the actual application, the issue was still there. After that, initializing with 1 did fix it in the example as well as in the application (... I hope). Thanks a lot!!
Probably worth to mention somewhere xd
-
• #6
Probably worth to mention somewhere xd
It is a bug so I reported it as https://github.com/gfwilliams/EspruinoCompiler/issues/15
-
• #7
Thanks - I'll get a fix in for this soon
Hi,
I tried
E.compiledC
on my Bangle 1 2v16 and see weird things happening. After "Resetting without loading any code", the followinggives me
Prior to that I ran code which wrote to RAM locations where it shouldn't have. So I rebooted and reflashed the firmware hoping it would reset the device and resolve the issues I see. Is there anything I can do? Its a bit scary to run code that might modify any RAM location at any point.
Thanks in advance!