VSCode + JTAG調試合宙ESP32C3的經歷

来源:https://www.cnblogs.com/liteng0305/archive/2023/01/02/17019812.html
-Advertisement-
Play Games

VSCode + JTAG調試合宙ESP32C3 環境 Windows10 VSCode + ESP-IDF 合宙ESP32C3(無串口晶元版本) 理論 想要直接使用內置JTAG,USB要求連接GPIO18和GPIO19 合宙ESP32C3有串口晶元版本USB經過CH343連接的串口,無法使用內置J ...


VSCode + JTAG調試合宙ESP32C3

環境

Windows10

VSCode + ESP-IDF

合宙ESP32C3(無串口晶元版本)

理論

想要直接使用內置JTAG,USB要求連接GPIO18和GPIO19

合宙ESP32C3有串口晶元版本USB經過CH343連接的串口,無法使用內置JTAG

合宙ESP32C3無串口晶元版本滿足要求

步驟

連接PC後有一個虛擬串口和一個USB JTAG介面

按住BOOT,然後按下RST,鬆開BOOT,晶元進入下載模式,下載固件

PS F:\Espressif\frameworks\esp-idf-v4.4.3\workspace\hello_world> idf.py flash -p COM16 -b 921600
Executing action: flash
Running ninja in directory f:\espressif\frameworks\esp-idf-v4.4.3\workspace\hello_world\build
Executing "ninja flash"...
[1/5] cmd.exe /C "cd /D F:\Espressif\frameworks\esp-idf-v4.4.3\workspace\hello_world\build\esp-idf\esptool_py && ...ion_table/partition-table.bin F:/Espressif/frameworks/esp-idf-v4.4.3/workspace/hello_world/build/hello_world.bin"hello_world.bin binary size 0x25130 bytes. Smallest app partition is 0x100000 bytes. 0xdaed0 bytes (86%) free.
[2/5] Performing build step for 'bootloader'
[1/1] cmd.exe /C "cd /D F:\Espressif\frameworks\esp-idf-v4.4.3\workspace\hello_world\build\bootloader\esp-idf\esptool_py && F:\Espressif\python_env\idf4.4_py3.8_env\Scripts\python.exe F:/Espressif/frameworks/esp-idf-v4.4.3/components/partition_table/check_sizes.py --offset 0x8000 bootloader 0x0 F:/Espressif/frameworks/esp-idf-v4.4.3/workspace/hello_world/build/bootloader/bootloader.bin"
Bootloader binary size 0x4d70 bytes. 0x3290 bytes (40%) free.
[2/3] cmd.exe /C "cd /D F:\Espressif\frameworks\esp-idf-v4.4.3\components\esptool_py && F:\Espressif\tools\cmake\...rkspace/hello_world/build" -P F:/Espressif/frameworks/esp-idf-v4.4.3/components/esptool_py/run_serial_tool.cmake"esptool.py esp32c3 -p COM16 -b 921600 --before=default_reset --after=hard_reset write_flash --flash_mode dio --flash_freq 80m --flash_size 2MB 0x0 bootloader/bootloader.bin 0x10000 hello_world.bin 0x8000 partition_table/partition-table.bin
esptool.py v3.3.2
Serial port COM16
Connecting....
Chip is ESP32-C3 (revision 3)
Features: Wi-Fi
Crystal is 40MHz
MAC: 60:55:f9:75:9c:90
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 921600
Changed.
Configuring flash size...
Flash will be erased from 0x00000000 to 0x00004fff...
Flash will be erased from 0x00010000 to 0x00035fff...
Flash will be erased from 0x00008000 to 0x00008fff...
Compressed 19824 bytes to 12050...
Writing at 0x00000000... (100 %)
Wrote 19824 bytes (12050 compressed) at 0x00000000 in 0.3 seconds (effective 585.5 kbit/s)...
Hash of data verified.
Compressed 151856 bytes to 82022...
Writing at 0x00010000... (16 %)
Writing at 0x00019991... (33 %)
Writing at 0x000202c8... (50 %)
Writing at 0x0002749a... (66 %)
Writing at 0x0002dacd... (83 %)
Writing at 0x00035037... (100 %)
Wrote 151856 bytes (82022 compressed) at 0x00010000 in 1.8 seconds (effective 687.7 kbit/s)...
Hash of data verified.
Compressed 3072 bytes to 103...
Writing at 0x00008000... (100 %)
Wrote 3072 bytes (103 compressed) at 0x00008000 in 0.0 seconds (effective 684.5 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...
Done
PS F:\Espressif\frameworks\esp-idf-v4.4.3\workspace\hello_world> 

啟動OpenOCD和GDB前先按下RST重啟晶元,運行在正常模式,而不是下載模式

使用樂鑫OpenOCD,搭配board/esp32c3-builtin.cfg

啟動OpenOCD,監聽3333,成功

PS F:\Espressif\frameworks\esp-idf-v4.4.3\workspace\hello_world> openocd -f board/esp32c3-builtin.cfg
Open On-Chip Debugger  v0.11.0-esp32-20220706 (2022-07-06-15:48)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
Info : only one transport option; autoselect 'jtag'       
Info : esp_usb_jtag: VID set to 0x303a and PID to 0x1001  
Info : esp_usb_jtag: capabilities descriptor set to 0x2000
Warn : Transport "jtag" was already selected
Info : Listening on port 6666 for tcl connections   
Info : Listening on port 4444 for telnet connections
Info : esp_usb_jtag: serial (60:55:F9:75:9C:90)     
Info : esp_usb_jtag: Device found. Base speed 40000KHz, div range 1 to 255
Info : clock speed 40000 kHz
Info : JTAG tap: esp32c3.cpu tap/device found: 0x00005c25 (mfg: 0x612 (Espressif Systems), part: 0x0005, ver: 0x0)
Info : datacount=2 progbufsize=16
Info : Examined RISC-V core; found 1 harts       
Info :  hart 0: XLEN=32, misa=0x40101104
Info : starting gdb server for esp32c3 on 3333   
Info : Listening on port 3333 for gdb connections

根據官方教程創建gdbinit文件,埠3333

target remote :3333
set remote hardware-watchpoint-limit 2
mon reset halt
flushregs
thb app_main
c

啟動GDB調試,成功,此時已經可以使用GDB調試了

PS F:\Espressif\frameworks\esp-idf-v4.4.3\workspace\hello_world> riscv32-esp-elf-gdb -x gdbinit build/hello_world.elf
F:\Espressif\tools\riscv32-esp-elf\esp-2021r2-patch5-8.4.0\riscv32-esp-elf\bin\riscv32-esp-elf-gdb.exe: warning: Couldn't determine a path for the index cache directory.
GNU gdb (crosstool-NG esp-2021r2-patch5) 9.2.90.20200913-git
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "--host=x86_64-host_w64-mingw32 --target=riscv32-esp-elf".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from build/hello_world.elf...
0x40000000 in ?? ()
JTAG tap: esp32c3.cpu tap/device found: 0x00005c25 (mfg: 0x612 (Espressif Systems), part: 0x0005, ver: 0x0)
Reset cause (3) - (Software core reset)
Hardware assisted breakpoint 1 at 0x42005eee: file F:/Espressif/frameworks/esp-idf-v4.4.3/workspace/hello_world/main/hello_world_main.c, line 17.
[New Thread 1070136696]
[New Thread 1070130304]
[Switching to Thread 1070134812]

Thread 1 "main" hit Temporary breakpoint 1, app_main () at F:/Espressif/frameworks/esp-idf-v4.4.3/workspace/hello_world/main/hello_world_main.c:17
17      {
(gdb)

OpenOCD可以看到GDB連接後的行為

Info : accepting 'gdb' connection on tcp/3333
Memory protection is enabled. Reset target to disable it...
Info : JTAG tap: esp32c3.cpu tap/device found: 0x00005c25 (mfg: 0x612 (Espressif Systems), part: 0x0005, ver: 0x0)
Info : Reset cause (3) - (Software core reset)
Warn : No symbols for FreeRTOS!
Info : [esp32c3] Found 8 triggers
Info : Flash mapping 0: 0x10020 -> 0x3c020020, 27 KB
Info : Flash mapping 1: 0x20020 -> 0x42000020, 75 KB
Info : Auto-detected flash bank 'esp32c3.flash' size 4096 KB
Info : Using flash bank 'esp32c3.flash' size 4096 KB
Info : Flash mapping 0: 0x10020 -> 0x3c020020, 27 KB
Info : Flash mapping 1: 0x20020 -> 0x42000020, 75 KB
Info : Using flash bank 'esp32c3.irom' size 76 KB
Info : Flash mapping 0: 0x10020 -> 0x3c020020, 27 KB
Info : Flash mapping 1: 0x20020 -> 0x42000020, 75 KB
Info : Using flash bank 'esp32c3.drom' size 28 KB
Warn : negative reply, retrying
Warn : Prefer GDB command "target extended-remote :3333" instead of "target remote :3333"
Info : JTAG tap: esp32c3.cpu tap/device found: 0x00005c25 (mfg: 0x612 (Espressif Systems), part: 0x0005, ver: 0x0)
Info : Reset cause (3) - (Software core reset)

VSCode

使用指令行已成功,接下來使用VSCode

VSCode ESP-IDF插件官方說明如下,我使用ESP-IDF Debug Adapter失敗,使用Microsoft C/C++ extension調試成功

vscode-esp-idf-extension/DEBUGGING.md at master · espressif/vscode-esp-idf-extension · GitHub

使用ESP-IDF插件,啟動OpenOCD,列印如下,本質和指令行直接調用沒啥區別

[OpenOCD]
[Stopped] : OpenOCD Server
[OpenOCD]
Open On-Chip Debugger  v0.11.0-esp32-20220706 (2022-07-06-15:48)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
[OpenOCD]
debug_level: 2

[OpenOCD]
Info : only one transport option; autoselect 'jtag'
[OpenOCD]
Info : esp_usb_jtag: VID set to 0x303a and PID to 0x1001
Info : esp_usb_jtag: capabilities descriptor set to 0x2000
Warn : Transport "jtag" was already selected
[OpenOCD]
Info : Listening on port 6666 for tcl connections
[OpenOCD]
Info : Listening on port 4444 for telnet connections
[OpenOCD]
Info : esp_usb_jtag: serial (60:55:F9:75:9C:90)
[OpenOCD]
Info : esp_u[OpenOCD]
sb_jtag: Device found. Base speed 40000KHz, div range 1 to 255
[OpenOCD]
Info : cloc[OpenOCD]
k speed 40000 kHz
[OpenOCD]
Info : JTAG tap: esp32c3.cpu tap/device found: 0x00005c25 (mfg:[OpenOCD]
 0x612 (Espressif Systems), part: 0x0005, ver: 0x0)
[OpenOCD]
Info : datacount=2 progbufsize=16
[OpenOCD]
Info : Examined RISC-V[OpenOCD]
 core; found 1 harts
Info :  hart 0: XLEN=32, misa=0x40101104
[OpenOCD]
Info : [esp32c3] Found 8 trig[OpenOCD]
gers
[OpenOCD]
Info : starting gdb server for esp32c3 on 3333
Info : Listening on port 3333 for gdb connections

根據插件官方說明,創建launch.json,我修改了"miDebuggerPath",根據自己的情況修改即可

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "GDB",
      "type": "cppdbg",
      "request": "launch",
      "MIMode": "gdb",
      "miDebuggerPath": "F:/Espressif/tools/riscv32-esp-elf/esp-2021r2-patch5-8.4.0/riscv32-esp-elf/bin/riscv32-esp-elf-gdb.exe",
      "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
      }
    }
  ]
}

