我正在研究 STM32F407 设备,开发引导加载程序和应用程序
环境是Visual Studio Code,并使用Cortex-Debug扩展进行调试。
地址 0x0800 0000 处的引导加载程序正在启动重新定位到 FLASH 中 0x0802 0000 处的应用程序。因此应用程序链接器文件指定了新的起始地址@0x0802 000,而system_stm32f4xx.c文件定义了VECT_TAB_OFFSET = 0x00020000
在没有调试器的情况下运行时,引导加载程序启动应用程序,一切正常。但在调试模式下,永远不会到达 main() 并且无法进行调试。但 Cortex 调试不会崩溃。我可以暂停/播放它,但它没有显示任何内容。看起来“迷失了”
因此,在运行模式下,一切都按预期进行。引导调用应用程序并执行应用程序。
如果我使用 VECT_TAB_OFFSET == 0 重新定位应用程序 @0x0800 0000,我就可以使用 Cortex 调试来调试代码。但是使用 VECT_TAB_OFFSET == 0x0002 0000 调试 @0x0802 0000 是不可能的。 Main() 从未被调用。我检查了内存,.bin 已正确加载到 0x0802 0000
这是我的 launch.json 文件:
{
"version": "0.2.0",
"configurations": [
{
"name": "Cortex Debug",
"cwd": "${workspaceFolder}",
"executable": "./build/Debug/APP.bin",
"request": "launch",
"type": "cortex-debug",
"servertype": "openocd",
"device": "STM32F407",
"configFiles": [
"interface/stlink.cfg",
"target/stm32f4x.cfg"
],
"symbolFiles": [
"${workspaceFolder}/build/Debug/APP.elf"
],
"loadFiles": [
"${workspaceFolder}/build/Debug/APP.hex"
],
"gdbPath": "arm-none-eabi-gdb.exe",
"interface": "swd"
}
]
}
是否有一个参数表明调试器工作在0x0802 0000?我认为加载 .hex 文件就足够了,也许我错了
我也遇到了同样的问题。将
overrideLaunchCommands
添加到 configurations
文件中的 launch.json
节点后,我能够成功调试。
"configurations": [
{
"showDevDebugOutput": "parsed",
"cwd": "${workspaceRoot}",
"executable": "${workspaceRoot}/build/app.elf",
"name": "Debug STM32",
"request": "launch",
"type": "cortex-debug",
"servertype": "openocd",
"preLaunchTask": "CMake: build",
"device": "stm32f407",
"configFiles": [
"openocd.cfg"
],
"overrideResetCommands": [],
"overrideLaunchCommands": [
"cd ${workspaceRoot}/build",
"file app.elf",
"target extended-remote localhost:50000",
"monitor reset halt",
"load",
"set output-radix 16"
],
"svdFile": "${workspaceRoot}/STM32F407.svd"
}
]
我也面临着同样的问题。 答案是使用上面提到的“overrideLaunchCommands”,但有一些小的注释。 您可以检查加载文件名偏移量。
假设您的 *.ld 文件如下所示
/* Memories definition */
MEMORY
{
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 256K
FLASH (rx) : ORIGIN = 0x08010000, LENGTH = 128K
}
所以需要指定加载偏移量为0x10000。
"overrideLaunchCommands": [
"load ./build/debug/_bootloader_test_.elf 0x10000"
],