Hi All,
Related to my previous post but more general. I have a large project running on Teensy 4.1 to make a real-time inverted pendulum controller. The teensy is responsible for all tasks, except for torque amplification of the AC servo motor (managed by its own drive). I have a lot of libraries and code involved and the Teensy is getting filled up in RAM1. Still have plenty of RAM2 and Flash. Have spent several dozen hours trying to get this working.
Libraries Used:
In my latest build, I started to link data to a couple "LEDs" on the display and while it compiles, it overruns RAM1 with dynamic allocation during boot. This results in the double blink error code of the built-in LED. My compiler shows:
Flash has 7.3MB free, RAM2 has 242kB free, but RAM1 only has 14kB during static allocation that overflows with dynamic allocation.
Things I've tried:
Things I still plan to try:
My Questions:
Thanks so much for your support!
Related to my previous post but more general. I have a large project running on Teensy 4.1 to make a real-time inverted pendulum controller. The teensy is responsible for all tasks, except for torque amplification of the AC servo motor (managed by its own drive). I have a lot of libraries and code involved and the Teensy is getting filled up in RAM1. Still have plenty of RAM2 and Flash. Have spent several dozen hours trying to get this working.
Libraries Used:
- LVGL
- Arduino
- SPI
- IntervalTimer
- Arduino FreeRTOS
- timers.h (FreeRTOS Timers)
- Custom RS485 Serial Host library for the servo drive (Allen Bradley Ultra 3000)
- ILI9341_T4 display driver
- QuadEncoder
- FT6336U touchscreen
In my latest build, I started to link data to a couple "LEDs" on the display and while it compiles, it overruns RAM1 with dynamic allocation during boot. This results in the double blink error code of the built-in LED. My compiler shows:
Code:
Memory Usage on Teensy 4.1:
FLASH: code:384388, data:404968, headers:8336 free for files:7328772
RAM1: variables:148992, code:328076, padding:32372 free for local variables:14848
RAM2: variables:281376 free for malloc/new:242912
Flash has 7.3MB free, RAM2 has 242kB free, but RAM1 only has 14kB during static allocation that overflows with dynamic allocation.
Things I've tried:
- ILI9341_T4 frame buffers and diff buffers to RAM2 (170kB static)
- LVGL draw buffer moved to RAM2 (25kB static)
- "Chart recorder" history buffer moved to RAM2 (2.4kB static)
- Chart head/count variables moved to RAM2 (small)
- Encoder Snapshots moved to RAM2 (small)
- DAC sample history moved to RAM2 (small)
- Digital input state flags moved to RAM2 (small)
- QuadEncoder objects moved to RAM2 (0.5kB static)
- FT6336U touch controller object moved to RAM2 (0.2kB static)
- U3K_SerialHost object moved to RAM2 (1.5kB static)
- LVGL FPS counter globals moved to RAM2 (small)
- Ultra3000 status arrays / lookup tables moved to RAM2 (0.2kB)
- FreeRTOS Tasks and Stack moved to RAM
- All task stacks moved to RAM2 using DMAMEM (14kB dynamic)
- All task TCBs moved to RAM2 (1.2kB dynamic)
- Startup task stack + TCB moved to RAM2
- FreeRTOS heap moved to RAM2 (up to 40kB dynamic)
Things I still plan to try:
- Move LVGL Stack to RAM2
My Questions:
- I think much of the variable use in RAM1 is coming from libraries I reference. Is there any way to move these to RAM2?
- Program memory in RAM1 is 328kB. Any reasonable way to load/unload parts of this from Flash at runtime to make this chunk smaller or would that tank performance?
- Are there strategies / tools to evaluate memory in a more granular way?
- Am I just filled up and nothing more I can do?
Thanks so much for your support!