I am getting the following error (debugger output) when i try to do "ST_LINK: attach to application" in vscode. I have no idea what is going on. Any help is greatly appreciated.
I use WSL ubuntu 22.04.
My version of vscode is1.107.0 (user setup).
Cortex-Debug: VSCode debugger extension version 1.12.1 git(652d042). Usage info: https://github.com/Marus/cortex-debug#usage
"configuration": {
"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",
"__configurationTarget": 6,
"gdbServerConsolePort": 55878,
"pvtAvoidPorts": [],
"chainedConfigurations": {
"enabled": false
},
"debuggerArgs": [],
"swoConfig": {
"enabled": false,
"decoders": [],
"cpuFrequency": 0,
"swoFrequency": 0,
"source": "probe"
},
"rttConfig": {
"enabled": false,
"decoders": []
},
"graphConfig": [],
"preLaunchCommands": [],
"postLaunchCommands": [],
"preAttachCommands": [],
"postAttachCommands": [],
"preRestartCommands": [],
"postRestartCommands": [],
"preResetCommands": [],
"postResetCommands": [],
"toolchainPath": "/opt/gcc-arm-none-eabi/bin",
"toolchainPrefix": "arm-none-eabi",
"extensionPath": "/home/federico/.vscode-server/extensions/marus25.cortex-debug-1.12.1",
"registerUseNaturalFormat": true,
"variableUseNaturalFormat": true,
"pvtVersion": "1.12.1",
"__sessionId": "1b5c4f93-51d1-4784-b53d-5821e9169153",
"pvtShowDevDebugOutput": "raw"
}
Reading symbols from /opt/gcc-arm-none-eabi/bin/arm-none-eabi-objdump --syms -C -h -w /home/federico/bare-metal-series/app/firmware.elf
Reading symbols from /opt/gcc-arm-none-eabi/bin/arm-none-eabi-nm --defined-only -S -l -C -p /home/federico/bare-metal-series/app/firmware.elf
Launching GDB: /opt/gcc-arm-none-eabi/bin/arm-none-eabi-gdb -q --interpreter=mi2
1-gdb-version
Launching gdb-server: st-util -p 50000 --no-reset
Please check TERMINAL tab (gdb-server) for output from st-util
Finished reading symbols from objdump: Time: 37 ms
Finished reading symbols from nm: Time: 52 ms
-> =thread-group-added,id="i1"
-> ~"GNU gdb (Arm GNU Toolchain 14.3.Rel1 (Build arm-14.174)) 15.2.90.20241229-git\n"
-> ~"Copyright (C) 2024 Free Software Foundation, Inc.\n"
-> ~"License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\nThis is free software: you are free to change and redistribute it.\nThere is NO WARRANTY, to the extent permitted by law."
-> ~"\nType \"show copying\" and \"show warranty\" for details.\n"
-> ~"This GDB was configured as \"--host=x86_64-pc-linux-gnu --target=arm-none-eabi\".\n"
-> ~"Type \"show configuration\" for configuration details.\n"
-> ~"For bug reporting instructions, please see:\n"
-> ~"<https://bugs.linaro.org/>.\n"
-> ~"Find the GDB manual and other documentation resources online at:\n <"
-> ~"http://www.gnu.org/software/gdb/documentation/>.\n\n"
-> ~"For help, type \"help\".\n"
-> ~"Type \"apropos word\" to search for commands related to \"word\".\n"
-> 1^done
2-gdb-set mi-async on
-> 2^done
3-interpreter-exec console "set print demangle on"
-> 3^done
4-interpreter-exec console "set print asm-demangle on"
-> =cmd-param-changed,param="print asm-demangle",value="on"
-> 4^done
5-enable-pretty-printing
-> 5^done
6-interpreter-exec console "source /home/federico/.vscode-server/extensions/marus25.cortex-debug-1.12.1/support/gdbsupport.init"
-> 6^done
7-interpreter-exec console "source /home/federico/.vscode-server/extensions/marus25.cortex-debug-1.12.1/support/gdb-swo.init"
-> =cmd-param-changed,param="language",value="c"
-> =cmd-param-changed,param="language",value="auto"
-> 7^done
8-interpreter-exec console "set output-radix 0xa"
-> ~"Output radix now set to decimal 10, hex a, octal 12.\n"
Output radix now set to decimal 10, hex a, octal 12.
-> 8^done
9-interpreter-exec console "set input-radix 0xa"
-> ~"Input radix now set to decimal 10, hex a, octal 12.\n"
Input radix now set to decimal 10, hex a, octal 12.
-> 9^done
10-file-exec-and-symbols "/home/federico/bare-metal-series/app/firmware.elf"
-> 10^done
11-target-select extended-remote localhost:50000
-> =thread-group-started,id="i1",pid="42000"
-> =thread-created,id="1",group-id="i1"
-> ~"0x08000ac2 in ?? ()\n"
0x08000ac2 in ?? ()
-> *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
-> 11^connected
12-interpreter-exec console "monitor halt"
-> 12^done
13-thread-list-ids
-> 13^done,thread-ids={thread-id="1"},current-thread-id="1",number-of-threads="1"
14-thread-info 1
-> 14^done,threads=[{id="1",target-id="Thread <main>",frame={level="0",addr="0x08000ac2",func="??",args=[],arch="armv7e-m"},state="stopped"}]
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"}]
16-stack-list-frames --thread 1 0 19
-> 16^done,stack=[frame={level="0",addr="0x08000ac2",func="??",arch="armv7e-m"},frame={level="1",addr="0x08000abe",func="??",arch="armv7e-m"}]
The code im trying to run is this one. It is about having a LED blink.
#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;
}
Launch.json file is the following:
{
"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"
}
]
}
When i type st-util the board is recognized. Vscode recognizes the board.
Not sure what else to say. The toolchain seems right to me.
The file structure of my project is:
bare-metal-series:
app:
src:
firmware.c
firmware.elf
firmware.map
firmware.bin
.vscode:
launch.json
libopencm3:
include:
libopencm3:
stm32:
rcc.h
gpio.h