Debug STM32 with VScode

Development environment specific, Arduino, Eclipse, VS2013,Em::Blocks etc
vitor_boss
Posts: 63
Joined: Wed Apr 19, 2017 9:50 am

Re: Debug STM32 with VScode

Post by vitor_boss » Thu Dec 21, 2017 2:41 pm

otw wrote:
Wed Dec 06, 2017 10:35 pm
I finally managed to debug my project.
I installed openocd and gcc-arm-none-eabi using Homebrew.
Then I set up parameters inside launch.json file:

Code: Select all

            "miDebuggerPath": "/usr/local/Cellar/gcc-arm-none-eabi/20160928/bin/arm-none-eabi-gdb",
            "debugServerPath": "/usr/local/Cellar/open-ocd/0.10.0/bin/openocd",
            "debugServerArgs": "-f interface/stlink-v2.cfg -f target/stm32f4x.cfg",
Insure to type proper version/revision/date inside mentioned above paths.
Thank you for the information, now VScode is trying to connect but give above error
"Unable to start debugging. Debug server process failed to initialize."

My board is Black 407VE https://danieleff.github.io/STM32GENERI ... CK_F407VE/
I'm using STM32GENERIC core but with Roger's don't work either.

User avatar
BennehBoy
Posts: 501
Joined: Thu Jan 05, 2017 8:21 pm
Location: Yorkshire
Contact:

Re: Debug STM32 with VScode

Post by BennehBoy » Thu Dec 21, 2017 3:52 pm

Ooh, this looks like it's going to replace notepad++
-------------------------------------
https://github.com/BennehBoy

User avatar
BennehBoy
Posts: 501
Joined: Thu Jan 05, 2017 8:21 pm
Location: Yorkshire
Contact:

Re: Debug STM32 with VScode

Post by BennehBoy » Sun Jan 28, 2018 2:33 pm

To get the most from VSCode you'll probably want to configure intellisense so that function refs from libraries and stock includes can be looked up/peeked.

All of this is predicated upon having the c/cpp extension and the MS Arduino extension installed.

Here's what I did on Windows to make this work for rogers core - the intellisense settings are set per project in c_cpp_properties.json (I suspect there's a master template that can also be edited however)

First of all switch on the new tag parser in the global settings in vscode:

Click the settings cog bottom left, and choose 'Settings'

In the right hand pane paste this into 'USER SETTINGS'

Code: Select all

{
    "C_Cpp.intelliSenseEngine": "Tag Parser",
}
Now you need to turn on intellisense and set up some paths, here's the instructions from MS:
To enable code completion and navigation, you will need to generate a c_cpp_properties.json file:

Find any green squiggle in a source file (for example, an #include statement) and set the cursor on the line.
Click the lightbulb that appears in the left gutter.
Click Update "browse.path" setting.
browse path light bulb

This will generate a c_cpp_properties.json file that allows you to add additional browse paths to properly enable code navigation and auto-completion. The generated c_cpp_properties.json file has sections for different operating systems, make sure you update the appropriate settings for your current platform.
The generated c_cpp_properties.json lives in the .vscode folder that the above created in your folder, replace the contents with this:

Code: Select all

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${USERPROFILE}\\Documents\\Arduino\\hardware\\Arduino_STM32\\STM32F1\\cores\\maple",
                "${USERPROFILE}\\Documents\\Arduino\\libraries",
                "${USERPROFILE}\\Documents\\Arduino\\hardware\\Arduino_STM32\\STM32F1\\libraries",
                "${USERPROFILE}\\Documents\\Arduino\\hardware\\Arduino_STM32\\STM32F1\\system\\libmaple\\include\\libmaple",
                "${SYSTEMROOT}\\Program Files (x86)\\Arduino\\hardware\\tools\\avr\\avr\\include",
                "${workspaceRoot}"
            ],
            "browse": {
                "limitSymbolsToIncludedHeaders": false,
                "path": [
                    "${USERPROFILE}\\Documents\\Arduino\\hardware\\Arduino_STM32\\STM32F1\\cores\\maple",
                    "${USERPROFILE}\\Documents\\Arduino\\libraries",
                    "${USERPROFILE}\\Documents\\Arduino\\hardware\\Arduino_STM32\\STM32F1\\libraries",
                    "${USERPROFILE}\\Documents\\Arduino\\hardware\\Arduino_STM32\\STM32F1\\system\\libmaple\\include\\libmaple",
                    "${SYSTEMROOT}\\Program Files (x86)\\Arduino\\hardware\\tools\\avr\\avr\\include",
                    "${workspaceRoot}"
                ]
            },
            "intelliSenseMode": "msvc-x64"
        }
    ],
    "version": 3
}
Happy coding, no 'problems' should now show in your project - if any do because I've missed some include paths, just add them into the above file. For other cores you'll need to use the most relevant paths.
-------------------------------------
https://github.com/BennehBoy

