Short of memory in IDE but no problem in PlatformIO?

I had made a project using PlatformIO and I published it on Hackster.io

After a while I got a question of someone who could NOT upload the sketch because of a lack of Dynamic memory?!

The difference is quite big after compiling:

ARDUINO IDE 1.8.15:
Sketch uses 28612 bytes (88%) of program storage space. Maximum is 32256 bytes.
Global variables use 2092 bytes (102%) of dynamic memory, leaving -44 bytes for local variables. Maximum is 2048 bytes.data section exceeds available space in board

PlatformIO latest update:
RAM: [========= ] 93.1% (used 1906 bytes from 2048 bytes)
Flash: [======== ] 83.2% (used 26842 bytes from 32256 bytes)
========================================== [SUCCESS] Took 1.59 seconds

I am amazed, what is going on and can this be solved?
Has it to do with the HEX file with or without bootloader?

I tried it out with the Arduino IDE and got the same results as were reported to you.

The default SPI and Wire libraries end up being selected by the Arduino build system instead of the ones you provided:

Multiple libraries were found for "Wire.h"
 Used: C:\Users\in0\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.3\libraries\Wire
 Not used: C:\Users\in0\Documents\Arduino\libraries\Wire
Multiple libraries were found for "SPI.h"
 Used: C:\Users\in0\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.3\libraries\SPI
 Not used: C:\Users\in0\Documents\Arduino\libraries\SPI

I adjusted the metadata of the ones you provided so that they would be used and did get different results, but still no joy:

Sketch uses 27724 bytes (90%) of program storage space. Maximum is 30720 bytes.
Global variables use 2081 bytes (101%) of dynamic memory, leaving -33 bytes for local variables. Maximum is 2048 bytes.

No, that is not it.

Unfortunately, I don't know enough about PlatformIO to say what is different. I did a little bit of looking through their "atmelavr' platform to see if I could tell whether they were using a different version of the avr-gcc compiler or different optimization flags on the compilation commands, etc., but I didn't catch anything.

1 Like

Were is the download link for the complete code?
The doc says "in the attachements section", but I don't see such a section!

Click the downward pointing arrow icon ("Download") on the code window here:
https://www.hackster.io/edr1924/bathroom-ventilation-fan-controller-0590ab#code

I was also tripped up by hackster.io having truncated the code you get from the "Copy the code" button.

The libraries are available here:
https://www.hackster.io/edr1924/bathroom-ventilation-fan-controller-0590ab#cad

1 Like

Well, avr-nm -SC --size-sort *.elf reports the top memory users:

008002d9 00000020 b TwoWire::rxBuffer
00800327 00000020 b TwoWire::txBuffer
008002fb 00000020 b twi_masterBuffer
0080027f 00000020 b twi_rxBuffer
0080025d 00000020 b twi_txBuffer
00800124 00000035 d u8x8_d_ssd1306_128x64_noname_init_seq
008008b2 0000003a b buttonDown
00800926 0000003a b buttonSelect
008008ec 0000003a b buttonUP
008007f4 0000003b b bme
0080082f 00000083 b u8g2
00800349 0000009d b Serial
008003f4 00000400 b buf.9242

The big "buf.9242" is apparently from U8g2/src/clib/u8g2_d_memory.c - a display dependent variable.

Can we get a similar report from the PlatformIO build?

1 Like

I no nothing about the AVR, it a black box for me...
But found this site which I will look into.

PlatformIO memory analysis

Conclusion for me is continue to avoid the Arduino IDE when possible. It has served me very well in the first years after discovering the Arduino platform!

I prefer to use genuine Arduino hardware but sadly the IDE, local or online is far away from useable now for several reasons. Online compiling takes way too long. So no Arduino IoT for me which I regret.

Anyways, here is the verbose PlatformIO output:

Processing uno (platform: atmelavr; board: uno; framework: arduino; upload_port: /dev/ttyACM0; upload_flags: -V; monitor_speed: 19200)
-----------------------------------------------------------------------------------------------------------------
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/uno.html
PLATFORM: Atmel AVR (3.4.0) > Arduino Uno
HARDWARE: ATMEGA328P 16MHz, 2KB RAM, 31.50KB Flash
DEBUG: Current (avr-stub) On-board (avr-stub, simavr)
PACKAGES: 
 - framework-arduino-avr 5.1.0 
 - toolchain-atmelavr 1.70300.191015 (7.3.0)
