2021基于vscode以及jlink调试esp32最新

Posted _WILLPOWER_

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2021基于vscode以及jlink调试esp32最新相关的知识,希望对你有一定的参考价值。

ESP32-JTAG 调试官方指南

前提条件

1. 插件安装:vscode插件Espressif IDF安装
2. 插件安装:vscode插件Native Debug安装
3. 有一个jlink调试器.

Jlink调试器

首先你需要安装jlink的驱动,这里给出一个链接下载[提取码:2wq7 ],安装说明:链接[提取码:4s9l]



请注意:VERF一定要连接到开发板的VCC,让其工作,有什么jtag连接的问题请参考安装说明
注意:esp32是不支持swd的

openocd-jlink配置修改

在连接完后,我们可以到你安装Espressif IDF插件中的espressif文件夹中(根据你安装位置的不同自己找),它长这样

进入tools->openocd-esp32->v0.10.0-esp32-20210401->openocd-esp32中,可以看到如下文件

其中bin中存放着openocd.exe就是我们需要用到的调试软件,而在share文件加中,存放着是不同协议的配置文件以及芯片信息。
因为我们用的是jlink因此我们对jlink的配置文件做出修改:
share\\openocd\\scripts\\interface中找到jlink.cfg进行修改:
添加:
adapter_khz 20000

保存退出



驱动更换

登陆网站http://zadig.akeo.ie/下载zadig软件,用来安装仿真器的驱动程序,openOCD只把Jlink仿真器当作普通的USB设备来使用,不使用Jlink自带的仿真器驱动程序,如果已安装了Jlink仿真器驱动程序,这个过程就是把原先的驱动程序换掉。

作者:罗蓁蓁
链接:https://www.jianshu.com/p/a66a4c7e6f94
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

打开Zadig软件,选择Options勾选List All Devices

这个时候选择j-link然后驱动更换为winUSB类型,点击install driver即可安装
一定要进行此步,不然openocd找不到jlink的

vscode配置修改

进行完此步后,我们就可以打开vscode工程了,这里我们以helloworld为例

crtl+shift+p输入idf example,选择我们的helloworld工程

我们首先修改我们的配置文件.vscode/setting.json


添加OpenOCD脚本目录中的配置文件列表
修改interface,也就是idf.openocdconfigs第一行配置为我们的jlink,其中第二行修改为我们的芯片。

修改完了后,我们到.vscode/launch.setting中将其中的内容全部删除,替换为如下
此处参考出处
我自己修改了下面这部分,就不用增加环境变量等了。

// ======================== launch.json ========================

  // Use IntelliSense to learn about possible attributes.
  // Hover to view descriptions of existing attributes.
  // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
  "version": "0.2.0",
  "configurations": [
    
      "type": "gdb",
      "request": "launch",
      "name": "Debug ESP32",
      "target": "build/$workspaceFolderBasename.elf",
      "cwd": "$workspaceFolder",
      "gdbpath": "$config:idf.toolsPathWin/tools/xtensa-esp32-elf/esp-2021r1-8.4.0/xtensa-esp32-elf/bin/xtensa-esp32-elf-gdb.exe", // Path of the toolchain
      "autorun": [
        "target remote :3333", // Connect to OpenOCD
        "mon reset halt", // Reset the chip and keep the CPUs halted
        "set remote hardware-watchpoint-limit 2", // Restrict GDB to using two hardware watchpoints supported by ESP32
        "flushregs", // Force GDB to get new state from the target
        "thb app_main", // Insert a temporary hardware breakpoint at the main function
        "c" // Resume the program. It will then stop at breakpoint inserted at app_main
      ],
      // "preLaunchTask": "OpenOCD"
    ,
    
      "type": "gdb",
      "request": "launch",
      "name": "flash and debug ESP32",
      "target": "build/$workspaceFolderBasename.elf",
      "cwd": "$workspaceFolder",
      "gdbpath": "$config:idf.toolsPathWin/tools/xtensa-esp32-elf/esp-2021r1-8.4.0/xtensa-esp32-elf/bin/xtensa-esp32-elf-gdb.exe", // Path of the toolchain
      "autorun": [
        "target remote :3333", // Connect to OpenOCD
        "mon reset halt", // Reset the chip and keep the CPUs halted
        "mon program_esp32 build/$workspaceFolderBasename.bin 0x10000",
        "mon reset halt", // Reset the chip and keep the CPUs halted
        "set remote hardware-watchpoint-limit 2", // Restrict GDB to using two hardware watchpoints supported by ESP32
        "flushregs", // Force GDB to get new state from the target
        "thb app_main", // Insert a temporary hardware breakpoint at the main function
        "c" // Resume the program. It will then stop at breakpoint inserted at app_main
      ],
      // "preLaunchTask": "OpenOCD"
    

  ]

其中
Debug ESP32是直接调试
flash and debug ESP32是烧录并调试

然后我们开始编译(注意终端要是cmd或者powershell,不能是bash)



编译完成后,进行下载


打开我们的monitor进行查看

然后完成后,我们开启openocd服务器端,让xtensa-esp32-elf-gdb.exe进行连接调试。
说实话,调试起来体验感不是很好,可以看一下gif

问题

说找不到hello_world.elf文件的,修改顶层cmakelist.txt

参考

开源调试软件OpenOCD
解决openocd无法识别jlink的问题
ESP32 使用 Jlink 进行 JTAG 调试的流程
esp32-JTAG 调试官方指南
esp32_debug_template

以上是关于2021基于vscode以及jlink调试esp32最新的主要内容,如果未能解决你的问题,请参考以下文章

在Linux环境下使用JLink一键编译烧录调试包括但不限于Cortex-M芯片,如STM32SAMK60等

在Linux环境下使用JLink一键编译烧录调试包括但不限于Cortex-M芯片,如STM32SAMK60等

在Linux环境下使用JLink一键编译烧录调试包括但不限于Cortex-M芯片,如STM32SAMK60等

基于VSCode的Java的构建调试环境搭建指南

调试笔记--jlink 变量转实时波形小技巧

荔枝派 zero 使用 Jlink 调试