Hi, PIO noob alert. I’m trying to learn PIO with a small board and example (though I have decades of experience in embedded systems – old school, if you will, trying to get up to speed).
I have a problem where I am flashing by hand and things work, though I am not sure why when I flash the board through the IDE it fails every time.
Through the command line I got to the point that it worked perfectly somehow.
The goal is: I would like to get it to work from the IDE so that it is captured properly in the program. I just do not know enough about PIO/frameworks/platforms, etc.
The board is an ESP-C3-32S-Kit and I made a small blink example to get things to work (in RISC-V). For a long time it would not build. Through a lot of researching, trying, etc., i made it compile and flash. The ini file is shown below.
[env:esp32dev]
platform = espressif32
framework = arduino, espidf
build_flags =
-D CONFIG_BLINK_GPIO=2
-D ARDUINO_RUNNING_CORE=0
-D CORE_DEBUG_LEVEL=5
monitor_speed = 115200
board = esp32-c3-devkitm-1
board_build.mcu = esp32c3
board_build.f_cpu = 160000000L
board_build.flash_size = 2MB
board_build.flash_mode = dio
board_build.partitions = partitions_2mb.csv
It would not work when flashing from the IDE arrow button, though the actual flashing appears to work without errors, however it just fails when the board attempts to run the code. It crashes after the bootloader, etc. In a clean copy of the project, I found that the partitions.bin created is different than what I found around and I placed in the project. I got this through research:
# Name, Type, SubType, Offset, Size
nvs, data, nvs, 0x9000, 0x4000
otadata, data, ota, 0xd000, 0x2000
app0, app, ota_0, 0x10000, 0x160000
app1, app, ota_1, 0x170000, 0x160000
eeprom, data, 0x99, 0x2d0000, 0x1000
spiffs, data, spiffs, 0x2d1000, 0x2F000
However, when I decoded the partitions.bin that worked via gen_esp32part.py (not sure how it was generated), I got this:
# ESP-IDF Partition Table
# Name, Type, SubType, Offset, Size, Flags
nvs,data,nvs,0x9000,24K,
phy_init,data,phy,0xf000,4K,
factory,app,factory,0x10000,1M,
I am not sure how I ended up with that file, as there was a LOT of trial and error while researching.
In the end, flashing from the IDE always fails and from the terminal it works. Here is the command that works (from the .pio/build/esp32dev/ folder):
esptool.py --chip esp32c3 --port /dev/tty.usbserial-110 --baud 460800 write_flash --flash_size 2MB 0x0 bootloader.bin 0x8000 partitions.bin 0x10000 firmware.bin
When I do the flashing from the IDE, I see this:
Processing esp32dev (platform: espressif32; framework: arduino, espidf; board: esp32-c3-devkitm-1)
-------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/esp32-c3-devkitm-1.html
PLATFORM: Espressif 32 (6.10.0) > Espressif ESP32-C3-DevKitM-1
HARDWARE: ESP32C3 160MHz, 320KB RAM, 4MB Flash
DEBUG: Current (cmsis-dap) External (cmsis-dap, esp-bridge, esp-builtin, esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES:
- framework-arduinoespressif32 @ 3.20017.241212+sha.dcc1105b
- framework-espidf @ 3.40407.240606 (4.4.7)
- tool-cmake @ 3.16.4
- tool-esptoolpy @ 1.40501.0 (4.5.1)
- tool-mkfatfs @ 2.0.1
- tool-mklittlefs @ 1.203.210628 (2.3)
- tool-mkspiffs @ 2.230.0 (2.30)
- tool-ninja @ 1.9.0
- toolchain-esp32ulp @ 1.23800.240113 (2.38.0)
- toolchain-riscv32-esp @ 8.4.0+2021r2-patch5
Warning! Arduino framework as an ESP-IDF component doesn't handle the `variant` field! The default `esp32` variant will be used.
Reading CMake configuration...
Warning! Flash memory size mismatch detected. Expected 4MB, found 2MB!
Please select a proper value in your `sdkconfig.defaults` or via the `menuconfig` target!
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 33 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Retrieving maximum program size .pio/build/esp32dev/firmware.elf
Checking size .pio/build/esp32dev/firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM: [ ] 2.2% (used 7096 bytes from 327680 bytes)
Flash: [== ] 21.1% (used 221376 bytes from 1048576 bytes)
Configuring upload protocol...
AVAILABLE: cmsis-dap, esp-bridge, esp-builtin, esp-prog, espota, esptool, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa
CURRENT: upload_protocol = esptool
Looking for upload port...
Auto-detected: /dev/cu.usbserial-110
Uploading .pio/build/esp32dev/firmware.bin
esptool.py v4.5.1
Serial port /dev/cu.usbserial-110
Connecting....
Chip is ESP32-C3 (revision v0.3)
Features: WiFi, BLE
Crystal is 40MHz
MAC: 7c:df:a1:b6:a3:9c
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 460800
Changed.
Configuring flash size...
Flash will be erased from 0x00000000 to 0x00004fff...
Flash will be erased from 0x00008000 to 0x00008fff...
Flash will be erased from 0x00010000 to 0x00046fff...
Compressed 20096 bytes to 12256...
Writing at 0x00000000... (100 %)
Wrote 20096 bytes (12256 compressed) at 0x00000000 in 0.7 seconds (effective 216.4 kbit/s)...
Hash of data verified.
Compressed 3072 bytes to 103...
Writing at 0x00008000... (100 %)
Wrote 3072 bytes (103 compressed) at 0x00008000 in 0.1 seconds (effective 385.3 kbit/s)...
Hash of data verified.
Compressed 223648 bytes to 115416...
Writing at 0x00010000... (12 %)
Writing at 0x0001b459... (25 %)
Writing at 0x00021ea1... (37 %)
Writing at 0x0002998e... (50 %)
Writing at 0x00030196... (62 %)
Writing at 0x00038426... (75 %)
Writing at 0x0003f35f... (87 %)
Writing at 0x0004633e... (100 %)
Wrote 223648 bytes (115416 compressed) at 0x00010000 in 4.0 seconds (effective 452.2 kbit/s)...
Hash of data verified.
Leaving...
Hard resetting via RTS pin...
I do not know why that does not work. It does look like there is a warning about detecting a 2M flash while expecting a 2MB flash (which I believe the board has).
Now, I´m bumbling around and do not know what I’m doing exacly, but somehow (somewhat directed guesswork) ended up making it work, but I am not sure how or why it works while the IDE does not.
So, to recap: is there anything that can be done to coerce the IDE to do what it has been done in the CLI flashing? i.w. so that the project and IDE captures things into doing the proper thing every time?
Thanks in advance!