Skip to content

Commit 1b77d01

Browse files
committed
add: 增加AirMCU的调试方法
1 parent 27269f5 commit 1b77d01

6 files changed

Lines changed: 103 additions & 0 deletions

File tree

docs/Advanced/Debug.md

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
---
2+
title: AirMCU 的调试方法
3+
order: 1
4+
icon: fa fa-flask
5+
---
6+
7+
## 使用 VSCode 的`Crotex-Debug`插件
8+
9+
### 先决条件
10+
11+
- 安装 VSCode
12+
- 有一个支持的调试器,可以是 JLink,ST-Link,CMSIS-DAP 等,这里我们使用 DAPLink 作为例子
13+
- 安装 AirMCU 的 SDK
14+
- 安装`PyOCD`
15+
16+
### VSCode 的配置
17+
18+
#### 安装插件
19+
20+
在 VSCode 的插件市场中搜索`Cortex-Debug`,或者在<https://marketplace.visualstudio.com/items?itemName=marus25.cortex-debug>安装即可。
21+
22+
同样,搜索 [`Arduino`](https://marketplace.visualstudio.com/items?itemName=vsciot-vscode.vscode-arduino),安装`Arduino`插件。
23+
24+
#### 安装 PyOCD
25+
26+
安装 PyOCD 比较简单,在拥有 Python 环境的情况下,直接输入
27+
28+
```bash
29+
pip install --pre -U git+https://github.com/pyocd/pyOCD.git@develop
30+
```
31+
32+
命令安装最新版的 develop 分支的即可。
33+
34+
#### 建立工程
35+
36+
不管是新建一个工程还是用之前老的工程都行,这里我们以新建工程为例。
37+
38+
点击`F1`按钮,输入`Arduino: Initialize`
39+
40+
![](image/2023-10-05-01-11-32.png)
41+
42+
这里输入文件名,需要注意的是,这个文件名必须和父目录的名字一样,我们这里就修改为`Air001DebugTest.ino`
43+
44+
![](image/2023-10-05-01-12-37.png)
45+
46+
芯片型号我们以`Air001 Dev Chip`为例。
47+
48+
建立完成之后,我们随便写一些测试代码,例如:
49+
50+
```cpp
51+
void setup()
52+
{
53+
Serial.begin(115200);
54+
pinMode(PB0, OUTPUT);
55+
Serial.println("Hello World!");
56+
}
57+
58+
void loop()
59+
{
60+
digitalWrite(PB0, HIGH);
61+
delay(1000);
62+
digitalWrite(PB0, LOW);
63+
delay(1000);
64+
}
65+
```
66+
67+
对于 Arduino Board Configuration,我们选择如下的配置:
68+
69+
![](image/2023-10-05-01-16-17.png)
70+
71+
切记,Debug symbols and logs 选项中一定要选择有带`-g`的选项,这样才能生成调试符号。
72+
73+
#### 调试配置
74+
75+
在自动生成的`.vscode/arduino.json`文件中,我们需要添加一个属性`output`,这样才能获得编译出来的文件,一个典型的配置如下:
76+
77+
```json
78+
{
79+
"sketch": "Air001DebugTest.ino",
80+
"configuration": "UploadSpeed=115200,ClockSourceAndFrequency=HSI24M_HCLK48M,LowSpeedClockSource=None,xserial=generic,dbg=enable_sym,opt=osstd,SupplyVoltage=3V3,BootConnection=defaule",
81+
"board": "AirM2M:AirMCU:Air001Dev",
82+
"output": "build"
83+
}
84+
```
85+
86+
然后,我们点击上方的`Upload`按钮,编译并上传代码。
87+
88+
![](image/2023-10-05-01-23-50.png)
89+
90+
接下来,我们需要配置调试器,点击`F1`按钮,输入`Debug: Add uration`,然后选择`Cortex-Debug`
91+
92+
这样,在`.vscode`文件夹下就会自动生成一个`launch.json`文件。
93+
01. 我们需要修改其中的`serverpath`属性为`pyocd`
94+
2. 添加一个`armToolchainPath`属性,该属性的含义是一个`arm-none-eabi-gcc`套件的地址,需要注意的是其中需要包含 gbd,我们这里可以直接使用 AirMCU sdk 自带的,
95+
3. 添加`targetId`属性,属性的值为 pyocd 的 target 的 Part Number,我们这里使用`Air001`
96+
4. 修改`executable`属性,属性的值为编译出来的 elf 文件的地址,我们这里使用`${workspaceRoot}/build/Air001DebugTest.ino.elf`
97+
5. 修改`runToEntryPoint`属性,该属性为调试时自动运行到入口点,我们这里设置为`setup`
98+
99+
最后,我们点击 vscode 左边的`运行与调试`图标,或者是直接按`F5`,就可以开始调试了。
100+
101+
![](image/2023-10-05-01-35-12.png)
102+
103+
享受调试的乐趣吧!
71.2 KB
Loading
459 KB
Loading
516 KB
Loading
14.9 KB
Loading
2.21 MB
Loading

0 commit comments

Comments
 (0)