【前言】
最近调通了gd32f527的Zephyr工程,然后国产的雅特力还没有人接手做Zephyr的移植,我准备把手上的开发板利用起来,给国产的芯片移植到Zephyr生态贡献一份力量。
要移植Zephyr,那么首先需要整理好在vscode下面开发板的基础工作。雅特力刚好提供了vscode的模工程,此次是下载官方的vscode模版库,然后完成配置,实现在vscode下面的开发、下载、调试等工作。
1. 准备工作
首先下载官方的AN0130_AT32_MCU_Develop_With_VSCode_V2.0.5.zip库,这个库我上传到附件。
解压后,使用vscode打开at32f423的模版库
工具链目录结构D:\AT32F423\SourceCode\software_tool\tool_for_windows\ ├── OpenOCD_V2.0.2\ # OpenOCD 调试器 │ ├── bin\openocd.exe │ └── scripts\ │ ├── interface\atlink.cfg │ └── target\at32f423xx.cfg └── gcc-arm-none-eabi-10.3-2021.10-win32.exe C:\Users\liujianhua\.eide\tools\gcc_arm\bin\ └── arm-none-eabi-gcc.exe # GCC 编译工具链修改配置如下:
2. .vscode/launch.json
{
"configurations": [
{
"cwd": "${workspaceRoot}",
"type": "cortex-debug",
"request": "launch",
"name": "openocd-launch",
"armToolchainPath": "C:/Users/liujianhua/.eide/tools/gcc_arm/bin",
"gdbPath": "C:/Users/liujianhua/.eide/tools/gcc_arm/bin/arm-none-eabi-gdb.exe",
"interface": "swd",
"servertype": "openocd",
"serverpath": "D:/AT32F423/SourceCode/software_tool/tool_for_windows/OpenOCD_V2.0.2/bin/openocd.exe",
"configFiles": [
"D:/AT32F423/SourceCode/software_tool/tool_for_windows/OpenOCD_V2.0.2/scripts/interface/atlink.cfg",
"D:/AT32F423/SourceCode/software_tool/tool_for_windows/OpenOCD_V2.0.2/scripts/target/at32f423xx.cfg"
],
"executable": "build/at32f423_template.elf",
"svdFile": "project/misc/AT32F423xx_v2.svd",
"runToEntryPoint": "main"
}
]
}3. .vscode/tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "make",
"args": ["-j4"],
"problemMatcher": []
},
{
"label": "clean",
"type": "shell",
"command": "make",
"args": ["clean"],
"problemMatcher": []
},
{
"label": "download code",
"type": "process",
"command": "D:/AT32F423/SourceCode/software_tool/tool_for_windows/OpenOCD_V2.0.2/bin/openocd.exe",
"args": [
"-f", "D:/AT32F423/SourceCode/software_tool/tool_for_windows/OpenOCD_V2.0.2/scripts/interface/atlink.cfg",
"-f", "D:/AT32F423/SourceCode/software_tool/tool_for_windows/OpenOCD_V2.0.2/scripts/target/at32f423xx.cfg",
"-c", "program build/at32f423_template.hex",
"-c", "exit"
],
"problemMatcher": []
}
]4. .vscode/c_cpp_properties.json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"C:/Users/liujianhua/.eide/tools/gcc_arm/arm-none-eabi/include",
"${workspaceFolder}/project/inc",
"${workspaceFolder}/project/board",
"${workspaceFolder}/libraries/cmsis/cm4/core_support",
"${workspaceFolder}/libraries/cmsis/cm4/device_support",
"${workspaceFolder}/libraries/drivers/inc",
"${workspaceFolder}",
"${workspaceFolder}/libraries/cmsis/cm4/device_support"
],
"defines": [
"_DEBUG", "UNICODE", "_UNICODE",
"AT_START_F423_V1",
"AT32F423VCT7",
"USE_STDPERIPH_DRIVER"
],
"compilerPath": "C:/Users/liujianhua/.eide/tools/gcc_arm/bin/arm-none-eabi-gcc.exe",
"cStandard": "gnu17",
"cppStandard": "gnu++14",
"intelliSenseMode": "gcc-x64"
}
],
"version": 4
}5. 关键注意事项
坑点1:OpenOCD 版本必须使用 `D:\AT32F423\SourceCode\software_tool\tool_for_windows\OpenOCD_V2.0.2\bin\openocd.exe`系统自带的 `C:\OpenOCD\bin\openocd.exe` 缺少 `at32f4xx` Flash 驱动,会报错: Error: flash driver 'at32f4xx' not found
坑点2:调试 vs 下载路径不同调试 (launch.json): 需要加 `serverpath` 指定 OpenOCD 路径下载 (tasks.json): 需要在 `command` 中写完整路径
坑点3:VSCode 默认使用 PATH 中的 openocdCortex-Debug 扩展默认从系统 PATH 查找 openocd必须在 launch.json 中显式指定 `serverpath`
6. 硬件连接
| AT-LINK | AT32F423 ||---------|----------|| SWDIO | PA13 || SWCLK | PA14 || VCC | VCC || GND | GND |
7. 验证方法
1. 编译: Ctrl+Shift+P → "Tasks: Run Task" → "build"2. 下载: Ctrl+Shift+P → "Tasks: Run Task" → "download code"
3. 调试: F5 或点击调试按钮
附:工程模板
我要赚赏金
