[Linux + STM32] lighting LED with cubemx + vscode under Linux (STM32)

Time:2021-5-13

Environment: Ubuntu 18.04

In addition to the debugging part, the article is a little long. After removing it, I wrote an article only about the construction and download of the configuration environment.

step

  • Install vscode, stm32cubemx and stlink driver (if stlink is used). The reference link is as follows:

    VSCode

    CubeMX

    STLink

  • Then, arm none EABI GCC is installed. Here, the author uses the method of adding PPA to install.

    sudo add-apt-repository ppa:team-gcc-arm-embedded/ppa
    sudo apt-get update
    sudo apt-get install gcc-arm-embedded

The installation information shows that the installed version is 7-2018q2-1 ~ bionic1.

  • Then, according to the general method, use cube to create a new lighting project (suppose we click the light on pc13), set HSE, set debug, set GPIO, configure clock tree… Finally, select toolchain as “makefile” on the project manager page, and generate the code. When using a device for the first time, you need to install the corresponding library. After confirmation, wait for a moment.
  • typingcodeOpen vscode, install plug-in “C / C + +”, and then use vscode to open the project directory generated by cube (for example, if your project is called “F4”)_ If it’s “blink”, I’ll choose this when I open folder.
  • In the vscode interface, press F1, enter edit configurations and select Edit configurations (JSON), then a C will be opened_ cpp_ The default content of the properties.json file is as follows:

    {
        "configurations": [
            {
                "name": "Linux",
                "includePath": [
                    "${workspaceFolder}/**"
                ],
                "defines": [],
                "compilerPath": "/usr/bin/gcc",
                "cStandard": "gnu11",
                "cppStandard": "gnu++14",
                "intelliSenseMode": "linux-gcc-x64"
            }
        ],
        "version": 4
    }

Some items need to be changed. Open the makefile file in the project directory, and_ The contents of includes are moved to the inlcudepath, and C_ The content of defs is moved to definitions. Note that you may need to make some modifications. For example, the original content may be in the format of – ICORE / Inc. after deleting “- I”, please refer to the format below.

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**",
                "Core/Inc",
                "Drivers/STM32F4xx_HAL_Driver/Inc",
                "Drivers/STM32F4xx_HAL_Driver/Inc/Legacy",
                "Drivers/CMSIS/Device/ST/STM32F4xx/Include",
                "Drivers/CMSIS/Include"
            ],
            "defines": [
                "USE_HAL_DRIVER",
                "STM32F401xC"
            ],
            "compilerPath": "/usr/bin/arm-none-eabi-gcc",
            "cStandard": "gnu11",
            "cppStandard": "gnu++14",
            "intelliSenseMode": "linux-gcc-x64"
        }
    ],
    "version": 4
}
  • Then, open core / SRC / main. C and skillfully type out the following lighting Code: (and save)

    HAL_GPIO_TogglePin(GPIOC,GPIO_PIN_13);
    HAL_Delay(500);
  • In vscode, open terminal (the shortcut key to open the default terminal is Ctrl + \ ‘), typemakeAfter compiling, there will be a build folder with generated. Bin. Elf and other files.
  • Plug in the stlink, connect the cable and typest-info --probeSee if the debugger and the chip to which it is connected can be detected. If you can, continue to type the following instructions:

    St flash write. / build / your target file. Bin 0x0800000
  • After burning, reset the chip and you can see the light flashing.
  • I wish you a smooth development!