When asking for help, it is usually very beneficial to post your entire sketch to allow those attempting to help to be able to reproduce the problem being addressed. Without this, it is nearly impossible to provide anything of any value that is anything other than an outright guess.
In this specific case, your RAM1 "variables" went from a pre-FLASHMEM value of 29952 to a post-FLASHMEM value of 44224. This almost certainly is not an apples-to-apples comparison. Other changes have been applied over & above the simple addition of the FLASHMEM attribute.
Here's a simple test to demonstrate why it seems that other changes are influencing that results you reported:
Simple test sketch (without FLASHMEM):
Code:
/*
Blink
Turns on an LED on for one second, then off for one second, repeatedly.
This example code is in the public domain.
*/
// Pin 13 has an LED connected on most Arduino boards.
// Pin 11 has the LED on Teensy 2.0
// Pin 6 has the LED on Teensy++ 2.0
// Pin 13 has the LED on Teensy 3.0
// give it a name:
int led = 13;
boolean toggle = false;
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
blinkIt(); // toggle the LED on/off
delay(1000); // wait for a second
}
void blinkIt(void) {
toggle = !toggle;
digitalWrite(led, toggle);
}
Build memory report (without FLASHMEM):
Code:
Memory Usage on Teensy 4.0:
FLASH: code:8036, data:3016, headers:8400 free for files:2012164
RAM1: variables:3456, code:6256, padding:26512 free for local variables:488064
RAM2: variables:12416 free for malloc/new:511872
NOTE that the
code consumption of RAM1 is specifically 6256.
Simple test sketch (with addition of FLASHMEM):
Code:
/*
Blink
Turns on an LED on for one second, then off for one second, repeatedly.
This example code is in the public domain.
*/
// Pin 13 has an LED connected on most Arduino boards.
// Pin 11 has the LED on Teensy 2.0
// Pin 6 has the LED on Teensy++ 2.0
// Pin 13 has the LED on Teensy 3.0
// give it a name:
int led = 13;
boolean toggle = false;
// the setup routine runs once when you press reset:
FLASHMEM void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
}
// the loop routine runs over and over again forever:
FLASHMEM void loop() {
blinkIt(); // toggle the LED on/off
delay(1000); // wait for a second
}
FLASHMEM void blinkIt(void) {
toggle = !toggle;
digitalWrite(led, toggle);
}
Build memory report (with addition of FLASHMEM):
Code:
Memory Usage on Teensy 4.0:
FLASH: code:8108, data:3016, headers:8328 free for files:2012164
RAM1: variables:3456, code:6224, padding:26544 free for local variables:488064
RAM2: variables:12416 free for malloc/new:511872
NOTE that the
code consumption of RAM1 reduced to 6224.
It is also important to note that, in spite of the reduction in RAM1 usage for code, the overall "free for local variables" value did not change. This is due to the fact that RAM1 allocation is done in 32K chunks. Until a 32K reduction in RAM1 usage is made, any changes will be expected to simply show up in the "padding" value.
Hope this helps . . . and please post your entire sketch. Without that, not much help should be expected !!
Mark J Culross
KD5RXT