VSCODE CUEMX STM32开发环境

所需软件

编号作用软件
1make工具make minigw-make
2编译工具arm-none-eabi-gcc
3调试工具OpenOCD
4STM32 配置工具STM32CUBEMX
5编辑工具vscode
6版本控制git
7调试工具Cortex-Debug

安装软件

  1. git 工具
    优先安装git管理工具。可以用于验证后面环境变量的配置是否成功。

  2. make 工具
    make可用于执行make命令
    minigwminigw内的make工具为minigw-make所以建议重命名为make。
    两个工具二选一,都是执行make命令的工具,需要添加环境变量。

    验证环境变量
    【右键】–>【git bash】

     make -v  //会显示工具版本信息
    
  3. 编译工具

    arm 编译工具
    双击安装后,添加环境变量
    验证环境变量
    【右键】–>【git bash】

     arm-none-eabi-gcc -v //会显示工具版本信息
    
  4. 调试工具
    openocd是压缩包,解压到安装位置后添加环境变量
    验证环境变量
    【右键】–>【git bash】

     openocd -v //会显示工具版本信息
    

测试编译工具链

  1. 使用stm32cubemx创建一个测试项目,项目类型为makefile类型
    注意,需要是能mcu的调试功能,否则无法二次链接mcu

  2. 打开测试项目文件夹

  3. 【右键】–>【git bash】

     make
     ----------------------------------------------------------------
     arm-none-eabi-size build/STM32F103_TEST.elf
        text    data     bss     dec     hex filename
        3776      20    1636    5432    1538 build/STM32F103_TEST.el
     arm-none-eabi-objcopy -O ihex build/STM32F103_TEST.elf build/ST
     arm-none-eabi-objcopy -O binary -S build/STM32F103_TEST.elf bui
    

配置vscode 进行编译

通过vscode 打开测试项目文件夹

编号文件名说明作用
2c_cpp_properties.jsonc语言项目配置文件包含头文件路径 和编译器信息等
3launch.json调试配置文件
4task.json任务配置文件可用于创建相关任务
  1. 编辑c语言项目配置文件
    创建 c_cpp_properties.json
    【F1】–>【输入 “C++”】 -->【C/C++编辑配置(JSON)】

     {
     "configurations": [
         {
             "name": "Win32",
             "includePath": [
                 "${workspaceFolder}/**",
                 "${workspaceFolder}/stm32_cubemx/Drivers/STM32F7xx_HAL_Driver/Inc",
                 "${workspaceFolder}/stm32_cubemx/Drivers/CMSIS/Device/ST/STM32F7xx/Include",
                 "${workspaceFolder}/stm32_cubemx/Drivers/CMSIS/Include",
                 "D:/Program Files (x86)/GNU Tools ARM Embedded/5.4 2016q3/arm-none-eabi/include",
                 "D:/Program Files (x86)/GNU Tools ARM Embedded/5.4 2016q3/arm-none-eabi/include/c++/5.4.1",
                 //"D:/Program Files (x86)/GNU Tools ARM Embedded/5.4 2016q3/arm-none-eabi/include/c++/5.4.1/arm-none-eabi/thumb/v7-m",
                 "D:/Program Files (x86)/GNU Tools ARM Embedded/5.4 2016q3/arm-none-eabi/include/c++/5.4.1/backward",
                 "D:/Program Files (x86)/GNU Tools ARM Embedded/5.4 2016q3/arm-none-eabi/include/sys",
                 "D:/Program Files (x86)/GNU Tools ARM Embedded/5.4 2016q3/lib/gcc/arm-none-eabi/5.4.1/include",
                 "D:/Program Files (x86)/GNU Tools ARM Embedded/5.4 2016q3/lib/gcc/arm-none-eabi/5.4.1/include-fixed"
             ],
             "defines": [
                 "_DEBUG",
                 "UNICODE",
                 "_UNICODE"
             ],
             "compilerPath": "D:/Program Files (x86)/GNU Tools ARM Embedded/5.4 2016q3/bin/arm-none-eabi-gcc.exe",
             "cStandard": "gnu11",
             "cppStandard": "gnu++14",
             "intelliSenseMode": "windows-gcc-x86"
         }
     ],
     "version": 4
    

    }

  2. 任务配置文件
    创建 tasks.json
    【F1】–>【输入 “tasks”】 -->【任务:配置默认生成任务】

     {
     // 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": [],
         "group": "build",
     },
     {
         "label": "clean",
         "type": "shell",
         "command": "make",
         "args": [
             "clean"
         ],
         "group": "build",
     }
     ]
     }
    
  3. 编译项目
    [CTRL + SHIF +B]

Cortex Debug

  1. 创建 launch.json
    点击【调试按钮】–>【创建 launch.json 文件】–>【 Cortex Debug】

     {
     "version": "0.2.0",
     "configurations": [
         {
             "cwd": "${workspaceRoot}",
             "executable": "./build/${workspaceRootFolderName}.elf",
             "name": "Debug stlink",
             "request": "launch",
             "type": "cortex-debug",
             "servertype": "openocd",
             "runToMain": true,
             "configFiles": [
                 "interface/stlink.cfg",
                 "target/stm32f1x.cfg",
             ]
         },
         {
             "cwd": "${workspaceRoot}",
             "executable": "./build/${workspaceRootFolderName}.elf",
             "name": "Debug Jink",
             "request": "launch",
             "type": "cortex-debug",
             "servertype": "jlink",
             "interface": "swd",
             "runToMain": true,
             "device": "STM32F103C8",
             "configFiles": [
                 "interface/jlink.cfg",
                 "target/stm32f1x.cfg",
             ]
         }
     ]
     }
    

由于 jlinkv8不支持stm32f7故只保留stlink配置
注意供电不足会造成能够连接mcu,但是无法正常仿真的情况

	{
	    "version": "0.2.0",
	    "configurations": [
	        {
	            "cwd": "${workspaceRoot}",
	            "executable": "./build/${workspaceRootFolderName}.elf",
	            "name": "Debug stlink",
	            "request": "launch",
	            "type": "cortex-debug",
	            "servertype": "openocd",
	            "runToEntryPoint": "main",
	            "runToMain": true,
	            "configFiles": [
	                "interface/stlink.cfg",
	                "target/stm32f7x.cfg",
	            ]
	        },
	    ]
	}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值