通常芯片厂家会提供各类开发IDE方案,一般其中就包括其自家的集成IDE,如:html
意法半导体 STM32CubeIDEpython
NXP Codewarriorc++
TI CCSgit
另外也能够用eclipse、VS studio、VS code等搭建开发环境shell
1.下载并安装 vs code编程
2.下载并安装 STM32CubeMXjson
支持最新的HAL库,工程代码配置与生成工具,支持生成IAR、Keil、STM32CubeIDE、Makefile等工程,这里使用其生成的Makefile工程。windows
3.下载并安装 Git for Windowsbash
该工具集成有精简版的mingw,这里咱们使用其bash终端和版本管理均很是有用。eclipse
4.下载并安装 arm-none-eabi-gcc
编译器,GUN的arm的通用交叉编译链工具,基本上经常使用的arm处理器均支持;
安装时勾选设置全局环境变量以便于配置;
使用离线免安装包时,解压到合适的位置,在系统环境变量添加\bin目录,运行CMD或者Windows PowerShell,测试一下是否可用。命令:arm-none-eabi-gcc -v
5.下载并安装 mingw
MinGW 的全称是:Minimalist GNU on Windows 。它其实是将经典的开源 C语言 编译器 GCC 移植到了 Windows 平台下,而且包含了 Win32API 和 MSYS,所以能够将源代码编译生成 Windows 下的可执行程序,又能如同在 Linux 平台下时,使用一些 Windows 不具有的开发工具。
一句话来归纳:MinGW 就是 GCC 的 Windows 版本 。
其安装通常为在线安装,按网上步骤便可。
这里咱们主要须要使用其 mingw32-make 功能.
若是因为环境不能在线安装,可安装其离线安装包
MinGW-W64 GCC-8.1.0 x86_64-win32-seh
下载压缩文件并解压到合适的位置,在系统环境变量添加\bin目录,运行CMD或者Windows PowerShell,测试一下是否可用。命令:gcc -v
同时为方便使用,复制 mingw32-make.exe 一份为 make.exe,这样后面编译程序使用 make 便可。
6.安装mysy2
shell 命令行开发环境,可用于替代 git-bash、cmd、power shell,功能相对更完善。
安装以后,在vscode中配置 settings.json--"terminal.integrated.shell.windows": "C:\msys64\msys2_shell.cmd", 详见下节。
7.下载并安装(可选) OpenOCD for Windows
8.Jlink、ST-Link驱动
9.STM32CubeProg 用于stm32下载程序
安装开发所需基础插件(插件在 vs code 拓展栏搜索名称便可)
C/C++(必要)
增长了对C / C ++的语言支持,语法智能感知、加亮及调试功能
GBKtoUTF8
cortex-debug
1.芯片选型、HAL版本、引脚配置、时钟树配置等,可参照下面博客
http://www.javashuo.com/article/p-hxpqfthi-ea.html
2.工程管理中,选择生成makefile工程,而后点击 generate code便可
默认状况下,工程下是不含.vscode的文件夹的,修改编辑用户或工程settings.json文件时会自动建立;
user--settings.json文件参考修改以下(包含配置终端和一些格式等设置):
{ "C_Cpp.updateChannel": "Insiders", "http.proxySupport": "off", "workbench.iconTheme": "vscode-icons", //取消左侧自动聚焦 "explorer.autoReveal": false, "[c]": { "editor.defaultFormatter": "ms-vscode.cpptools" //默认格式化工具 }, "[h]": { "editor.defaultFormatter": "ms-vscode.cpptools" //默认格式化工具 }, "editor.formatOnSave": true, //文件保存时自动格式化 "editor.formatOnPaste": true, //代码粘贴时自动格式化 "editor.formatOnType": true, //自动格式化键入行 // "terminal.integrated.shell.windows": "D:\\Program Files\\Git\\git-bash.exe", "terminal.integrated.shell.windows": "C:\\msys64\\msys2_shell.cmd", "terminal.integrated.shellArgs.windows": [ "-defterm", "-mingw64", "-no-start", "-here", "-use-full-path" //使用系统环境变量 ], "terminal.external.windowsExec": "D:\\Program Files\\Git\\git-bash.exe" }
或者在菜单中设置 File--Preferences--Settings--Features--Terminal
1.实际开发须要熟悉 makefile
工程后面添加的文件程序须要由makefile来组织编译;
打开工程makefile,编译工具指定,默认 PREFIX = arm-none-eabi- ,若是已设置环境变量则无需修改,不然需添加(实际绝对路径路径) GCC_PATH = D:\gcc-arm-none-eabi-5_4-2016q3-20160926-win32\bin
PREFIX = arm-none-eabi- # The gcc compiler bin path can be either defined in make command via GCC_PATH variable (> make GCC_PATH=xxx) # either it can be added to the PATH environment variable. ifdef GCC_PATH CC = $(GCC_PATH)/$(PREFIX)gcc AS = $(GCC_PATH)/$(PREFIX)gcc -x assembler-with-cpp CP = $(GCC_PATH)/$(PREFIX)objcopy SZ = $(GCC_PATH)/$(PREFIX)size else CC = $(PREFIX)gcc AS = $(PREFIX)gcc -x assembler-with-cpp CP = $(PREFIX)objcopy SZ = $(PREFIX)size endif HEX = $(CP) -O ihex BIN = $(CP) -O binary -S
1.c_cpp_properties.json
主要有添加include路径,编译器路径,宏定义等,设置好后索引、编译就跟keil同样方便;
打开工程 .vscode 下面的 c_cpp_properties.json 配置脚本,这个json不容许有注释,若是你本身编写了头文件又不在workspaceFolder下,路径也要加到includePath和browse里。设置以下:
{ "configurations": [ { "name": "Win32", "includePath": [ "${workspaceFolder}/**", "${workspaceFolder}Drivers/STM32F4xx_HAL_Driver/Inc", "${workspaceFolder}Drivers/STM32F4xx_HAL_Driver/Inc/Legacy", "${workspaceFolder}Drivers/CMSIS/Device/ST/STM32F4xx/Include", "${workspaceFolder}Drivers/CMSIS/Include", "${workspaceFolder}Drivers/CMSIS/Include", "D:/gcc-arm-none-eabi-5_4-2016q3-20160926-win32/arm-none-eabi/include" ], "defines": [ "_DEBUG", "UNICODE", "_UNICODE", "USE_HAL_DRIVER", "STM32F407xx" ], "compilerPath": "D:\\gcc-arm-none-eabi-5_4-2016q3-20160926-win32\\bin\\arm-none-eabi-gcc.exe", "cStandard": "c11", "cppStandard": "c++17", "intelliSenseMode": "gcc-x86" } ], "version": 4 }
2.launch.json
所须要调试的文件的路径、调试时的CWD(工做路径)、调试器的路径及一些调试参数(程序启动参数等);
{ // 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": [ { "cwd": "${workspaceRoot}", "executable": "./bin/HAL_Test.elf", "name": "stm32 Debug", "request": "launch", "type": "cortex-debug", "servertype": "stutil", "device": "STM32F407ZG", "preLaunchTask": "编译并下载", "postDebugTask": "复位设备" } ] }
3.tasks.json
{ // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format "version": "2.0.0", "tasks": [ { "label": "编译", "type": "shell", "command": "make -j6", "problemMatcher": [], "group": { "kind": "build", "isDefault": true } }, { "label": "编译并下载", "type": "shell", "command": "make -j6 && make update", "problemMatcher": [] }, { "label": "从新编译", "type": "shell", "command": "make clean && make -j6", "problemMatcher": [] }, { "label": "复位设备", "type": "shell", "command": "STM32_Programmer_CLI -c port=SWD -hardRst", "problemMatcher": [] } ] }
4.工程下打开终端,输入 make
工程编程会生成 .bin 文件,这个就是咱们要烧录的目标文件。
5.使用 Jlink 的 Jflash 工具烧录
6.使用 JLink GDB server 调试,调试方法如同Linux下面的GDB,主要使用命令行
1.取消文件自动定位到侧边栏
当我在右侧点击某个文件时,左侧会自动定位到该文件所在位置,这点特别烦,尤为在项目目录很长的时候。
在用户 settings.json 中修改
"explorer.autoReveal": false
2.设置默认终端
File--Preferences--Settings-- 中打开用户 setting.json文件,修改以下:
"terminal.integrated.shell.windows": "D:\\Program Files\\Git\\bin\\bash.exe", "terminal.external.windowsExec": "D:\\Program Files\\Git\\bin\\bash.exe",
2.使用插件推荐(根据需求选择)
插件 | 功能 |
---|---|
C/C++ | C / C ++的语言支持,语法智能感知、加亮及调试功能,固然须要系统安装arm-none-eabi-gcc编译器 |
Include Autocomplete | 头文件自动匹配 |
Code Runner | 代码一键运行 |
Cortex Debug | 提供jlink、stlink等调试接口功能 |
filesize | 显示文件大小 |
Python | Python的语言支持,语法智能感知、加亮及调试功能,须要系统安装python |
Git History | 查看版本历史及比较 |
GitLens | 代码中显示提交信息、日志查看方便,同时提供操做图标 |
GBKtoUTF8 | |
ARM | arm汇编语言支持 |
Bracket Pair Colorizer | 彩虹花括号,程序逻辑范围查看方便 |
DeviceTree | 设备树语法支持 |
vscode-icons | 文件图标,可快速查看文件类型 |
PlatformIO IDE |