附ESP32C3的GPIO一覽:
vscode選擇Jtag燒錄,終端輸出esp_usb_jtag: could not find or open device:
D:\Devtools\Espressif\tools\openocd-esp32\v0.12.0-esp32-20230921\openocd-esp32\bin\openocd.exe -f board/esp32s3-builtin.cfgOpen On-Chip Debugger v0.12.0-esp32-20230921 (2023-09-21-13:40)
Licensed under GNU GPL v2
For bug reports, readhttp://openocd.org/doc/doxygen/bugs.html
Info : only one transport option; autoselecting 'jtag'
Info : esp_usb_jtag: VID set to 0x303a and PID to 0x1001
Info : esp_usb_jtag: capabilities descriptor set to 0x2000
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Error: esp_usb_jtag: could not find or open device!
按照Configure ESP32-C3 Built-in JTAG Interface嘗試解決,下了驅動:
Invoke-WebRequest 'https://dl.espressif.com/dl/idf-env/idf-env.exe' -OutFile .\idf-env.exe; .\idf-env.exe driver install --espressif
發現仍舊無法燒錄,設備管理器一看沒有相關的jtag unit驅動,只好嘗試改用esp prog。
用esp prog燒錄
參考了:https://blog.csdn.net/Marchtwentytwo/article/details/122071442
首先用espefuse查看芯片配置:
espefuse.py -p COM7 summary
參考的文章是直接不指定串口執行的,我這邊執行會報找不到串口的錯誤,原因是espefuse是通過串口來識別板子的,建議指定串口。
關于efuse設置可以參考esp官方c3的技術手冊:https://www.espressif.com/sites/default/files/documentation/esp32-c3_technical_reference_manual_cn.pdf#iomuxgpio
我手上的這塊c3版DIS_USB_SERIAL_JTAG
已經被置位了,難怪裝驅動時找不到JTAG unit.
espefuse.py v4.7.0
Connecting....
Detecting chip type... ESP32-C3=== Run "summary" command ===
EFUSE_NAME (Block) Description = [Meaningful Value] [Readable/Writeable] (Hex Value)
----------------------------------------------------------------------------------------
Calibration fuses:
K_RTC_LDO (BLOCK1) BLOCK1 K_RTC_LDO = 4 R/W (0b0000001)
。。。Usb fuses:
DIS_USB_JTAG (BLOCK0) Set this bit to disable function of usb switch to = False R/W (0b0)jtag in module of usb device
DIS_USB_SERIAL_JTAG (BLOCK0) USB-Serial-JTAG = Enable R/W (0b0)
USB_EXCHG_PINS (BLOCK0) Set this bit to exchange USB D+ and D- pins = False R/W (0b0)
DIS_USB_SERIAL_JTAG_ROM_PRINT (BLOCK0) USB printing = Enable R/W (0b0)
DIS_USB_SERIAL_JTAG_DOWNLOAD_MODE (BLOCK0) Disable UART download mode through USB-Serial-JTAG = False R/W (0b0)Vdd fuses:
VDD_SPI_AS_GPIO (BLOCK0) Set this bit to vdd spi pin function as gpio = False R/W (0b0)Wdt fuses:
WDT_DELAY_SEL (BLOCK0) RTC watchdog timeout threshold; in unit of slow cl = 40000 R/W (0b00)ock cycle
esp prog燒錄參考下文:
由于 ESP32-C3 默認選用 內置的 USB_SERIAL_JTAG 外設。此時需要燒錄 efuse 來選擇外接 JTAG 適配器,有以下兩種方式:
燒毀 DIS_USB_JTAG eFuse: 將永久禁用 USB_SERIAL_JTAG 和 CPU 的 JTAG 端口之間的連接。 然后可以將 JTAG 接口連接到 GPIO4 - GPIO7。 請注意,USB_SERIAL_JTAG 的 USB CDC 功能仍然可用,即仍然可以通過 USB CDC 進行燒錄和 log 查看。
燒毀 JTAG_SEL_ENABLE eFuse: 將啟用由 Strapping 引腳 GPIO10 選擇的 JTAG 接口。 如果 ESP32-C3 復位時 Strapping 引腳為低電平,則 JTAG 接口將使用 GPIO4 - GPIO7。 如果 Strapping 引腳為高電平,則 USB_SERIAL_JTAG 將用作 JTAG 接口。
我這邊summary沒有看到JTAG_SEL_ENABLE 選項,看來只能用DIS_USB_JTAG 方法了。
python -m espefuse -p COM7 burn_efuse DIS_USB_JTAGespefuse.py v4.7.0
Connecting....
Detecting chip type... ESP32-C3=== Run "burn_efuse" command ===
The efuses to burn:from BLOCK0- DIS_USB_JTAGBurning efuses:- 'DIS_USB_JTAG' (Set this bit to disable function of usb switch to jtag in module of usb device) 0b0 -> 0b1Check all blocks for burn...
idx, BLOCK_NAME, Conclusion
[00] BLOCK0 is not empty(written ): 0x000000008000000000000000000000000000000000000000(to write): 0x000000000000000000000000000000000000020000000000(coding scheme = NONE)
.
This is an irreversible operation!
Type 'BURN' (all capitals) to continue.
BURN
BURN BLOCK0 - OK (all write block bits are set)
Reading updated efuses...
Checking efuses...
Successful
燒錄完成后將esp prog連接至esp32c3對應引腳,用vscode的esp-idf擴展打開blink例子,測試燒錄:
idf.py build
或者
vscode ctrl+e然后b
若出現LIBUSB_ERROR_NOT_xxx
錯誤,記得用Zadig將esp prog的對應interface0驅動更新:
經測試,燒錄成功!
然后F5
, 測試gdb調試功能,畢竟花費這么久時間和心思用JTAG,不就是為了用gdb嗎?
首先寫好launch.json
{"version": "0.2.0","configurations": [{"name": "GDB","type": "cppdbg","request": "launch","MIMode": "gdb","miDebuggerPath": "${command:espIdf.getXtensaGdb}","program": "${workspaceFolder}/build/${command:espIdf.getProjectName}.elf","windows": {"program": "${workspaceFolder}\\build\\${command:espIdf.getProjectName}.elf"},"cwd": "${workspaceFolder}","environment": [{ "name": "PATH", "value": "${config:idf.customExtraPaths}" }],"setupCommands": [{ "text": "target remote :3333" },{ "text": "set remote hardware-watchpoint-limit 2"},{ "text": "mon reset halt" },{ "text": "thb app_main" },{ "text": "flushregs" }],"externalConsole": false,"logging": {"engineLogging": true}}]}
發現openocd server能正常啟動,很快就進入到熟悉的界面: