Debugging custom STM32 board


My custom board based on STM32L063 Cortex-M0+ halts at first instruction @Reset_Handler when starting debug session in VSCode. I would like it to place a preliminary breakpoint and halt at main, for example. Where to look for .gdbinit or similar pre-debug functionality?

External STM32L0Discovery as STLinkv2.1 for SWD is used for debug, if that is of any relevance.


env_default = my_prototype
;env_default = nucleo_l053r8

# common defaults
platform = ststm32
framework = stm32cube
build_flags =
#  ...

platform = ${env:default.platform}
framework = ${env:default.framework}
board = my_prototype
build_flags = ${env:debug.build_flags} -DSTM32L0XX -DF_CPU=32000000


  "build": {
    "cpu": "cortex-m0plus",
    "extra_flags": "-DSTM32L063xx",
    "f_cpu": "32000000L",
    "mcu": "stm32l063c8t6"
  "frameworks": [
  "name": "My prototype",
  "upload": {
    "maximum_ram_size": 8192,
    "maximum_size": 65536,
    "protocol": "stlink"
  "debug": {
    "tools": {
      "stlink-v2-1": {
        "server": {
          "package": "tool-openocd",
          "executable": "bin/openocd",
          "arguments": [
            "-f", "scripts/interface/stlink-v2-1.cfg",
            "-c", "transport select hla_swd",
            "-f", "scripts/target/stm32l0.cfg"
        "onboard": false
  "url": "http://localhost/",
  "vendor": "myself"

I know it is a tangential question, I apologize for digressing.
If you dont mind my asking, how do you work with stm32cube and platformio?
Your workflow, from creating a project in vscode and starting a project in stm32cube to importing and/or modifying the necessary file to get it to compile in platformio. The toolchain selection in stm32cube and any changes you might make to the stm32cube output files in platformio.

Thank you and again I apologize for hijacking your query.

PS: to answer your question,
You can specify the arguments, for example

debug_init_cmds =
  target remote $DEBUG_PORT
  file "$PROG_PATH"
  load "$PROG_PATH"
  monitor init
  monitor reset halt

to break at the point you would like the program to halt.

Or alternatively, you can pass a .gdbinit file by using
debug_extra_cmds =
break main.cpp:13
break foo.cpp:100
source .gdbinit
Either works for your purpose.

I hope this helps. :slight_smile:

Please have a look here for complete list of options for customizing

Hi Krishna,

Regarding your question: I’m using stm32cube library/framework in pio, and debugging in VSCode. There is really nothing special. Everything needed is included in platformio.ini above.

EDIT: clarification

Thank you for your suggestion.

The STM32L0 Discovery, Nucleo and Eval boards I use in the very same projects jump directly to main(). This is not the case for my custom board.

In all cases, SWD debug port is used. My custom board is hooked onto L053 Discovery STLink SWD header, therefore I would exclude any influence of the SWD interface.

To rephrase my question, I’m interested into finding out: why is my custom board halting at Reset_handler instead of setting up a breakpoint and resuming to main?



@bitsmith - I think this might be related to how you have configured OpenOCD, rather than being a specific PlatformIO issue.

The discovery L0 board has a specific OpenOCD boards config file. I see that you have duplicated most of its functionality, but there are a few other lines which aren’t included.

What happens if you just set "arguments": ["-f", "scripts/board/stm32l0discovery.cfg"] in your json file?

1 Like

Have you resolved this issue?

@valeros do you have any ideas why debug stops on Reset_Handler() instead of main()? We add tb main by default.

Hi Ivan,

Somehow my answer got lost. Sorry for delay.

EDIT: The issue is obsolete now as the board development has progressed to next revision.