Can someone point me to an explanation of how memory is managed on the Teensy device? I'm working on a decent-sized project and feel like I'm just fumbling around in the dark with this stuff, and continue to get stuck on trivial dumb (some might even say spooky) stuff that feels like I could avoid if I just actually knew what was going on.
Our project is probably about 10k lines of code at this point, so like I said decent sized but nothing crazy large. We build in VS Code on Windows, using a makefile project generated by a tool called VSTeensy. AFAIK it's all pretty straightforward. When I build/upload the sketch, the tools tell me we're using like ~45% of available memory, so again it doesn't seem like we should really have worries about this.
The "big" problem: I have a singleton object that once contained an array of 200 items, each of which is 8-16 bytes in size. When I upload the sketch, the device hangs at boot. Reducing the size of the array finally got us back up and running, and via trial and error we determined that 50 items was roughly the maximum size we could use. I later determined that if I took the array out of the class definition, and referred to the external array from within the class, it could handle 75 or so items, but at roughly 100 it would run for a little while then hang, and anything larger would just hang at boot again. Nothing is being dynamically allocated in the code, it's just a single instance of this class declared as a global variable holding a bunch of state. This one feels just like lack of knowledge on my part, like whatever memory management code there is on the system can't handle what I've done, so if I knew how to appease it or just manage the location of stuff on my own I could make this work as desired. From there, though, things got weird. Both of the following are real things that have actually happened to me in the past week:
ii. We found a global variable that is a small array of structures, like 10 items of size 20-32 bytes roughly. When we change the *name* of the variable in the code, the resultant sketch won't boot on the device. Cleaned the build from the IDE and rebuilt, no love. Cleaned the tree using 'git clean -xdf', rebuilt, still no joy. Change the name back, rebuild, all good again.
iii. Have another global boolean variable that's initialized to true. All it does is indicate whether a line of text should be shown on the display at startup, and we've built and run the code with the line displayed and without. When we change the value of the variable to false, however, the device again won't boot. Again same as before, clean build has no effect, and everybody's happy as soon as the variable is set to true.
If anyone can share any experience/knowledge/docs/whatever related to properly laying out stuff in memory and/or debugging this stuff when it happens, I'd be much obliged.
Our project is probably about 10k lines of code at this point, so like I said decent sized but nothing crazy large. We build in VS Code on Windows, using a makefile project generated by a tool called VSTeensy. AFAIK it's all pretty straightforward. When I build/upload the sketch, the tools tell me we're using like ~45% of available memory, so again it doesn't seem like we should really have worries about this.
The "big" problem: I have a singleton object that once contained an array of 200 items, each of which is 8-16 bytes in size. When I upload the sketch, the device hangs at boot. Reducing the size of the array finally got us back up and running, and via trial and error we determined that 50 items was roughly the maximum size we could use. I later determined that if I took the array out of the class definition, and referred to the external array from within the class, it could handle 75 or so items, but at roughly 100 it would run for a little while then hang, and anything larger would just hang at boot again. Nothing is being dynamically allocated in the code, it's just a single instance of this class declared as a global variable holding a bunch of state. This one feels just like lack of knowledge on my part, like whatever memory management code there is on the system can't handle what I've done, so if I knew how to appease it or just manage the location of stuff on my own I could make this work as desired. From there, though, things got weird. Both of the following are real things that have actually happened to me in the past week:
ii. We found a global variable that is a small array of structures, like 10 items of size 20-32 bytes roughly. When we change the *name* of the variable in the code, the resultant sketch won't boot on the device. Cleaned the build from the IDE and rebuilt, no love. Cleaned the tree using 'git clean -xdf', rebuilt, still no joy. Change the name back, rebuild, all good again.
iii. Have another global boolean variable that's initialized to true. All it does is indicate whether a line of text should be shown on the display at startup, and we've built and run the code with the line displayed and without. When we change the value of the variable to false, however, the device again won't boot. Again same as before, clean build has no effect, and everybody's happy as soon as the variable is set to true.
If anyone can share any experience/knowledge/docs/whatever related to properly laying out stuff in memory and/or debugging this stuff when it happens, I'd be much obliged.