当前位置:   article > 正文

VSCode搭建STM32编译环境_vscode编译stm32

vscode编译stm32

VSCode 插件下载

必须的像是C++,makefile,ARM都需要下载下来
以下仅供参考:
在这里插入图片描述

STM32MX 工程配置

需要在STM32MX里面生成一个工程文件,具体在generate code时需要特殊配置;参考如下
一定要生成基于Makefile的工具链
在这里插入图片描述
下面是工程的必要的文件抽取,可以选择默认也行
在这里插入图片描述

工程架构

生成的工程如下参考,有build , Drivers, Inc, Src等目录
在这里插入图片描述

新建一个.vscode的配置

在工程目录下面新建一个.vscode的配置,包括编译环境,终端,以及task格式
在这里插入图片描述

c_cpp_properties.json

工程配置如下,请参考我当前的配置

{
    "configurations": [
        {
            "name": "STM32",
            "includePath": [
                "${workspaceFolder}/**",
                "${workspaceFolder}/Drivers/CMSIS/Device/ST/STM32F4xx/Include",
                "${workspaceFolder}/Drivers/CMSIS/Include",
                "${workspaceFolder}/Drivers/STM32F4xx_HAL_Driver/Inc",
                "${workspaceFolder}/Drivers/STM32F4xx_HAL_Driver/Inc/Legacy",
                "${workspaceFolder}/Inc"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE",
                "USE_HAL_DRIVER"

            ],
            "compilerPath": "F:\\Program Files (x86)\\MinGW\\bin\\gcc.exe",
            "cStandard": "c99",
            "cppStandard": "c++98",
            "intelliSenseMode": "gcc-x64"
        }
    ],
    "version": 4
}


  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29

settings.json

{
    "terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe"
}
  • 1
  • 2
  • 3

task.json

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "type": "shell",
            "command": "make",
            "args": [
                // Ask msbuild to generate full paths for file names.
                "/property:GenerateFullPaths=true",
                "/t:build",
                // Do not generate summary otherwise it leads to duplicate errors in Problems panel
                "/consoleloggerparameters:NoSummary"
            ],
            "group": "build",
            "presentation": {
                // Reveal the output only if unrecognized errors occur.
                "reveal": "silent"
            },
            // Use the standard MS compiler pattern to detect errors, warnings and infos
            "problemMatcher": "$msCompile"
        }
    ]
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26

终端编译bash

如果用Makefile的话,需要使用bash的中断进行编译,因此将终端从powershell切换到git bash;

在这里插入图片描述

当前,也可以自己找到绝对路径,主动启动,都可以;

在这里插入图片描述

安装交叉编译工具链arm-none-ebai-gcc

下载路径如下:

https://launchpadlibrarian.net/287101671/gcc-arm-none-eabi-5_4-2016q3-20160926-win32.exe

安装后配置好环境变量
在这里插入图片描述

检查环境变量是否存在

在这里插入图片描述

切换到工程目录编译

在这里插入图片描述
在这里插入图片描述

检查生成的Hex文件

在这里插入图片描述

烧录(待补充)

本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/406234
推荐阅读
相关标签
  

闽ICP备14008679号