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?
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.
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?
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.