build: 对齐模板工具链与 .vscode,APP 迁移 Bootloader 布局(0x08002000/54K)

工程编译与开发环境(参照 gd32e23x_template_cmake_vscode 模板)
- cmake/arm-none-eabi-gcc.cmake:硬编码工具链路径改为 GD32_GCC_BIN
  环境变量 / -DTOOLCHAIN_DIRECTORY 参数,与模板逐字一致
- .vscode:launch/tasks/settings/extensions 对齐模板,烧录与调试全部
  读取 GD32_GCC_BIN / GD32_OPENOCD_BIN / GD32_OPENOCD_SCRIPTS 环境变量;
  新增 J-Link 调试配置与 flash/reset/erase.jlink 脚本
- CMakeLists.txt:POST_BUILD 增加 Application/Application.hex 生成
  (J-Link 烧录脚本 loadfile 依赖)
- 验证:Debug / Release 编译通过(本机 ARM GCC 15.2.1)

Bootloader 布局适配(与旧版独立镜像不兼容,升级需整片烧录一次)
- LD/gd32e23x_flash.ld:FLASH ORIGIN=0x08002000, LENGTH=54K
- Src/system_gd32e23x.c:VECT_TAB_OFFSET=0x2000——Bootloader 不写
  VTOR,APP 必须自设向量表,否则中断落回 Bootloader 向量表
- 验证:.vectors 链接于 0x08002000,固件 12164B(54KB 上限 22%)

驱动修复
- Src/ldc1612.c:ldc1612_config_single_channel 各步骤 I2C 写入检查
  返回值,失败立即返回错误(原审查项 L3)

