VSCode搭建STM32编译环境

本文介绍了如何在VSCode中配置STM32工程,包括生成基于Makefile的工具链,设置.c_cpp_properties.json、settings.json和task.json文件,以及安装和配置ARM交叉编译工具链。通过这些步骤,可以实现STM32项目的编译和构建。
摘要由CSDN通过智能技术生成

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
}


settings.json

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

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"
        }
    ]
}

终端编译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文件

在这里插入图片描述

烧录(待补充)

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值