打個斷點按下F5進行調試,按了三下才開啟,原因未知


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • JZ78 把二叉樹列印成多行 題目 給定一個節點數為 n 二叉樹,要求從上到下按層列印二叉樹的 val 值,同一層結點從左至右輸出,每一層輸出一行, 將輸出的結果存放到一個二維數組中返回。 例如:給定的二叉樹是{1,2,3,#,#,4,5} [ [1], [2,3], [4,5] ] 方法 非遞歸層 ...
  • 1. 協議的作用 TCP/IP 中消息傳輸基於流的方式,沒有邊界 協議的目的就是劃定消息的邊界,制定通信雙方要共同遵守的通信規則 2. Redis 協議 如果我們要向 Redis 伺服器發送一條 set name Nyima 的指令,需要遵守如下協議 // 該指令一共有3部分,每條指令之後都要添加回 ...
  • JVM是運行在操作系統之上的,它與硬體沒有直接的交互。先說一下JVM的記憶體區域,當函數開始運行時,JVM拿到自己的記憶體將自己的記憶體區域進行了分割,分為五塊區域:線程共用的有堆、方法區,線程私有的有java棧、本地方法棧、程式計數器。 ...
  • 公司直招 急聘崗位 ♦telegram:@xiaobai04 @HRdajisi♦釘釘:馬新宇 零九四五五五壹零壹六吧♦Skype: live:.cid.d850fdc83f05e44a♦郵箱:[email protected] ♦技術部:薪資面議 薪資範圍25-100k 績效:MA ...
  • 來源:blog.csdn.net/randompeople/article/details/114917087 為什麼 java wait/notify 必須與 synchronized 一起使用 這個問題就是書本上沒怎麼講解,就是告訴我們這樣處理,但沒有解釋為什麼這麼處理?我也是基於這樣的困惑去了 ...
  • 在2012 年 10 月,一個叫 Mike Youngstrom 的人在 Spring Jira 中創建了一個功能請求,要求在 Spring Framework 中支持無容器 Web 應用程式體繫結構,提出了在主容器引導 Spring 容器內配置 Web 容器服務;這件事情對 SpringBoot ... ...
  • 初識Java Java的特性和優勢 簡單性 就是c++語法的純凈版。沒有頭文件,指針運算,結構,聯合,操作符重載,虛基類等等。 面向對象 面向對象是一種程式設計技術,他將重點放在數據(即對象)和對象之間的介面上。萬物皆對象! 可移植性 這是JAVA的一個重要的優勢。JAVA代碼或者說位元組碼、二進位碼 ...
  • 數據分頁往往有三種常用方案。 第一種,把資料庫中存放的相關數據,全部讀入PHP/Java/C#代碼/記憶體,再由代碼對其進行分頁操作(速度慢,簡易性高)。 第二種,直接在資料庫中對相關數據進行分頁操作,再把分頁後的數據輸出給代碼程式(速度中,簡易性中)。 第三種,先把資料庫中的相關數據全部讀入“緩存” ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...