背景
有時候使用PIO
編寫的代碼需要發給客戶去驗證,相比較于發送源碼直接發送bin文件,更加的安全而且高效。不用擔心源碼的泄漏,也不用幫客戶配置PIO環境。
操作方法
1.編譯
首先進行代碼編譯,如編譯成功會在 .pio\build\airm2m_core_esp32c3
目錄下生成對應的編譯產物
2.準備對應產物文件
編譯生成的產物如下圖所示,其實還缺少一個boot_app0.bin
的二級boot跳轉文件,此文件在esp32 sdk的安裝目錄下。小編的在如下所示路徑中。可以參考此目錄在自己電腦上找下:
C:\Users\songz\.platformio\packages\framework-arduinoespressif32\tools\partitions\boot_app0.bin
3.燒錄
首先使用PIO
進行一次燒錄,查看下每個bin文件對應的地址分布,相應的地址分布如下圖所示:
產物名 | 燒錄地址 |
---|---|
bootloader.bin | 0x00000000 |
partitions.bin | 0x00008000 |
boot_app0.bin | 0x0000e000 |
firmware.bin | 0x00010000 |
然后使用ESP32 Download tool
進行燒錄(Flash下載工具|樂鑫科技 (espressif.com))
后記
可能有的讀者會好奇我是如何知道上面地址和產物的對應關系的,這是因為PIO
燒錄ESP32 歸根結底也是依賴于ESP tool
進行下載的,只是PIO
隱藏了燒錄過程中關于燒錄產物和地址的相關輸出,可以直接使用下面的命令在PIO
終端中進行一次燒錄即可看到相關的信息。
pio run -v -t upload
完整的日志如下:
PS E:\work\ESP32_BLE_Exit\ESP32_BLE_EXTI> pio run -v -t upload
Processing airm2m_core_esp32c3 (platform: espressif32; board: airm2m_core_esp32c3; framework: arduino; upload_speed: 1152000; upload_port: COM116; monitor_speed:
115200; monitor_port: COM116)
------------------------------------------------------------------------------------------------------------------------------------------------------------------CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/airm2m_core_esp32c3.html
PLATFORM: Espressif 32 (6.0.1) > AirM2M CORE ESP32C3
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.20006.221224 (2.0.6)- tool-esptoolpy @ 1.40400.0 (4.4.0)- tool-mkfatfs @ 2.0.1- tool-mklittlefs @ 1.203.210628 (2.3)- tool-mkspiffs @ 2.230.0 (2.30)- toolchain-riscv32-esp @ 8.4.0+2021r2-patch5
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 33 compatible libraries
Scanning dependencies...
Dependency Graph
|-- ESP32 BLE Arduino @ 2.0.0 (License: Unknown, Path: C:\Users\songz\.platformio\packages\framework-arduinoespressif32\libraries\BLE)
Building in release mode
<lambda>(["checkprogsize"], [".pio\build\airm2m_core_esp32c3\firmware.elf"])
MethodWrapper(["checkprogsize"], [".pio\build\airm2m_core_esp32c3\firmware.elf"])
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM: [= ] 13.9% (used 45580 bytes from 327680 bytes)
Flash: [========= ] 87.2% (used 1143238 bytes from 1310720 bytes)
.pio\build\airm2m_core_esp32c3\firmware.elf :section size addr.rtc.text 16 1342177280.rtc.force_fast 0 1342177296.rtc.data 16 1342177296.rtc_noinit 0 1342177312.rtc.force_slow 0 1342177312.iram0.text 63518 1077411840.dram0.dummy 64000 1070071808.dram0.data 13980 1070135808.noinit 0 1070149788.dram0.bss 31600 1070149792.flash.text 879028 1107296288.flash_rodata_dummy 917504 1006632992.flash.appdesc 256 1007550496.flash.rodata 186712 1007550752.eh_frame 81120 1007737464.flash.rodata_noload 0 1007818584.iram0.text_end 482 1077475358.iram0.data 0 1077475840.iram0.bss 0 1077475840.dram0.heap_start 0 1070181392.debug_info 9790248 0.debug_abbrev 704014 0.debug_loc 2036887 0.debug_aranges 89984 0.debug_ranges 246160 0.debug_line 3289982 0.debug_str 1500422 0.comment 93 0.riscv.attributes 55 0.debug_frame 206320 0Total 20102397
<lambda>(["upload"], [".pio\build\airm2m_core_esp32c3\firmware.bin"])
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
BeforeUpload(["upload"], [".pio\build\airm2m_core_esp32c3\firmware.bin"])
Using manually specified: COM116
"C:\Users\songz\.platformio\penv\Scripts\python.exe" "C:\Users\songz\.platformio\packages\tool-esptoolpy\esptool.py" --chip esp32c3 --port "COM116" --baud 1152000 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size 4MB 0x0000 E:\work\ESP32_BLE_Exit\ESP32_BLE_EXTI\.pio\build\airm2m_core_esp32c3\bootloader.bin 0x8000 E:\work\ESP32_BLE_Exit\ESP32_BLE_EXTI\.pio\build\airm2m_core_esp32c3\partitions.bin 0xe000 C:\Users\songz\.platformio\packages\framework-arduinoespressif32\tools\partitions\boot_app0.bin 0x10000 .pio\build\airm2m_core_esp32c3\firmware.bin
esptool.py v4.4
Serial port COM116
Connecting....
Chip is ESP32-C3 (revision v0.3)
Features: WiFi, BLE
Crystal is 40MHz
MAC: 60:55:f9:7b:b8:98
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 1152000
Changed.
Configuring flash size...
Flash will be erased from 0x00000000 to 0x00002fff...
Flash will be erased from 0x00008000 to 0x00008fff...
Flash will be erased from 0x0000e000 to 0x0000ffff...
Flash will be erased from 0x00010000 to 0x0013bfff...
Compressed 12144 bytes to 8814...
Writing at 0x00000000... (100 %)
Wrote 12144 bytes (8814 compressed) at 0x00000000 in 0.2 seconds (effective 422.4 kbit/s)...
Hash of data verified.
Compressed 3072 bytes to 146...
Writing at 0x00008000... (100 %)
Wrote 3072 bytes (146 compressed) at 0x00008000 in 0.0 seconds (effective 558.6 kbit/s)...
Hash of data verified.
Compressed 8192 bytes to 47...
Writing at 0x0000e000... (100 %)
Wrote 8192 bytes (47 compressed) at 0x0000e000 in 0.1 seconds (effective 762.0 kbit/s)...
Hash of data verified.
Compressed 1224752 bytes to 637138...
Writing at 0x00010000... (2 %)
Writing at 0x0001bd8c... (5 %)
Writing at 0x00028c4b... (7 %)
Writing at 0x00035a14... (10 %)
Writing at 0x00042dc6... (12 %)
Writing at 0x00050725... (15 %)
Writing at 0x000581cf... (17 %)
Writing at 0x0005df3e... (20 %)
Writing at 0x0006417a... (23 %)
Writing at 0x0006adc0... (25 %)
Writing at 0x00071f47... (28 %)
Writing at 0x00077fc5... (30 %)
Writing at 0x0007ead3... (33 %)
Writing at 0x00085ea9... (35 %)
Writing at 0x0008c45c... (38 %)
Writing at 0x00092af1... (41 %)
Writing at 0x00098f5c... (43 %)
Writing at 0x0009ef42... (46 %)
Writing at 0x000a64ab... (48 %)
Writing at 0x000acd4d... (51 %)
Writing at 0x000b470b... (53 %)
Writing at 0x000baf62... (56 %)
Writing at 0x000c12bc... (58 %)
Writing at 0x000c8372... (61 %)
Writing at 0x000d0324... (64 %)
Writing at 0x000d881c... (66 %)
Writing at 0x000df2c9... (69 %)
Writing at 0x000e5bb3... (71 %)
Writing at 0x000ec6da... (74 %)
Writing at 0x000f2bdb... (76 %)
Writing at 0x000f8997... (79 %)
Writing at 0x000ff7c3... (82 %)
Writing at 0x001078f4... (84 %)
Writing at 0x0010fb59... (87 %)
Writing at 0x0011a658... (89 %)
Writing at 0x001209b6... (92 %)
Writing at 0x001270c7... (94 %)
Writing at 0x0012e3e9... (97 %)
Writing at 0x001359f6... (100 %)
Wrote 1224752 bytes (637138 compressed) at 0x00010000 in 17.1 seconds (effective 572.2 kbit/s)...
Hash of data verified.Leaving...
Hard resetting via RTS pin...
================================================================== [SUCCESS] Took 24.93 seconds ==================================================================