Skip to content

Instantly share code, notes, and snippets.

@eloraiby
Last active September 4, 2020 01:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eloraiby/25d3ecbaf664aea29924a68cb3cab26e to your computer and use it in GitHub Desktop.
Save eloraiby/25d3ecbaf664aea29924a68cb3cab26e to your computer and use it in GitHub Desktop.
Setup Stm32f103 blue pill under vscode

stm32f103 Blue pill C/C++ programming

In STM32CubeMX, enable debugging: Pinout & Configuration > System Core > SYS > Mode > Debug: Enable.

Then under Project Manager > Toolchain/IDE: Makefile

Inside VSCode, add a configuration in launch.json:

        {
            "name": "GDB",
            "type": "gdb",
            "request": "launch",
            "cwd": "${workspaceRoot}",
            "target": "./build/oled_test.elf",
            "gdbpath" : "/usr/bin/gdb-multiarch",
            "autorun": [
                "target remote localhost:3333",
                "monitor reset init",
                "monitor sleep 100",
                "monitor halt",
                "monitor sleep 100",
                "load",
                "break main",
                "continue",
                ]
        }

Flash your program:

st-flash write build/oled_test.bin 0x8000000

or use STM32 official flash programmer (you might need to have the exact paths to make it work on linux):

~/STMicroelectronics/STM32Cube/STM32CubeProgrammer/bin/STM32_Programmer.sh -c port=SWD -d build/oled_test.elf

Then run:

openocd -f interface/stlink-v2.cfg -f target/stm32f1x.cfg

Now set your breakpoints and hit F5 after choosing GDB as debug configuration

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment