我去年 (2024) 年下半年 (7~11 月) 花了近半年時間玩 ESP32 & MicroPython, 之後就回到 AI 學習軌道, 最近因為轉換至 Telegram 近尾聲, 想說也該給 xtools 函式庫改版了, 順手查詢 MicroPython 版本演進, 赫然發現它在 4 月時已釋出 v1.25 版! 我直接跳過 v1.24 哈哈.
韌體下載 :
此版更新說明參考 :
以下是請 ChatGPT 彙整的功能異動摘要 :
🔹 主要功能更新 :
- ROMFS(唯讀記憶體檔案系統)正式推出 :
經過三年開發, ROMFS 現已正式整合至 MicroPython. 它支援直接從唯讀記憶體執行 .mpy 位元組碼, 無需將其載入 RAM, 顯著提升模組匯入速度並減少記憶體使用.
目前支援 ROMFS 的板子包括:PYBD-SFx, 所有 alif-port 板子, 新的 ESP8266_GENERIC FLASH_2M_ROMFS 變體, 所有 STM32 Arduino 板子. 此外, mpremote 工具新增了 romfs 指令, 方便查詢、建構與部署 ROMFS. - 新增 alif port :
引入了 alif port, 支援 Alif Semiconductor 的 Ensemble 系列處理器, 擴展了 MicroPython 的硬體支援範圍. - 支援 RISC-V Inline Assembler :
RISC-V 架構現已支援內嵌組合語言, 允許開發者在 MicroPython 中撰寫高效能的底層程式碼. - 新增 DTLS 支援 :
透過 mbedTLS, MicroPython 現在支援 DTLS (Datagram Transport Layer Security), 增強了在 UDP 上的安全通訊能力. - mpremote 工具增強 :
mpremote 工具新增了遞迴刪除功能, 提升了遠端檔案管理的便利性.
🔸 其他重要更新 :
- 效能提升 :
RP2 port 的效能提升約 10%; STM32 port 在特定基準測試中效能提升達 20%. - ESP32 port 更新 :
全面轉向 ESP-IDF 5, 並支援 BLE 配對與綁定. - ESP8266 port 更新 :
新增對 ESP-NOW 協議的支援, 並整合所有板子為 ESP8266_GENERIC, 提供 FLASH_512K, FLASH_1M 和 OTA 變體. - 模組與函式增強 :
新增 machine.USBDevice, soft_reset() 等函式, 並在多個 port 中統一了 machine 模組的行為. - 語言功能增強 :
支援 f-string 的轉換指定符 (如 !r). 字典合併運算 (PEP 584), 並改進了浮點數的解析與格式化. - 網路模組統一 : 統一了 network 模組中 scan(),
connect() 和 config() 函式的參數名稱, 並新增了 hostname() 和 country() 函式. - 安全性增強 : 統一了各 port 的 mbedTLS 設定, 並啟用了橢圓曲線 DH 和 DSA 密碼學, 提升了連接網站的兼容性.
燒錄程序與指令參考 :
首先將開發板插入 PC 的 USB 埠, 然後按 Windows + X 鍵, 在彈出選單中點選 "裝置管理員" :
點選 "連接埠 (COM 和 LPT)" 就可以看到開發板目前所連接的 COM 埠 :
這個埠號在下面使用 esptool 燒錄韌體時會用到.
注意, 在進行下面的 esptool 指令操作之前須將 Thonny 關掉, 因為若 Thonny 已開啟開發板的 COM 埠, 則 esptool 程式將抓不到此埠, 會導致 esptool 指令執行失敗.
1. ESP32 S3 韌體燒錄 :
下載網址 :
因 ESP32-S3 有內建 8MB SPI RAM, 故要下載 "Support for Octal-SPIRAM" 的 .bin 檔才能使用到這些 SPI RAM :
我的 ESP32-S3 模組名稱為 ESP32-S3-WROOM-1-N16R8, 其中 N16 表示 Nand Flash 容量為 16MB, 而 R8 則表示 PSRAM (SPI RAM) 記憶體容量是 8MB.
PS D:\ESP32> esptool --port COM11 flash_id
esptool.py v4.6.2
Serial port COM11
Connecting....
Detecting chip type... ESP32-S3
Chip is ESP32-S3 (revision v0.2)
Features: WiFi, BLE
Crystal is 40MHz
MAC: 98:3d:ae:ee:f1:90
Uploading stub...
Running stub...
Stub running...
Manufacturer: 68
Device: 4018
Detected flash size: 16MB
Flash type set in eFuse: quad (4 data lines)
Hard resetting via RTS pin...
可見此 ESP32 S3 有 16MB 的 Flash 容量.
PS D:\ESP32> esptool --chip esp32s3 --port COM11 erase_flash
esptool.py v4.6.2
Serial port COM11
Connecting....
Chip is ESP32-S3 (revision v0.2)
Features: WiFi, BLE
Crystal is 40MHz
MAC: 98:3d:ae:ee:f1:90
Uploading stub...
Running stub...
Stub running...
Erasing flash (this may take a while)...
Chip erase completed successfully in 8.4s
Hard resetting via RTS pin...
這樣舊的韌體就被抹除了.
PS D:\ESP32> esptool --chip esp32s3 --port COM11 write_flash -z 0 ESP32_GENERIC_S3-SPIRAM_OCT-20250415-v1.25.0.bin
esptool.py v4.6.2
Serial port COM11
Connecting....
Chip is ESP32-S3 (revision v0.2)
Features: WiFi, BLE
Crystal is 40MHz
MAC: 98:3d:ae:ee:f1:90
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
Flash will be erased from 0x00000000 to 0x00199fff...
Compressed 1676624 bytes to 1098448...
Wrote 1676624 bytes (1098448 compressed) at 0x00000000 in 96.1 seconds (effective 139.5 kbit/s)...
Hash of data verified.
Leaving...
Hard resetting via RTS pin...
這樣新韌體就燒錄進去了, 按 Reset 鈕冷開機或 Thonny 的 "執行" 選單下的 "停止/重新啟動後端程式" 暖開機, 然後檢查記憶體 :
rst:0x1 (POWERON),boot:0x8 (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fce3820,len:0x105c
load:0x403c9700,len:0x4
load:0x403c9704,len:0xbd8
load:0x403cc700,len:0x2e34
entry 0x403c989c
MicroPython v1.25.0 on 2025-04-15; Generic ESP32S3 module with Octal-SPIRAM with ESP32S3
Type "help()" for more information.
MicroPython v1.25.0 on 2025-04-15; Generic ESP32S3 module with Octal-SPIRAM with ESP32S3
Type "help()" for more information.
>>> import gc
>>> print(gc.mem_free())
8309856
>>> import micropython
>>> micropython.mem_info()
stack: 736 out of 15360
GC: total: 64000, used: 14848, free: 49152, max new split: 8257536
No. of 1-blocks: 341, 2-blocks: 45, max blk sz: 32, max free sz: 3060
從 gc.mem_free() 與 micropython.mem_info() 的 max new split 大約 8MB 可知, MicroPython 已經成功地啟用了 ESP32 S3 開發板內建的 8MB SPRAM (SPI RAM), 因為這塊 S3 開發板是 N16R8, 其中 R8 表示 SPRAM 容量是 8MB. 這些 SPI RAM 記憶體在配置大物件 (例如長字串, 圖片, 或緩衝器等) 時就會用到.
2. ESP32 Wrover 韌體燒錄 :
韌體下載網址 :
因 ESP32 Wrover 有內建 4MB SPI RAM, 故要下載 "Support for SPIRAM/WROVER" 的 .bin 檔 (ESP32_GENERIC-SPIRAM-20250415-v1.25.0.bin) 才能使用到這些 SPI RAM :
查詢 Flash 資訊 :
D:\ESP32>esptool --port COM5 flash_id
esptool.py v4.6.2
Serial port COM5
Connecting....
Detecting chip type... Unsupported detection protocol, switching and trying again...
Connecting.......
Detecting chip type... ESP32
Chip is ESP32-D0WD-V3 (revision v3.1)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
Crystal is 40MHz
MAC: a8:42:e3:ae:72:64
Uploading stub...
Running stub...
Stub running...
Manufacturer: 68
Device: 4016
Detected flash size: 4MB
Hard resetting via RTS pin...
抹除 Flash 的舊韌體 :
D:\ESP32>esptool --chip esp32 --port COM5 erase_flash
esptool.py v4.6.2
Serial port COM5
Connecting....
Chip is ESP32-D0WD-V3 (revision v3.1)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
Crystal is 40MHz
MAC: a8:42:e3:ae:72:64
Uploading stub...
Running stub...
Stub running...
Erasing flash (this may take a while)...
Chip erase completed successfully in 5.2s
Hard resetting via RTS pin...
燒錄新韌體 :
D:\ESP32>esptool --chip esp32 --port COM5 write_flash -z 0x1000 ESP32_GENERIC-SPIRAM-20250415-v1.25.0.bin
esptool.py v4.6.2
Serial port COM5
Connecting.......
Chip is ESP32-D0WD-V3 (revision v3.1)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
Crystal is 40MHz
MAC: a8:42:e3:ae:72:64
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
Flash will be erased from 0x00001000 to 0x00177fff...
Compressed 1533872 bytes to 1010450...
Wrote 1533872 bytes (1010450 compressed) at 0x00001000 in 89.2 seconds (effective 137.6 kbit/s)...
Hash of data verified.
Leaving...
Hard resetting via RTS pin...
按 Reset 鈕冷開機或 Thonny 的 "執行" 選單下的 "停止/重新啟動後端程式" 暖開機, 然後檢查記憶體 :
ets Jul 29 2019 12:21:46
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:4892
ho 0 tail 12 room 4
load:0x40078000,len:14896
load:0x40080400,len:4
load:0x40080404,len:3372
entry 0x400805b0
MicroPython v1.25.0 on 2025-04-15; Generic ESP32 module with SPIRAM with ESP32
Type "help()" for more information.
MicroPython v1.25.0 on 2025-04-15; Generic ESP32 module with SPIRAM with ESP32
Type "help()" for more information.
>>> import gc
>>> print(gc.mem_free())
4174896
>>> import micropython
>>> micropython.mem_info()
stack: 736 out of 15360
GC: total: 56000, used: 13040, free: 42960, max new split: 4128768
No. of 1-blocks: 301, 2-blocks: 39, max blk sz: 32, max free sz: 2673
從 gc.mem_free() 與 micropython.mem_info() 的 max new split 大約 4MB 可知, MicroPython 已經成功地啟用了 ESP32 WROVER 開發板內建的 4MB SPRAM (SPI RAM).
3. ESP32 WROOM 韌體燒錄 :
韌體下載網址 :
這是一般的 ESP32 WROOM 開發板, 沒有 SPI RAM, 下載的 .bin 檔名為 ESP32_GENERIC-20250415-v1.25.0.bin :
D:\ESP32>esptool --port COM5 flash_id
esptool.py v4.6.2
Serial port COM5
Connecting....
Detecting chip type... Unsupported detection protocol, switching and trying again...
Connecting....
Detecting chip type... ESP32
Chip is ESP32-D0WD-V3 (revision v3.0)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
WARNING: Detected crystal freq 41.01MHz is quite different to normalized freq 40MHz. Unsupported crystal in use?
Crystal is 40MHz
MAC: c0:49:ef:b2:ba:60
Uploading stub...
Running stub...
Stub running...
Manufacturer: 0b
Device: 4016
Detected flash size: 4MB
Hard resetting via RTS pin...
D:\ESP32>esptool --chip esp32 --port COM5 erase_flash
esptool.py v4.6.2
Serial port COM5
Connecting.........
Chip is ESP32-D0WD-V3 (revision v3.0)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
Crystal is 40MHz
MAC: c0:49:ef:b2:ba:60
Uploading stub...
Running stub...
Stub running...
Erasing flash (this may take a while)...
Chip erase completed successfully in 10.1s
Hard resetting via RTS pin...
D:\ESP32>esptool --chip esp32 --port COM5 write_flash -z 0x1000 ESP32_GENERIC-20250415-v1.25.0.bin
esptool.py v4.6.2
Serial port COM5
Connecting.....
Chip is ESP32-D0WD-V3 (revision v3.0)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
WARNING: Detected crystal freq 41.01MHz is quite different to normalized freq 40MHz. Unsupported crystal in use?
Crystal is 40MHz
MAC: c0:49:ef:b2:ba:60
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
Flash will be erased from 0x00001000 to 0x001a0fff...
Compressed 1702240 bytes to 1117021...
Wrote 1702240 bytes (1117021 compressed) at 0x00001000 in 98.9 seconds (effective 137.7 kbit/s)...
Hash of data verified.
Leaving...
Hard resetting via RTS pin...
重新開機 :
ets Jul 29 2019 12:21:46
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:4892
ho 0 tail 12 room 4
load:0x40078000,len:14896
load:0x40080400,len:4
load:0x40080404,len:3372
entry 0x400805b0
MicroPython v1.25.0 on 2025-04-15; Generic ESP32 module with ESP32
Type "help()" for more information.
MicroPython v1.25.0 on 2025-04-15; Generic ESP32 module with ESP32
Type "help()" for more information.
>>> import gc
>>> print(gc.mem_free())
154224
>>> import micropython
>>> micropython.mem_info()
stack: 736 out of 15360
GC: total: 56000, used: 15536, free: 40464, max new split: 110592
No. of 1-blocks: 340, 2-blocks: 44, max blk sz: 32, max free sz: 2517
可見 ESP32 WROOM 的可用記憶體比 WROVER 或 S3 少很多 (沒辦法傳本機圖片). 以下是上傳 esptools.py 與 config.py 之後的記憶體狀態:
>>> print(gc.mem_free())
117280
>>> micropython.mem_info()
stack: 736 out of 15360
GC: total: 56000, used: 50992, free: 5008, max new split: 110592
No. of 1-blocks: 241, 2-blocks: 36, max blk sz: 129, max free sz: 102
4. ESP8266 (D1 Mini) 韌體燒錄 :
韌體下載網址 :
下面以 D1 Mini 開發板為例測試 :
D:\ESP8266>esptool --port COM5 flash_id
esptool.py v4.6.2
Serial port COM5
Connecting....
Detecting chip type... Unsupported detection protocol, switching and trying again...
Connecting....
Detecting chip type... ESP8266
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: 5c:cf:7f:b9:60:91
Uploading stub...
Running stub...
Stub running...
Manufacturer: ef
Device: 4016
Detected flash size: 4MB
Hard resetting via RTS pin...
可見 D1 mini 有 4MB Flash 可用來儲存資料與模組程式等.
抹除 Flash :
D:\ESP8266>esptool --chip esp8266 --port COM5 erase_flash
esptool.py v4.6.2
Serial port COM5
Connecting....
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: 5c:cf:7f:b9:60:91
Uploading stub...
Running stub...
Stub running...
Erasing flash (this may take a while)...
Chip erase completed successfully in 7.5s
Hard resetting via RTS pin...
燒錄韌體 :
D:\ESP8266>esptool --port COM5 --baud 115200 write_flash --flash_size=detect -fm dio 0 ESP8266_GENERIC-20250415-v1.25.0.bin
esptool.py v4.6.2
Serial port COM5
Connecting....
Detecting chip type... Unsupported detection protocol, switching and trying again...
Connecting....
Detecting chip type... ESP8266
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: 5c:cf:7f:b9:60:91
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
Auto-detected Flash size: 4MB
Flash will be erased from 0x00000000 to 0x0009bfff...
Flash params set to 0x0240
Compressed 636820 bytes to 426256...
Wrote 636820 bytes (426256 compressed) at 0x00000000 in 37.5 seconds (effective 135.7 kbit/s)...
Hash of data verified.
Leaving...
Hard resetting via RTS pin...
開機 :
MicroPython v1.25.0 on 2025-04-15; ESP module with ESP8266
Type "help()" for more information.
>>> import gc
>>> print(gc.mem_free())
33712
>>> import micropython
>>> micropython.mem_info()
stack: 2160 out of 8192
GC: total: 38016, used: 5664, free: 32352
No. of 1-blocks: 124, 2-blocks: 22, max blk sz: 18, max free sz: 1924
2025-04-24 補充 :
ESP8266 的記憶體實在太寒酸了, 匯入 esptools 模組記憶體爆掉 :
>>> import config
>>> import esptools
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
MemoryError: memory allocation failed, allocating 1336 bytes
結論 : 以後只買 ESP32 WROVER 等級以上的開發板, ESP8266 不予考慮.
沒有留言 :
張貼留言