补充 国产芯片及 CMSIS-DAP 调试器的支持.

Signed-off-by: rick.chan <cy@sina.com>
This commit is contained in:
rick.chan 2023-12-28 23:03:06 +08:00
parent 7f5ab5d943
commit 91bf11de0a
1 changed files with 93 additions and 0 deletions

View File

@ -16,6 +16,10 @@ published: true
- [1.2. 项目配置](#12-项目配置)
- [1.3. 编译和下载](#13-编译和下载)
- [2. 调试](#2-调试)
- [3. 国产芯片及 CMSIS-DAP 调试器的支持](#3-国产芯片及-cmsis-dap-调试器的支持)
- [3.1. PyOCD 的安装](#31-pyocd-的安装)
- [3.2. 关于 PyOCD 的扩展说明](#32-关于-pyocd-的扩展说明)
- [3.3 PyOCD 常用命令](#33-pyocd-常用命令)
VSCode 的嵌入式开发插件具备了相当多的功能,这里主要使用 Embedded IDE这是一个支持 MCU 开发的工具,但不具备调试功能,为了调试 ARM Cortex-M MCUs可以配合安装 Cortex-Debug 插件。这两个插件直接在扩展商店进行搜索安装即可,下面主要介绍使用方法。
@ -92,3 +96,92 @@ Embedded IDE 不具备调试功能,需要 Cortex-Debug 扩展插件。Cortex-D
Cortex-Debug 会自动安装 RTOS Views 以及其他一些依赖插件,如果提示自动安装,点击允许即可。
RTOS Views 支持 RTOS 调试功能,比如查看系统中的 Task 等。
## 3. 国产芯片及 CMSIS-DAP 调试器的支持
通常国产芯片会提供 Keil 的 pack 文件,以及 JTAG 扩展支持该芯片的方法。因此如果使用 Keil+DAP 或者使用 EIDE+JTAG 均可下载和调试。但使用 EIDE+DAP 就需要变通一下,因为 EIDE 所支持的调试器中并没有 Keil 中的 CMSIS-DAP 选项,只有 OpenOCD 和 PyOCD。而想让 OpenOCD 支持某款芯片就要编写该芯片的 Flash 算法,这个方法有些复杂。
而 PyOCD 则可以直接使用 Keil 的 pack 文件,通过这种方式使 EIDE 支持国产芯片更加普遍适用,并且易于实现。同时在 EIDE 的“Chip Support Package”中也可以通过文件加载 pack 文件来获取国产芯片的型号支持。
### 3.1. PyOCD 的安装
既然是 Py 开头的,那一定使需要用到 PythonWindows 下从官网下载好 Python3或者 Linux 下使用命令进行安装后(需要安装 pip通过 pip 命令安装 PyOCD 即可:
```bash
# 配置 pip 使用阿里云镜像.
pip config set global.index-url http://mirrors.aliyun.com/pypi/simple/
pip config set global.trusted-host mirrors.aliyun.com
pip config set global.timeout 120
# 安装 PyOCD.
pip install pyocd
```
***需要注意的是Windows 下不要使用 MSYS2 这类环境下的 python 和 pip容易安装失败。***
之后使用
```bash
pyocd --version
```
验证安装是否成功。
然后将 EIDE 中的“Flasher Configurationgs” 配置为 pyOCD。点击“Flasher Configurationgs->Other Options”将打开“debug.pyocd.yaml”文件向该文件添加
```yaml
pack:
- /Abs/Path/To/Company.Family_DFP.Version.pack
```
之后重启 Vscode便可在 EIDE 的 “Flasher Configurationgs->Target Name”中选择 pack 文件中的芯片,并进行调试。
***PyOCD 能够自动识别 CMSIS-DAP 等多种调试器,不需要再 EDID 中设置调试器种类。***
### 3.2. 关于 PyOCD 的扩展说明
以上使用 pack 包的方法是基于 PyOCD 对 pack 包的手动管理。PyOCD 支持两种手动管理 pack 包的方式,[官方原文](https://pyocd.io/docs/target_support.html)说明如下:
```md
Manual pack usage
If you prefer to manually manage packs, or if the managed pack system cannot access online packs from your network, you can download them yourself from the official CMSIS-Pack list. The downloaded pack files can be stored wherever you like. Typically you would group them in a single common directory. Another good option is to place the pack file used with a project in a project-relative location.
There are two ways to use a manually downloaded pack.
The simplest option is to pass the --pack option to the pyocd tool, specifying the path to the .pack file. PyOCD does not cache any information about packs used this way, so this argument must be passed for every invocation in addition to the other arguments. For instance, to run the GDB server, you might execute pyocd gdbserver --pack=Keil.STM32L4xx_DFP.2.2.0.pack. Note that you can pass multiple --pack arguments to pyOCD, which might be useful in a scripted execution of pyOCD.
For a more permanent solution, use a pyocd.yaml configuration file. In the config file, set the pack session option to either a single .pack file path or a list of paths. Now when you run the pyocd tool, it will automatically pick up the pack file(s) to use.
Here is an example config file that lists two packs.
pack:
- /Users/admin/CMSIS-Packs/Keil.STM32L0xx_DFP.2.0.0.pack
- /Users/admin/CMSIS-Packs/NXP.MKV58F24_DFP.11.0.0.pack
To see the targets provided by a .pack file, run pyocd list --targets and pass the approprate --pack option or use a config file, as described above.
Note: .pack files are simply zip archives with a different extension. To examine the contents of a pack, change the extension to .zip and extract.
Note: PyOCD can work with expanded packs just like zipped .pack files. Pass the path to the root directory of the pack using the --pack argument, as above. This is very useful for cases such as development or debugging of a pack, or for working with other CMSIS-Pack managers that store packs in decompressed form.
```
PyOCD 的 [yam 配置文件说明](https://pyocd.io/docs/configuration.html)如下:
```md
Config file
pyOCD supports a YAML configuration file that lets you set session options that either apply to all probes or to a single probe, based on the probes unique ID.
The easiest way to use a config file is to place a pyocd.yaml file in the project directory. An alternate .yml extension and optional dot prefix on the config file name are allowed. Alternatively, you can use the --config command line option, for instance --config=myconfig.yaml. Finally, you can set the config_file option. If there is a need to prevent reading a config file, use the --no-config argument.
The top level of the YAML file is a dictionary. The keys in the top-level dictionary must be names of session options, or the key probes. Session options are set to the value corresponding to the dictionary entry. Unrecognized option names are ignored.
```
EIDE 中的 debug.pyocd.yaml 属于项目级的配置文件。
### 3.3 PyOCD 常用命令
```bash
pyocd pack find <part keyword>
pyocd pack install <part number>
```