Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. In the IDE, create a new project. You can do this by clicking File->new->STM32 project.

  2. This will open up the target selector.

    Image RemovedImage Added

    In the part number field, enter the part number of the relevant microcontroller (STM32F765ZG for the autopilot chip and STM32F030RC for the safety chip). Choose that part and click next.

  3. Now, give the project a name, select C++, empty, and click finish.

  4. Now, click on the green bug in the task bar

  5. This will pull up the debug configuration menu. You have to point the debugger to the elf file we built with our build system rather than the garbage that STM defaults to. So browse for the project. Our elf files are located in ZeroPilot-SW\Autopilot\build and are produced after a successful build.

    Image RemovedImage Added
  6. Sweet, now just make sure your debugger is plugged in, connected to the board, and everything is powered on. Hit apply then OK to begin the debug session.

  7. It is possible that upon launching the debug executable, ST has a hard time finding the source files. If that’s the case, just open the corresponding source files in the IDE (File->Open File)

  8. Awesome, your’e good to go. If your’e new to debugging in an eclipse based IDE, I’d recommend looking for some tutorials on YouTube to get familiar with doing that.

The VSCode Way

For those who are not interested in downloading and installing cubeide, you should be able to make vscode handle intellisense, build, flash, and debug processes with some basic configuration.

This process makes use of the stlink suite. They are a set of command line tools that can be used to work with the st-link device. st-flash will flash a binary image onto the board, and st-util will start a gdb (GNU Debugger) server on the board. In order to successfully use both of these tools you will need to follow the directions on the appropriate project websites to install stlink and arm-none-eabi-gdb on your device.

You can check that the stlink package is installed by connecting a dev board with an stlink and running st-info --probe. From here you could simply flash the binary files you have already built per instructions from Firmware Development Environment Setup. If you want to try it, the command is st-flash write build/Safety.bin 0x08000000.

If you know how to use gdb, or are interested in learning gdb on the command line, go ahead and run st-util. You should receive a message along the lines of “Listening at *:4242...”. If you open a new terminal, and run arm-none-eabi-gdb ./build/Safety.elf, then type target extend localhost:4242 (or whatever port st-util has opened) you will be in a gdb session for the software you just flashed to the board.

Most sane people dont use debuggers on the command line, so lets put setup vscode to make use of these two tools we have set up. I personally have my workspace set up as a multi-root workspace for safety and autopilot.

Zeropilot.code-workspace:

Code Block
languagejson
{
	"folders": [
		{
			"path": "Safety"
		},
		{
			"path": "Autopilot"
		}
	],
}

Within each of Safety and Autopilot I have configured some tasks to flash and build the project.

Safety/tasks.json

Code Block
languagejson
{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Build Safety",
            "type": "shell",
            "command": "bash ./Tools/build.bash",
            "options": {
                "cwd": "${workspaceRoot}",
            },
            "group": {
                "kind": "build",
                "isDefault": true
            }
        },
        {
            "label": "Flash Safety",
            "type": "shell",
            "command": "st-flash write build/Safety.bin 0x08000000",
            "options": {
                "cwd": "${workspaceRoot}",
            },
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "dependsOn": [
                "Build Safety",
            ]
        },
    ]
}

To unlock the full power of VSCode from here, you will need to install some extensions:

Below are my config files for the safety chip. They are similar for autopilot, but not identical. Make sure that you have the correct device configured.

Safety/c_cpp_properties.json

Code Block
{
    "configurations": [
        {
            "name": "Safety",
            "compilerPath": "/usr/bin/arm-none-eabi-g++",
            "cStandard": "c17",
            "cppStandard": "c++14",
            "intelliSenseMode": "linux-gcc-arm",
            "compileCommands": "${workspaceFolder}/build/compile_commands.json"
        }
    ],
    "version": 4
}

Safety/launch.json

Code Block
languagejson
{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "type": "cortex-debug",
            "request": "launch",
            "servertype": "stutil",
            "cwd": "${workspaceRoot}",
            "executable": "./build/Safety.elf",
            "name": "Debug Safety",
            "device": "STM32F030RC",
            "v1": false,
        }
    ]
}

With any luck, you should now have configured vscode to build, flash, and debug your code for the dev board. By default, Ctrl+Shift+B will run the default build task and F5 will open a debugger session.

Legacy way

This stuff is from before my time. If you’d like to try, have your hand at it.

...

  1. Using the official flashing software (Windows ONLY): To setup ST-link, visit ST-Link Drivers. Download the ST-link driver and ST-link utility. Once you download these, you should be able to connect to the board. You can verify this by opening the ST-Link utility and clicking "Connect" with the board powered and plugged into the programming port.

  2. Using Open-OCD - this is an open source project that allows for debugging and flashing of MANY MCU and programmer combos. You can also integrate it with CLion to get debugging through the IDE


You don't need both! Either Open-OCD or ST-Link will do

Installation (Windows)

  1. Install GNU Windows build tools

    - so you have make on your system

  2. Install the rest of the tools above, following the web page instructions


When installing CMake, make sure you tick the checkbox that asks if you wanna add it to you PATH

Installation (macOS)

  1. Open up a terminal window

  2. Install homebrew

  3. Run.    brew install git arm-gcc-bin cmake open-ocd

  4. If you're installing Clion, installing CMake is optional in the above command ^^. Also make sure to install version 2018.3, and not the latest version!

...