Hey guys,
Has anyone has any strange problems with memory locations depending on code size or alignment? In our current project, my friend and I are using a Maple Mini. We are reading from several sensors, and most of the time everything works just fine, but sometimes when we build, the LED on the board to throb, which I assume is from a fault of some sort. If the build doesn't work, we can make it start working by simply inserting several SerialUSB.println() statements. This makes me thing the issue either has to do with adding additional delays into the code (the time required to do the serial writes), or the location/alignment of the code itself (adding the extra println's adds extra instructions and causes the code below it to move within in the image when compiled).
I've tried simply adding a delay into the code with delay(5), and that didn't help, so I don't think it's a timing or delay issue.
I've tried looking at the memory locations of various bits of code and data structures in passing and failing cases. We are storing most of our data in some global data structures. In passing cases, those data structures get stored at addresses in the 0x20001000-ish range, which makes sense to me. In the failing cases, when I look at the address of the data structure during setup(), it's in the 0x20001000-ish range, but when I look at the address of the data structure during loop(), it has moved to 0x2000D000 or 0x2000B000 or something similar, which doesn't make any sense to me. First, why would it move? Second, the Mini only has 20k of memory, and D000 or B000 is way outside of that range.
My immediate thought was that maybe something went out of scope, or maybe a pointer has gotten overwritten or something, so I've been searching for that. However, what I can't figure out is why adding just a few SerialUSB.println() statements into my code somewhere seems to fix everything. I can't figure out why code alignment would have anything to do with this.
I've also tried connecting an FTDI cable up to Serial2 to try and watch for debug data coming back when the Maple Mini crashes, but I haven't seen anything come back. I've got the FTDI cable connected, and I've got a terminal window open, connected, and set to 9600 baud. Is there anything else I need to do? My understanding is that if you run into a hard fault, there is no debug data that comes back, so I'm wondering if that's what is happening here.
Anyway, has anyone seen anything like this? Any suggestions of anything to try?
For reference, I'm on MapleIDE 0.0.12 on OSX 10.6.8 (Snow Leopard). We're using whichever version of libmaple came with MapleIDE.
- Andy