You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

WSL Ubuntu环境下VSCode Cortex-Debug调试STM32F401RE时Attach失败的问题求助

WSL Ubuntu环境下VSCode Cortex-Debug调试STM32F401RE时Attach失败的问题求助

各位好,我现在在WSL2 Ubuntu 22.04环境下用VSCode + Cortex-Debug调试STM32F401RE的LED闪烁程序,遇到了Attach失败的问题,具体情况如下:

问题现象

我选择「ST-Link: Attach to Application」配置时,调试器能连接到st-util,但最终停在一个未知的地址0x08000ac2,栈帧里的函数都是??,设置了runToEntryPoint": "main"但程序并没有自动跳转到main函数执行。Debugger输出的关键片段如下:

-> *stopped,frame={addr="0x08000ac2",func="??",args=[],arch="armv7e-m"},thread-id="1",stopped-threads="all"
mi2.status = stopped
Program stopped, probably due to a reset and/or halt issued by debugger
...
15-stack-list-frames --thread 1 0 19
-> 15^done,stack=[frame={level="0",addr="0x08000ac2",func="??",arch="armv7e-m"},frame={level="1",addr="0x08000abe",func="??",arch="armv7e-m"}]

我的环境与配置

  • 系统:WSL2 Ubuntu 22.04
  • VSCode版本:1.107.0(User Setup)
  • Cortex-Debug版本:1.12.1
  • 工具链:Arm GNU Toolchain 14.3.Rel1,路径/opt/gcc-arm-none-eabi/bin
  • 调试器:st-util(能单独识别STM32F401RE板子)

Attach配置详情

{
    "name": "ST-Link: Attach to Application",
    "cwd": "/home/federico/bare-metal-series/app",
    "executable": "/home/federico/bare-metal-series/app/firmware.elf",
    "servertype": "stutil",
    "request": "attach",
    "type": "cortex-debug",
    "device": "STM32F401RE",
    "runToEntryPoint": "main",
    "interface": "swd",
    "showDevDebugOutput": "raw",
    "armToolchainPath": "/opt/gcc-arm-none-eabi/bin"
}

完整launch.json配置

{
  "configurations": [
    {
      "name": "ST-Link: Debug Application",
      "cwd": "${workspaceFolder}/app",
      "executable": "./firmware.elf",
      "servertype": "stutil",
      "request": "launch",
      "type": "cortex-debug",
      "device": "STM32F401RE",
      "runToEntryPoint": "main",
      "showDevDebugOutput": "raw",
      "interface": "swd",
      "preLaunchTask": "build_debug",
      "armToolchainPath": "/opt/gcc-arm-none-eabi/bin"
    },
    {
      "name": "ST-Link: Attach to Application",
      "cwd": "${workspaceFolder}/app",
      "executable": "./firmware.elf",
      "servertype": "stutil",           
      "request": "attach",
      "type": "cortex-debug",
      "device": "STM32F401RE",
      "runToEntryPoint": "main",
      "interface": "swd",
      "showDevDebugOutput": "raw",
      "armToolchainPath": "/opt/gcc-arm-none-eabi/bin"
    }
  ]
}

项目结构

bare-metal-series:
├── app:
│   ├── src:
│   │   └── firmware.c
│   ├── firmware.elf
│   ├── firmware.map
│   └── firmware.bin
├── .vscode:
│   └── launch.json
└── libopencm3:
    └── include:
        └── libopencm3:
            └── stm32:
                ├── rcc.h
                └── gpio.h

源代码(firmware.c)

#include <libopencm3/stm32/rcc.h>
#include <libopencm3/stm32/gpio.h>
#define LED_PORT (GPIOA)
#define LED_PIN (GPIO5)

static void rcc_setup(void) {
rcc_clock_setup_pll(&rcc_hsi_configs[RCC_CLOCK_3V3_84MHZ]);
}

static void gpio_setup(void) {
  rcc_periph_clock_enable(RCC_GPIOA);
gpio_mode_setup(LED_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, LED_PIN);
}

static void delay_cycles(uint32_t cycles){
  for(uint32_t i=0; i<cycles; i++){
    __asm__("nop");
  }
}

int main(void) {
rcc_setup();
gpio_setup();

  while (1) {
    gpio_toggle(LED_PORT, LED_PIN);
    delay_cycles(84000000/4);
  
  }

  // Never return
  return 0;
}

已排查的内容

  1. 单独运行st-util能正常识别STM32F401RE板子,无报错
  2. VSCode能正确识别ST-Link设备
  3. 工具链路径配置正确,编译过程无报错,firmware.elf文件生成正常
  4. WSL已经通过usbipd-win转发了ST-Link的USB设备,能被Ubuntu识别

我现在不确定问题出在符号加载、stutil配置还是WSL的某个设置上,有没有朋友遇到过类似问题,或者能给我一些排查方向?谢谢大家!

火山引擎 最新活动