2022年2月8日 星期二

用 esptool.py 燒錄 MicroPython v1.18 韌體到 ESP32S 開發板

用 esptool.py 來燒錄 MicroPython 韌體真的很方便, 一個指令下下去就打死, 而且 ESP8266/ESP32 都可以用, 程式員還是用 command line 最順手啦! 下面紀錄將一顆 WROOM ESP32S 開發板內的 MicroPython 用 esptool.py 升版到 v1.18 的過程, 參考 :





此板右下角有一個 Flash 鈕, 在查詢或燒錄 Flash 前要先按住不放, 等指令執行後再放開. 


1. 檢查 ESP32 Flash 記憶體 :   

D:\ESP32>esptool.py --port COM9 flash_id
esptool.py v2.6
Serial port COM9
Connecting....
Detecting chip type... ESP32  
Chip is ESP32D0WDQ6 (revision 1)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
MAC: 80:7d:3a:b7:a7:5c
Uploading stub...
Running stub...
Stub running...
Manufacturer: 68
Device: 4016
Detected flash size: 4MB  
Hard resetting via RTS pin...


2. 抹除 ESP32 Flash 記憶體 :   

D:\ESP32>esptool.py --chip esp32 --port COM9 erase_flash
esptool.py v2.6
Serial port COM9
Connecting....
Chip is ESP32D0WDQ6 (revision 1)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
MAC: 80:7d:3a:b7:a7:5c
Uploading stub...
Running stub...
Stub running...
Erasing flash (this may take a while)...
Chip erase completed successfully in 5.3s
Hard resetting via RTS pin...


3. 燒錄 v1.18 韌體 :  

D:\ESP32>esptool.py --chip esp32 --port COM9 write_flash -z 0x1000 esp32-20220117-v1.18.bin
esptool.py v2.6
Serial port COM9
Connecting.......
Chip is ESP32D0WDQ6 (revision 1)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
MAC: 80:7d:3a:b7:a7:5c
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
Auto-detected Flash size: 4MB
Compressed 1555136 bytes to 1022998...
Wrote 1555136 bytes (1022998 compressed) at 0x00001000 in 91.1 seconds (effective 136.5 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...

D:\ESP32>



ets Jun  8 2016 00:22:57

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:4540
ho 0 tail 12 room 4
load:0x40078000,len:12344
ho 0 tail 12 room 4
load:0x40080400,len:4124
entry 0x40080680
MicroPython v1.18 on 2022-01-17; ESP32 module with ESP32
Type "help()" for more information.
>>> print('Hello World')     
Hello World

用 dir() 檢查記憶體中已載入模組 :

>>> dir()    
['uos', '__name__', 'os', 'gc', 'bdev']   

可見只有 os, uos, gc, 與 bdev 四個模組, 其中 os 是 uos 的別名, 可以直接用 os, 它實際上會調用 uos. 另外 esp 模組在新版沒有預載, 須自行匯入, 例如檢查 Flash 記憶體大小 :
 
>>> import esp   
>>> esp.flash_size()     
4194304

檢查 SRAM 資訊 :

>>> import micropython   
>>> micropython.mem_info()      
stack: 704 out of 15360
GC: total: 111168, used: 2176, free: 108992   
 No. of 1-blocks: 39, 2-blocks: 19, max blk sz: 18, max free sz: 6796

可見此 ESP32S 開發板的 SRAM 大小為 111KB (total), 目前可用為 109 KB. 

2023-01-15 補充 :

下面這篇文章提到 ESP32 與 ESP32S 開發板的差異 :


主要是 ESP32S 訊號較穩定. 

沒有留言 :