avr-g++ -o "/home/erik/SynologyDrive/PlatformIO/Projects/Bathroom Fan Controller 1.11/src/main.ino.cpp" -x c++ -fpreprocessed -dD -E "/tmp/tmp2bu2y9qs"
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 13 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <Adafruit BME280 Library> 2.1.2 (/home/erik/SynologyDrive/PlatformIO/Projects/Bathroom Fan Controller 1.11/lib/Adafruit BME280 Library)
|   |-- <Adafruit Unified Sensor> 1.1.4 (/home/erik/SynologyDrive/PlatformIO/Projects/Bathroom Fan Controller 1.11/lib/Adafruit Unified Sensor)
|   |-- <SPI> 1.0 (/home/erik/SynologyDrive/PlatformIO/Projects/Bathroom Fan Controller 1.11/lib/SPI)
|   |-- <Wire> 1.0 (/home/erik/SynologyDrive/PlatformIO/Projects/Bathroom Fan Controller 1.11/lib/Wire)
|-- <EEPROMEx> (/home/erik/SynologyDrive/PlatformIO/Projects/Bathroom Fan Controller 1.11/lib/EEPROMEx)
|-- <OneButton> 0.0.0-alpha+sha.eb583d713a (/home/erik/SynologyDrive/PlatformIO/Projects/Bathroom Fan Controller 1.11/lib/OneButton)
|-- <SPI> 1.0 (/home/erik/SynologyDrive/PlatformIO/Projects/Bathroom Fan Controller 1.11/lib/SPI)
|-- <U8g2> 2.28.8 (/home/erik/SynologyDrive/PlatformIO/Projects/Bathroom Fan Controller 1.11/lib/U8g2)
|   |-- <SPI> 1.0 (/home/erik/SynologyDrive/PlatformIO/Projects/Bathroom Fan Controller 1.11/lib/SPI)
|   |-- <Wire> 1.0 (/home/erik/SynologyDrive/PlatformIO/Projects/Bathroom Fan Controller 1.11/lib/Wire)
|-- <Wire> 1.0 (/home/erik/SynologyDrive/PlatformIO/Projects/Bathroom Fan Controller 1.11/lib/Wire)
Building in release mode
avr-g++ -o .pio/build/uno/src/main.ino.cpp.o -c -fno-exceptions -fno-threadsafe-statics -fpermissive -std=gnu++11 -Os -Wall -ffunction-sections -fdata-sections -flto -mmcu=atmega328p -DPLATFORMIO=50202 -DARDUINO_AVR_UNO -DF_CPU=16000000L -DARDUINO_ARCH_AVR -DARDUINO=10808 -Iinclude -Isrc -Ilib/U8g2/src -Ilib/OneButton/src -Ilib/EEPROMEx "-Ilib/Adafruit BME280 Library" -Ilib/Wire -Ilib/Wire/utility -Ilib/SPI "-Ilib/Adafruit Unified Sensor" -I/home/erik/.platformio/packages/framework-arduino-avr/cores/arduino -I/home/erik/.platformio/packages/framework-arduino-avr/variants/standard src/main.ino.cpp
avr-g++ -o .pio/build/uno/firmware.elf -Os -mmcu=atmega328p -Wl,--gc-sections -flto -fuse-linker-plugin .pio/build/uno/src/main.ino.cpp.o -L.pio/build/uno -Wl,--start-group ".pio/build/uno/lib4ae/libAdafruit Unified Sensor.a" .pio/build/uno/lib5b9/libSPI.a .pio/build/uno/libdbb/libWire.a ".pio/build/uno/libc11/libAdafruit BME280 Library.a" .pio/build/uno/libf97/libEEPROMEx.a .pio/build/uno/lib06a/libOneButton.a .pio/build/uno/libf55/libU8g2.a .pio/build/uno/libFrameworkArduinoVariant.a .pio/build/uno/libFrameworkArduino.a -lm -Wl,--end-group
MethodWrapper(["checkprogsize"], [".pio/build/uno/firmware.elf"])
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [========= ]  93.1% (used 1906 bytes from 2048 bytes)
Flash: [========  ]  83.2% (used 26842 bytes from 32256 bytes)
.pio/build/uno/firmware.elf  :
section                     size      addr
.data                        240   8388864
.text                      26602         0
.bss                        1666   8389104
.comment                      17         0
.note.gnu.avr.deviceinfo      64         0
.debug_aranges               480         0
.debug_info                 4089         0
.debug_abbrev               1742         0
.debug_line                 2642         0
.debug_str                   520         0
Total                      38062
========================================== [SUCCESS] Took 1.57 seconds ==========================================

edited: typo and added result of PlatformIO verbose output

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.