Teensy LC out of RAM

Status
Not open for further replies.

asm

Member
Hi,

I've just been trying to write a simple SPI program for the Teensy LC, and got the error:

Code:
c:/users/andrew.main/arduino-1.8.8/hardware/tools/arm/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/bin/ld.exe: C:\Users\ANDREW~1.MAI\AppData\Local\Temp\arduino_build_545032/sketch_jun26a.ino.elf section `.bss' will not fit in region `RAM'

c:/users/andrew.main/arduino-1.8.8/hardware/tools/arm/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/bin/ld.exe: region `RAM' overflowed by 26800 bytes

collect2.exe: error: ld returned 1 exit status

Using library SPI at version 1.0 in folder: C:\Users\andrew.main\arduino-1.8.8\hardware\teensy\avr\libraries\SPI 
Error compiling for board Teensy LC.

Even when I try the example DigitalPotControl I get:

Code:
c:/users/andrew.main/arduino-1.8.8/hardware/tools/arm/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/bin/ld.exe: C:\Users\ANDREW~1.MAI\AppData\Local\Temp\arduino_build_494234/DigitalPotControl.ino.elf section `.bss' will not fit in region `RAM'

c:/users/andrew.main/arduino-1.8.8/hardware/tools/arm/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/bin/ld.exe: region `RAM' overflowed by 26736 bytes

collect2.exe: error: ld returned 1 exit status

Using library SPI at version 1.0 in folder: C:\Users\andrew.main\arduino-1.8.8\hardware\teensy\avr\libraries\SPI 
Error compiling for board Teensy LC.

I didn't think I'd be out of RAM with this. Any pointers?
 
Its just a SPI example though... I've used far smaller processors and written to SPI.

In fact if I choose the first example in the tutorial list "Blink" I get the same thing. (overflow by about 27k). So I'm guessing that something is set up wrong?

Code:
/* LED Blink, Teensyduino Tutorial #1
   http://www.pjrc.com/teensy/tutorial.html
 
   This example code is in the public domain.
*/

// Teensy 2.0 has the LED on pin 11
// Teensy++ 2.0 has the LED on pin 6
// Teensy 3.x / Teensy LC have the LED on pin 13
const int ledPin = 13;

// the setup() method runs once, when the sketch starts

void setup() {
  // initialize the digital pin as an output.
  pinMode(ledPin, OUTPUT);
}

// the loop() methor runs over and over again,
// as long as the board has power

void loop() {
  digitalWrite(ledPin, HIGH);   // set the LED on
  delay(1000);                  // wait for a second
  digitalWrite(ledPin, LOW);    // set the LED off
  delay(1000);                  // wait for a second
}


Code:
C:\Users\andrew.main\arduino-1.8.8\arduino-builder -dump-prefs -logger=machine -hardware C:\Users\andrew.main\arduino-1.8.8\hardware -hardware C:\Users\andrew.main\AppData\Local\Arduino15\packages -tools C:\Users\andrew.main\arduino-1.8.8\tools-builder -tools C:\Users\andrew.main\arduino-1.8.8\hardware\tools\avr -tools C:\Users\andrew.main\AppData\Local\Arduino15\packages -built-in-libraries C:\Users\andrew.main\arduino-1.8.8\libraries -libraries C:\Users\andrew.main\Documents\Arduino\libraries -fqbn=teensy:avr:teensyLC:usb=serial,speed=48,opt=osstd,keys=en-us -ide-version=10808 -build-path C:\Users\ANDREW~1.MAI\AppData\Local\Temp\arduino_build_263915 -warnings=none -build-cache C:\Users\ANDREW~1.MAI\AppData\Local\Temp\arduino_cache_740072 -verbose C:\Users\andrew.main\arduino-1.8.8\examples\Teensy\Tutorial1\Blink\Blink.pde
C:\Users\andrew.main\arduino-1.8.8\arduino-builder -compile -logger=machine -hardware C:\Users\andrew.main\arduino-1.8.8\hardware -hardware C:\Users\andrew.main\AppData\Local\Arduino15\packages -tools C:\Users\andrew.main\arduino-1.8.8\tools-builder -tools C:\Users\andrew.main\arduino-1.8.8\hardware\tools\avr -tools C:\Users\andrew.main\AppData\Local\Arduino15\packages -built-in-libraries C:\Users\andrew.main\arduino-1.8.8\libraries -libraries C:\Users\andrew.main\Documents\Arduino\libraries -fqbn=teensy:avr:teensyLC:usb=serial,speed=48,opt=osstd,keys=en-us -ide-version=10808 -build-path C:\Users\ANDREW~1.MAI\AppData\Local\Temp\arduino_build_263915 -warnings=none -build-cache C:\Users\ANDREW~1.MAI\AppData\Local\Temp\arduino_cache_740072 -verbose C:\Users\andrew.main\arduino-1.8.8\examples\Teensy\Tutorial1\Blink\Blink.pde
Using board 'teensyLC' from platform in folder: C:\Users\andrew.main\arduino-1.8.8\hardware\teensy\avr
Using core 'teensy3' from platform in folder: C:\Users\andrew.main\arduino-1.8.8\hardware\teensy\avr
Detecting libraries used...
"C:\\Users\\andrew.main\\arduino-1.8.8\\hardware\\teensy/../tools/arm/bin/arm-none-eabi-g++" -E -CC -x c++ -w -g -Wall -ffunction-sections -fdata-sections -nostdlib -fno-exceptions -felide-constructors -std=gnu++14 -Wno-error=narrowing -fno-rtti -mthumb -mcpu=cortex-m0plus -fsingle-precision-constant -D__MKL26Z64__ -DTEENSYDUINO=145 -DARDUINO=10808 -DF_CPU=48000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH "-IC:\\Users\\andrew.main\\arduino-1.8.8\\hardware\\teensy\\avr\\cores\\teensy3" "C:\\Users\\ANDREW~1.MAI\\AppData\\Local\\Temp\\arduino_build_263915\\sketch\\Blink.pde.cpp" -o nul
Generating function prototypes...
"C:\\Users\\andrew.main\\arduino-1.8.8\\hardware\\teensy/../tools/arm/bin/arm-none-eabi-g++" -E -CC -x c++ -w -g -Wall -ffunction-sections -fdata-sections -nostdlib -fno-exceptions -felide-constructors -std=gnu++14 -Wno-error=narrowing -fno-rtti -mthumb -mcpu=cortex-m0plus -fsingle-precision-constant -D__MKL26Z64__ -DTEENSYDUINO=145 -DARDUINO=10808 -DF_CPU=48000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH "-IC:\\Users\\andrew.main\\arduino-1.8.8\\hardware\\teensy\\avr\\cores\\teensy3" "C:\\Users\\ANDREW~1.MAI\\AppData\\Local\\Temp\\arduino_build_263915\\sketch\\Blink.pde.cpp" -o "C:\\Users\\ANDREW~1.MAI\\AppData\\Local\\Temp\\arduino_build_263915\\preproc\\ctags_target_for_gcc_minus_e.cpp"
"C:\\Users\\andrew.main\\arduino-1.8.8\\tools-builder\\ctags\\5.8-arduino11/ctags" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "C:\\Users\\ANDREW~1.MAI\\AppData\\Local\\Temp\\arduino_build_263915\\preproc\\ctags_target_for_gcc_minus_e.cpp"
Compiling sketch...
"C:\\Users\\andrew.main\\arduino-1.8.8\\hardware\\teensy/../tools/precompile_helper" "C:\\Users\\andrew.main\\arduino-1.8.8\\hardware\\teensy\\avr/cores/teensy3" "C:\\Users\\ANDREW~1.MAI\\AppData\\Local\\Temp\\arduino_build_263915" "C:\\Users\\andrew.main\\arduino-1.8.8\\hardware\\teensy/../tools/arm/bin/arm-none-eabi-g++" -x c++-header -Os --specs=nano.specs -g -Wall -ffunction-sections -fdata-sections -nostdlib -MMD -fno-exceptions -felide-constructors -std=gnu++14 -Wno-error=narrowing -fno-rtti -mthumb -mcpu=cortex-m0plus -fsingle-precision-constant -D__MKL26Z64__ -DTEENSYDUINO=145 -DARDUINO=10808 -DF_CPU=48000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH "-IC:\\Users\\andrew.main\\arduino-1.8.8\\hardware\\teensy\\avr/cores/teensy3" "C:\\Users\\ANDREW~1.MAI\\AppData\\Local\\Temp\\arduino_build_263915/pch/Arduino.h" -o "C:\\Users\\ANDREW~1.MAI\\AppData\\Local\\Temp\\arduino_build_263915/pch/Arduino.h.gch"
"C:\\Users\\andrew.main\\arduino-1.8.8\\hardware\\teensy/../tools/arm/bin/arm-none-eabi-g++" -c -Os --specs=nano.specs -g -Wall -ffunction-sections -fdata-sections -nostdlib -MMD -fno-exceptions -felide-constructors -std=gnu++14 -Wno-error=narrowing -fno-rtti -mthumb -mcpu=cortex-m0plus -fsingle-precision-constant -D__MKL26Z64__ -DTEENSYDUINO=145 -DARDUINO=10808 -DF_CPU=48000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH "-IC:\\Users\\ANDREW~1.MAI\\AppData\\Local\\Temp\\arduino_build_263915/pch" "-IC:\\Users\\andrew.main\\arduino-1.8.8\\hardware\\teensy\\avr\\cores\\teensy3" "C:\\Users\\ANDREW~1.MAI\\AppData\\Local\\Temp\\arduino_build_263915\\sketch\\Blink.pde.cpp" -o "C:\\Users\\ANDREW~1.MAI\\AppData\\Local\\Temp\\arduino_build_263915\\sketch\\Blink.pde.cpp.o"
Compiling libraries...
Compiling core...
Using precompiled core: C:\Users\ANDREW~1.MAI\AppData\Local\Temp\arduino_cache_740072\core\core_teensy_avr_teensyLC_usb_serial,speed_48,opt_osstd,keys_en-us_7af95a31dede3cce649843424637df07.a
Linking everything together...
"C:\\Users\\andrew.main\\arduino-1.8.8\\hardware\\teensy/../tools/arm/bin/arm-none-eabi-gcc" -Os --specs=nano.specs -Wl,--gc-sections,--relax,--defsym=__rtc_localtime=1561574079 "-TC:\\Users\\andrew.main\\arduino-1.8.8\\hardware\\teensy\\avr\\cores\\teensy3/mkl26z64.ld" -lstdc++ -mthumb -mcpu=cortex-m0plus -fsingle-precision-constant -o "C:\\Users\\ANDREW~1.MAI\\AppData\\Local\\Temp\\arduino_build_263915/Blink.pde.elf" "C:\\Users\\ANDREW~1.MAI\\AppData\\Local\\Temp\\arduino_build_263915\\sketch\\Blink.pde.cpp.o" "C:\\Users\\ANDREW~1.MAI\\AppData\\Local\\Temp\\arduino_build_263915/..\\arduino_cache_740072\\core\\core_teensy_avr_teensyLC_usb_serial,speed_48,opt_osstd,keys_en-us_7af95a31dede3cce649843424637df07.a" "-LC:\\Users\\ANDREW~1.MAI\\AppData\\Local\\Temp\\arduino_build_263915" -larm_cortexM0l_math -lm
c:/users/andrew.main/arduino-1.8.8/hardware/tools/arm/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/bin/ld.exe: C:\Users\ANDREW~1.MAI\AppData\Local\Temp\arduino_build_263915/Blink.pde.elf section `.bss' will not fit in region `RAM'

c:/users/andrew.main/arduino-1.8.8/hardware/tools/arm/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/bin/ld.exe: region `RAM' overflowed by 26696 bytes

collect2.exe: error: ld returned 1 exit status

Error compiling for board Teensy LC.
 
Found it. I forgot that I modded the serial1 rx buffer to increase the RX buffer size for a previous (3.6) project. Everything is working as expected with it reverted back to normal.
 
Found it. I forgot that I modded the serial1 rx buffer to increase the RX buffer size for a previous (3.6) project. Everything is working as expected with it reverted back to normal.

Glad you found that self made change - would have been tough to figure out … except when somebody said … reinstall TeensyDuino :)

That is a curse of having the sources to adjust :( Another problem comes with an upgrade when needed changes disappear … :confused:
 
It begs the question of whether we can prevent certain modules from being loaded into memory. This is highly beneficial for small devices. A dirty hack would be to stub them out I guess...
 
It begs the question of whether we can prevent certain modules from being loaded into memory. This is highly beneficial for small devices. A dirty hack would be to stub them out I guess...

That is an ongoing concern I've seen noted. For the LC some things are #ifdef'd to remove to save unless the user needs it. In the case of Serial each one allocs buffers and included used or not - so some buffers are set 64 or 40 bytes based on expected use or non-use - and as you found they can be expanded.

TeensyDuino is 'optimized' for usability I suppose - and user has the files to edit if things get tight or are not big enough.
 
I tried just now. The SPI DigitalPotControl example is using 2124 bytes (25%) of the 8K RAM on Teensy LC.

Most of the code isn't included if you don't use it, but there is a known issue where the 3 serial port buffers are always allocated. Two parts of the code are responsible, the yield() handling of serialEvent and the fault handler which attempts to transmit any unsent data that was in the transmit buffers when your code crashed. This problem is unlikely to ever get fixed, so if you really want that memory back, edit the 3 serial files.

But don't go crazy editing lots of other stuff in the core library, thinking you'll get similar gains. This is an issue specific to the 3 hardware serial ports, due to serialEvent and the fault handler.

The other big consumer of memory is the USB code. If you don't need USB at all, you can select Tools > USB Type and set it to No USB. When I do this with the DigitalPotControl example (but nothing done about the 3 serial ports), the memory usage drops to 680 bytes. The USB buffers are consuming most of the used-by-default RAM.

Without USB, you can't automatically upload. Instead, you will need to click Verify in Arduino and then physically press the button on your Teensy LC.

If you do need USB, you can try reducing the amount of memory it allocates. Edit usb_desc.h. Look for NUM_USB_BUFFERS. This exists in many places, 1 for each USB Type (as shown in the Tools menu), so make sure you edit the correct one. Reducing the number of buffers may result in lower USB performance in some cases, but maybe that's a worthwhile trade-off?
 
Status
Not open for further replies.
Back
Top