文档
- README:重写本地编译/烧录/调试说明,新增"固件布局与 Bootloader"章节
This commit is contained in:
2026-09-26 18:41:29 +08:00
parent 59f6e917fd
commit 89e7191cd5
13 changed files with 446 additions and 217 deletions
+2
View File
@@ -0,0 +1,2 @@
erase
exit
+7 -25
View File
@@ -1,26 +1,8 @@
{
"recommendations": [
"ms-vscode.cmake-tools",
"ms-vscode.cpptools",
"ms-vscode.cpptools-extension-pack",
"ms-vscode.cpptools-themes",
"ms-vscode.vscode-embedded-tools",
"ms-vscode.hexeditor",
"ms-vscode.notepadplusplus-keybindings",
"twxs.cmake",
"xaver.clang-format",
"marus25.cortex-debug",
"cheshirekow.cmake-format",
"mcu-debug.debug-tracker-vscode",
"mcu-debug.memory-view",
"mcu-debug.peripheral-viewer",
"mcu-debug.rtos-views",
"trond-snekvik.gnu-mapfiles",
"zixuanwang.linkerscript",
"gurumukhi.selected-lines-count",
"gruntfuggly.todo-tree",
"vscode-icons-team.vscode-icons",
"jeff-hykin.better-cpp-syntax",
"dan-c-underwood.arm"
]
}
"recommendations": [
"marus25.cortex-debug",
"ms-vscode.cmake-tools",
"twxs.cmake",
"ms-vscode.cpptools"
]
}
+4
View File
@@ -0,0 +1,4 @@
loadfile Application.hex
r
go
exit
+32 -10
View File
@@ -9,20 +9,19 @@
"type": "cortex-debug",
"runToEntryPoint": "main",
"showDevDebugOutput": "none",
"gdbPath": "${workspaceFolder}/Toolchain/xpack-arm-none-eabi-gcc-11.3.1-1.1/bin/arm-none-eabi-gdb.exe",
"gdbPath": "${env:GD32_GCC_BIN}/arm-none-eabi-gdb.exe",
"servertype": "openocd",
"serverpath": "${workspaceFolder}/Toolchain/xpack-openocd-0.11.0-3/bin/openocd.exe",
"serverpath": "${env:GD32_OPENOCD_BIN}/openocd.exe",
"svdFile": "${workspaceFolder}/GD32E230.svd",
"liveWatch": {
"enabled": true,
"samplesPerSecond": 1
},
"configFiles": [
"${workspaceFolder}/Toolchain/xpack-openocd-0.11.0-3/scripts/target/openocd_gdlink_gd32e23x.cfg"
"${env:GD32_OPENOCD_SCRIPTS}/${config:gd32.openocd.targetConfig}"
],
"serverArgs": [
"-s", "${workspaceFolder}/Toolchain/xpack-openocd-0.11.0-3/scripts"
"-s", "${env:GD32_OPENOCD_SCRIPTS}"
],
"env": {
"OPENOCD_SCRIPTS": "${env:GD32_OPENOCD_SCRIPTS}"
},
"searchDir": [
"${workspaceFolder}"
],
@@ -30,7 +29,30 @@
"preRestartCommands": [
"load",
"continue"
],
]
},
{
"cwd": "${workspaceFolder}",
"executable": "${workspaceFolder}/Build/Debug/Application/Application.elf",
"name": "Debug with J-Link",
"request": "launch",
"type": "cortex-debug",
"runToEntryPoint": "main",
"showDevDebugOutput": "none",
"gdbPath": "${env:GD32_GCC_BIN}/arm-none-eabi-gdb.exe",
"servertype": "jlink",
"device": "${config:gd32.jlink.device}",
"interface": "${config:gd32.jlink.interface}",
"svdFile": "${workspaceFolder}/GD32E230.svd",
"liveWatch": {
"enabled": true,
"samplesPerSecond": 1
},
"preLaunchTask": "Build",
"preRestartCommands": [
"load",
"continue"
]
}
]
}
}
+2
View File
@@ -0,0 +1,2 @@
r
exit
+11 -26
View File
@@ -1,30 +1,15 @@
{
"terminal.integrated.tabs.enabled": true,
"terminal.integrated.profiles.windows": {
"Git Bash": {
"path": "C:\\Program Files\\Git\\bin\\bash.exe",
"icon": "terminal-bash"
},
"Git-Bash": {
"path": "D:\\Git\\bin\\bash.exe",
"icon": "terminal-bash"
}
},
"terminal.integrated.defaultProfile.windows": "Git-Bash",
"clang-format.assumeFilename": ".clang-format",
"clang-format.executable": "clang-format",
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools",
"cmake.configureOnOpen": true,
"cmake.buildDirectory": "${workspaceFolder}/Build",
"vcpkg.storageLocation": "C:\\Dev\\Tools\\vcpkg",
"cmake.useCMakePresets": "always",
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools",
"cortex-debug.variableUseNaturalFormat": true,
"gd32.openocd.targetConfig": "target/openocd_gdlink_gd32e23x.cfg",
"gd32.openocd.massEraseCommand": "gd32e23x mass_erase 0",
"gd32.jlink.device": "GD32E230F8",
"gd32.jlink.interface": "SWD",
"gd32.jlink.speed": "4000",
"files.associations": {
"*.h": "c",
"*.c": "c",
"array": "c",
"string": "c",
"string_view": "c",
"ranges": "c",
"span": "c"
},
"cortex-debug.variableUseNaturalFormat": true,
}
"*.c": "c"
}
}
+196 -112
View File
@@ -1,116 +1,6 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "Build and Flash",
"group": {
"kind": "build",
"isDefault": true
},
"dependsOn": [
"Build",
"Flash MCU"
],
"dependsOrder": "sequence",
"icon": {
"id": "insert",
"tooltip": "Build and Flash"
}
},
{
"label": "Flash MCU",
"type": "shell",
"command": "'${workspaceFolder}/Toolchain/xpack-openocd-0.11.0-3/bin/openocd.exe' -s '${workspaceFolder}' -f '${workspaceFolder}/Toolchain/xpack-openocd-0.11.0-3/scripts/target/openocd_gdlink_gd32e23x.cfg' -c 'init; reset halt; flash write_image erase ${command:cmake.launchTargetFilename}; reset; exit'",
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": [],
"options": {
"cwd": "${command:cmake.buildDirectory}/Application",
"environment": {
"CLICOLOR_FORCE": "1",
"OPENOCD_SCRIPTS": ""
}
},
"presentation": {
"clear": true
},
"icon": {
"id": "gather",
"tooltip": "Flash MCU"
}
},
{
"label": "Reset MCU",
"type": "shell",
"command": "'${workspaceFolder}/Toolchain/xpack-openocd-0.11.0-3/bin/openocd.exe' -s '${workspaceFolder}' -f '${workspaceFolder}/Toolchain/xpack-openocd-0.11.0-3/scripts/target/openocd_gdlink_gd32e23x.cfg' -c 'init; reset; exit'",
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": [],
"options": {
"cwd": "${command:cmake.buildDirectory}/Application",
"environment": {
"CLICOLOR_FORCE": "1",
"OPENOCD_SCRIPTS": ""
}
},
"presentation": {
"clear": true
},
"icon": {
"id": "discard",
"tooltip": "Reset MCU"
}
},
{
"label": "Mass Erase MCU",
"type": "shell",
"command": "'${workspaceFolder}/Toolchain/xpack-openocd-0.11.0-3/bin/openocd.exe' -s '${workspaceFolder}' -f '${workspaceFolder}/Toolchain/xpack-openocd-0.11.0-3/scripts/target/openocd_gdlink_gd32e23x.cfg' -c 'init; reset halt; gd32e23x mass_erase 0; exit'",
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": [],
"options": {
"cwd": "${command:cmake.buildDirectory}/Application",
"environment": {
"CLICOLOR_FORCE": "1",
"OPENOCD_SCRIPTS": ""
}
},
"presentation": {
"clear": true
},
"icon": {
"id": "clear-all",
"tooltip": "Erase MCU"
}
},
{
"label": "OpenOCD Server",
"type": "shell",
"command": [
"'${workspaceFolder}/Toolchain/xpack-openocd-0.11.0-3/bin/openocd.exe' -s '${workspaceFolder}' -f '${workspaceFolder}/Toolchain/xpack-openocd-0.11.0-3/scripts/target/openocd_gdlink_gd32e23x.cfg'"
],
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": [],
"options": {
"cwd": "${command:cmake.buildDirectory}/Application",
"environment": {
"CLICOLOR_FORCE": "1",
"OPENOCD_SCRIPTS": ""
}
},
"presentation": {
"clear": true
}
},
{
"label": "Build",
"type": "cmake",
@@ -130,7 +20,8 @@
],
"options": {
"environment": {
"CLICOLOR_FORCE": "1"
"CLICOLOR_FORCE": "1",
"OPENOCD_SCRIPTS": "${env:GD32_OPENOCD_SCRIPTS}"
}
},
"presentation": {
@@ -140,6 +31,199 @@
"id": "code",
"tooltip": "Build"
}
},
{
"label": "Build and Flash",
"dependsOn": [
"Build",
"Flash MCU"
],
"dependsOrder": "sequence",
"group": "build",
"icon": {
"id": "insert",
"tooltip": "Build and Flash"
}
},
{
"label": "Flash MCU",
"type": "process",
"command": "${env:GD32_OPENOCD_BIN}/openocd.exe",
"args": [
"-s", "${env:GD32_OPENOCD_SCRIPTS}",
"-f", "${env:GD32_OPENOCD_SCRIPTS}/${config:gd32.openocd.targetConfig}",
"-c", "init; reset halt; flash write_image erase ${command:cmake.launchTargetFilename}; reset; exit"
],
"group": "build",
"problemMatcher": [],
"options": {
"cwd": "${command:cmake.buildDirectory}/Application",
"environment": {
"OPENOCD_SCRIPTS": "${env:GD32_OPENOCD_SCRIPTS}"
}
},
"presentation": {
"clear": true
},
"icon": {
"id": "gather",
"tooltip": "Flash MCU"
}
},
{
"label": "Reset MCU",
"type": "process",
"command": "${env:GD32_OPENOCD_BIN}/openocd.exe",
"args": [
"-s", "${env:GD32_OPENOCD_SCRIPTS}",
"-f", "${env:GD32_OPENOCD_SCRIPTS}/${config:gd32.openocd.targetConfig}",
"-c", "init; reset; exit"
],
"group": "build",
"problemMatcher": [],
"options": {
"cwd": "${command:cmake.buildDirectory}/Application",
"environment": {
"OPENOCD_SCRIPTS": "${env:GD32_OPENOCD_SCRIPTS}"
}
},
"presentation": {
"clear": true
},
"icon": {
"id": "discard",
"tooltip": "Reset MCU"
}
},
{
"label": "Mass Erase MCU",
"type": "process",
"command": "${env:GD32_OPENOCD_BIN}/openocd.exe",
"args": [
"-s", "${env:GD32_OPENOCD_SCRIPTS}",
"-f", "${env:GD32_OPENOCD_SCRIPTS}/${config:gd32.openocd.targetConfig}",
"-c", "init; reset halt; ${config:gd32.openocd.massEraseCommand}; exit"
],
"group": "build",
"problemMatcher": [],
"options": {
"cwd": "${command:cmake.buildDirectory}/Application",
"environment": {
"OPENOCD_SCRIPTS": "${env:GD32_OPENOCD_SCRIPTS}"
}
},
"presentation": {
"clear": true
},
"icon": {
"id": "clear-all",
"tooltip": "Erase MCU"
}
},
{
"label": "OpenOCD Server",
"type": "process",
"command": "${env:GD32_OPENOCD_BIN}/openocd.exe",
"args": [
"-s", "${env:GD32_OPENOCD_SCRIPTS}",
"-f", "${env:GD32_OPENOCD_SCRIPTS}/${config:gd32.openocd.targetConfig}"
],
"group": "build",
"problemMatcher": [],
"options": {
"cwd": "${command:cmake.buildDirectory}/Application",
"environment": {
"OPENOCD_SCRIPTS": "${env:GD32_OPENOCD_SCRIPTS}"
}
},
"presentation": {
"clear": true
}
},
{
"label": "Build and Flash (Jlink)",
"dependsOn": [
"Build",
"Flash MCU (Jlink)"
],
"dependsOrder": "sequence",
"group": "build",
"icon": {
"id": "insert",
"tooltip": "Build and Flash (Jlink)"
}
},
{
"label": "Flash MCU (Jlink)",
"type": "process",
"command": "JLink.exe",
"args": [
"-device", "${config:gd32.jlink.device}",
"-if", "${config:gd32.jlink.interface}",
"-speed", "${config:gd32.jlink.speed}",
"-autoconnect", "1",
"-CommanderScript", "${workspaceFolder}/.vscode/flash.jlink"
],
"group": "build",
"problemMatcher": [],
"options": {
"cwd": "${command:cmake.buildDirectory}/Application"
},
"presentation": {
"clear": true
},
"icon": {
"id": "gather",
"tooltip": "Flash MCU (Jlink)"
}
},
{
"label": "Reset MCU (Jlink)",
"type": "process",
"command": "JLink.exe",
"args": [
"-device", "${config:gd32.jlink.device}",
"-if", "${config:gd32.jlink.interface}",
"-speed", "${config:gd32.jlink.speed}",
"-autoconnect", "1",
"-CommanderScript", "${workspaceFolder}/.vscode/reset.jlink"
],
"group": "build",
"problemMatcher": [],
"options": {
"cwd": "${workspaceFolder}"
},
"presentation": {
"clear": true
},
"icon": {
"id": "discard",
"tooltip": "Reset MCU (Jlink)"
}
},
{
"label": "Mass Erase MCU (Jlink)",
"type": "process",
"command": "JLink.exe",
"args": [
"-device", "${config:gd32.jlink.device}",
"-if", "${config:gd32.jlink.interface}",
"-speed", "${config:gd32.jlink.speed}",
"-autoconnect", "1",
"-CommanderScript", "${workspaceFolder}/.vscode/erase.jlink"
],
"group": "build",
"problemMatcher": [],
"options": {
"cwd": "${workspaceFolder}"
},
"presentation": {
"clear": true
},
"icon": {
"id": "clear-all",
"tooltip": "Erase MCU (Jlink)"
}
}
]
}
}