I am trying to migrate my project from Arduino IDE to PlatformIO. I am new with PlatformIO. My project runs on an ESP32-C6. I am trying my best to learn the quirks and features of PlatformIO but I find it hard to find the information I am looking for within the documentation. In a way, this post sums up my struggles.
My main source of information is the following:
- https ://docs.platformio.org/en/latest/platforms/espressif32.html#espressif-32
- https ://docs.platformio.org/en/latest/frameworks/arduino.html#framework-arduino
- and this forum.
My issue I am having is mostly with how to configure platformio.ini properly so that compilation behaves like with Arduino IDE. When building with Arduino IDE, I get the following output:
Sketch uses 703230 bytes (53%) of program storage space. Maximum is 1310720 bytes.
Global variables use 33620 bytes (10%) of dynamic memory, leaving 294060 bytes for local variables. Maximum is 327680 bytes.
But when compiling with PlatformIO, the binary is too large and does not fit in a 4MB flash:
RAM: [== ] 17.6% (used 57728 bytes from 327680 bytes)
Error: The program size (1328424 bytes) is greater than maximum allowed (1310720 bytes)
Flash: [=====*** [checkprogsize] Explicit exit, status 1
=====] 101.4% (used 1328424 bytes from 1310720 bytes)
Where does the jump from 703kb to 1328kb comes from ? Clearly the platformIO project compiles more stuff or links more stuff. Maybe I am compiling in debug mode ? I don’t really know.
The source code is the same in both IDE/projects.
My project settings in Arduino IDE are the following:
- Boards:
ESP32C6 Dev Module - Debug Core Level:
Info - Flash Frequency:
80Mhz - Flash mode:
QIO - Flash size:
4MB - Partition Scheme:
Zigbee 4MB with spiffs - Upload speed
921600 - Zigbee Mode:
Zigbee ED (end device)
My platformio.ini file is the following:
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[env:esp32-c6-devkitc-1_arduino]
platform = https://github.com/pioarduino/platform-espressif32.git
board = esp32-c6-devkitc-1
framework = arduino
board_build.arduino.upstream_packages = no
lib_deps =
adafruit/Adafruit NeoPixel@^1.15.4
end2endzone/SoftTimers@^2.1.0
lennarthennigs/Button2@^2.5.0
build_flags =
-D ZIGBEE_MODE_ED
-D CORE_DEBUG_LEVEL=3
; PARTITION SCHEME:
; https://community.platformio.org/t/board-build-partitions-which-option-is-the-right-one/37201/3
; https://github.com/espressif/arduino-esp32/tree/master/tools/partitions
; https://esp32.jgarrettcorbin.com/
; https://raw.githubusercontent.com/espressif/arduino-esp32/refs/tags/3.3.7/boards.txt
; [...]
; According to https://raw.githubusercontent.com/espressif/arduino-esp32/refs/tags/3.3.7/boards.txt,
; to emulate selecting menu option `Zigbee 4MB with spiffs`, I need to define the following:
; esp32c6.menu.PartitionScheme.zigbee.build.partitions=zigbee
; esp32c6.menu.PartitionScheme.zigbee.upload.maximum_size=1310720
; Which maps to the following:
board_build.partitions=zigbee.csv
board_upload.maximum_size=1310720
; https://community.platformio.org/t/how-to-change-partition-scheme-for-esp32/29687/5
; https://community.platformio.org/t/moving-from-arduino-ide-to-platformio-ide/42372/15
; https://community.platformio.org/t/how-to-change-partition-scheme-for-esp32/29687/6
board_build.flash_mode = qio
board_build.f_flash = 80000000L
; ESP32 Core Debug Levels:
; https://docs.platformio.org/en/latest/platforms/espressif32.html#debug-level
; https://community.platformio.org/t/how-to-set-up-log-level-to-be-able-to-debug-the-esp32/8278
; Set macro `CORE_DEBUG_LEVEL` to one of the following values:
; NONE 0
; ERROR 1
; WARNING 2
; INFO 3
; DEBUG 4
; VERBOSE 5
; For example:
; -D CORE_DEBUG_LEVEL=2
; Zigbee Modes:
; https://github.com/espressif/arduino-esp32/blob/3.3.7/boards.txt
; -D ZIGBEE_MODE_ED
; -D ZIGBEE_MODE_ZCZR
; ERASE FLASH
; https://docs.platformio.org/en/latest/platforms/espressif32.html#erase-flash
; `pio run --target erase`
I’ve also found hints in other posts stating that I need to find my Arduino IDE settings in https://raw.githubusercontent.com/espressif/arduino-esp32/refs/tags/3.3.7/boards.txt and then “maps” them to values in the ini file. I do not understand how I am supposed to do this. For example, in Arduino IDE, i’Ve selected Upload Speel 921600, this matches the following lines:
```
esp32c6.menu.UploadSpeed.921600=921600
esp32c6.menu.UploadSpeed.921600.upload.speed=921600
```
But then I do not know the expected parameter names in the ini. The examples in https ://docs.platformio.org/en/latest/projectconf/index.html are not giving me hints of what it could be.
Same for when I configure my project settings as a Zigbee ED (end device). It matches the following lines in boards.txt:
esp32c6.menu.ZigbeeMode.ed=Zigbee ED (end device)
esp32c6.menu.ZigbeeMode.ed.build.zigbee_mode=-DZIGBEE_MODE_ED
esp32c6.menu.ZigbeeMode.ed.build.zigbee_libs=-lesp_zb_api.ed -lzboss_stack.ed -lzboss_port.native
but without my previous c/c++ experience I would not recognise that -DZIGBEE_MODE_ED is a macro definition which must be added to build_flags. But how about -lesp_zb_api.ed -lzboss_stack.ed -lzboss_port.native? These looks like linking libraries but I do not know what to do with these. How can I specify “additionnal linking library directories” (I come from Visual Studio 2019+) ?
I’m sorry. I do not want to sound angry, like I am ranting over this but I feel really lost and confused. I’ve seens many videos on youtube showing how easy it is to write arduino projects using PlatformIO. Now that VSCode’s Arduino extensions is down, I think PlatformIO is the right choice as my main IDE for Arduino dev. Any help a much appreciated.