User avatar
BennehBoy
Posts: 501
Joined: Thu Jan 05, 2017 8:21 pm
Location: Yorkshire
Contact:

Re: Debug STM32 with VScode

Post by BennehBoy » Sun Jan 28, 2018 4:02 pm

Also...

The original instructions are wrong, they state to install the SAMD M3 support, openocd comes with the M0+ support.

On windows the Arduino15 folder lives here:

%USERPROFILE%\AppData\Local\Arduino15
-------------------------------------
https://github.com/BennehBoy

User avatar
BennehBoy
Posts: 501
Joined: Thu Jan 05, 2017 8:21 pm
Location: Yorkshire
Contact:

Re: Debug STM32 with VScode

Post by BennehBoy » Sun Jan 28, 2018 5:07 pm

So this has turned out to be a huge exercise in frustration, looks like due to the board options Maple Mini isn't supported for debugging (no st-link upload method?).

Compilation is tediously slow via vscode, no idea why. I have a 16 core cpu and it's doing literally 'nothing' whilst the build runs.

I really like the editor and context sensitivity, but this right now may not be practicable :(

EDIT - fixed compile times by disabling Windows Real Time protection. Would still like to get debugging working though.
-------------------------------------
https://github.com/BennehBoy

User avatar
Rick Kimball
Posts: 1077
Joined: Tue Apr 28, 2015 1:26 am
Location: Eastern NC, US
Contact:

Re: Debug STM32 with VScode

Post by Rick Kimball » Sun Jan 28, 2018 7:00 pm

BennehBoy wrote:
Sun Jan 28, 2018 5:07 pm
So this has turned out to be a huge exercise in frustration, looks like due to the board options Maple Mini isn't supported for debugging (no st-link upload method?).
You might check out the entries I added to the boards.txt

https://gist.github.com/RickKimball/71a ... 72ecf4e095
-rick

User avatar
RogerClark
Posts: 7683
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Debug STM32 with VScode

Post by RogerClark » Sun Jan 28, 2018 8:27 pm

The reason the Maple mini does not have the STLink upload option is that those pins are not labelled as SWD on the Maple mini, and people are using them for GPIO, hence the Maple mini settings turn off the SWD function of the SWD pins so they work as GPIO.

To use STLink on the Maple mini you would also need to change the setting in boards.txt that disables the STLink pins, and initially use Connect Under Reset to get STLink to connect, as the setting wont change until you have loaded your next sketch.

I could add STLink as an option, but no one reads the docs and we would constantly be telling people they need to initially use Connect Under Reset to get the ball rolling.

Hence I think this is more trouble than its worth,

Most people who use STLink use the Blue Pill, and I now use the RobotDyn Black Pill in preference to the Maple Mini as it has the correct USB pull-up resistor, and has separate SWD pins and even more important has access to the 5V rail from USB

User avatar
BennehBoy
Posts: 501
Joined: Thu Jan 05, 2017 8:21 pm
Location: Yorkshire
Contact:

Re: Debug STM32 with VScode

Post by BennehBoy » Sun Jan 28, 2018 10:06 pm

Yeah, I figured this Roger - so I bought 10 black pills earlier :D

Rick, I'll have a look at that if it annoys me too much prior to the pill's arriving on the slow boat.
-------------------------------------
https://github.com/BennehBoy

zmemw16
Posts: 1677
Joined: Wed Jul 08, 2015 2:09 pm
Location: St Annes, Lancs,UK

Re: Debug STM32 with VScode

Post by zmemw16 » Sun Jan 28, 2018 10:23 pm

black pcb with RobotDyn painted on or a black pcb ?

on aliexpress i'm seeing £3.50 for the first :( and £1.47 for the latter :)
a link if possible ?

srp

User avatar
BennehBoy
Posts: 501
Joined: Thu Jan 05, 2017 8:21 pm
Location: Yorkshire
Contact:

Re: Debug STM32 with VScode

Post by BennehBoy » Sun Jan 28, 2018 11:06 pm

Oops, slip of the brain, 10 Blue Pills :D
-------------------------------------
https://github.com/BennehBoy

Post Reply