Teensy 4.1 memory space

bfinney

Member
Error message when compiling for Teensy 4.1, Arduino 2.1.0 Teensyduino 1.58.1

Opening Teensy Loader...
Memory Usage on Teensy 4.1:
FLASH: code:163572, data:323512, headers:8528 free for files:7630852
RAM1: variables:380704, code:160200, padding:3640 free for local variables:-20256
RAM2: variables:16576 free for malloc/new:507712
Error program exceeds memory space

When compiled for Teensy 3.6

Sketch uses 495228 bytes (47%) of program storage space. Maximum is 1048576 bytes.
Global variables use 70916 bytes (27%) of dynamic memory, leaving 191228 bytes for local variables. Maximum is 262144 bytes.

The code has conditional compiles for different pins and for different i2c libraries 4.1 uses Wire.h and 3.6 uses i2c_t3.h
Teensy 4.1 has more flash and ram memory than Teensy 3.6 so why does Teensy 4.1 exceed memory space? Is this a linker problem with how ram is allocated? Does anyone have a clue as to why this is happening?
 
The 1062 in the T_4.x's has the design allowing code to run from RAM directly - not just Flash with some code cache as the T_3.6.

That only works from RAM1's 512 KB where Data also resides. See: RAM1: variables:380704, code:160200, padding:3640 free for local variables:-20256

For optimal performance the Teensy build places most all code in RAM1 that has full processor speed access times - except that core code that does fine from FLASH, or is needed to reside there before the code is loaded from Flash to RAM1.

There is the option to keep code in FLASH. For information and details on that and other memory tidbits see: .../teensy41.html#memory

To selectively keep code running from FLASH {where it can be held in a 32KB cache for full speed access} and not loaded to RAM1 see/use: FLASHMEM

Alternatively, if there are uninitialized variables or memory that could use RAM2/DMAMEM - that memory area only runs at one quarter the processor speed, though is covered by a full speed 32KB Data Cache.

The error above indicates that some 24,000 bytes of code moved to FLASHMEM would allow the build to complete, and ideally all that code would utilize the 32KB cache for full speed access.
 
RAM1: variables:380704

Look for large const arrays, which you would add PROGMEM to move to flash. Or if you really do have large buffers or other stuff that needs to be allocated in RAM, add DMAMEM to some of those which you're willing to allocate in RAM2.
 
Look for large const arrays, which you would add PROGMEM to move to flash. Or if you really do have large buffers or other stuff that needs to be allocated in RAM, add DMAMEM to some of those which you're willing to allocate in RAM2.

My biggest problem was not understanding Teensy 4.x memory structure. There is a 32K character ring buffer that when placed into DMAMEM allowed the program to compile without any errors.

Thanks
 
Back
Top