Ubuntu18.04 基于VSCode和STM32CubeMX

2019-11-26  本文已影响0人  SmartFish

Step1:

sudo apt-get install default-jre

Step2:

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

Step3:

OPENOCD := openocd -f interface/jlink.cfg \
        -c 'transport select swd' \
        -f target/stm32f4x.cfg
# download your program
flash: all
    $(OPENOCD) -c init \
        -c 'reset halt' \
        -c 'flash write_image erase $(BUILD_DIR)/$(TARGET).elf' \
        -c 'reset run' \
        -c exit

注1:此时应该在Terminal中可以make flash直接一步编译并下载固件了。
注2:第一行-f表示的是选择jlink,如果不是jlink可以到OpenOCD的scripts目录下找(如stlink v2.1则可以改为openocd -f interface/stlink-v2-1.cfg),默认路径为/usr/share/openocd/scripts。第二行因为我的jlink仅支持swd模式,所以加上了,实际如果支持jtag模式是不需要的。第三行选择的是个人的芯片配置文件,同样可以在OpenOCD的scripts目录下找到,可根据自己选择的芯片进行修改。


target文件夹

Step4:

smartfish@smartfish:~$ whereis arm-none-eabi-gcc
arm-none-eabi-gcc: /usr/bin/arm-none-eabi-gcc
{
    // See https://go.microsoft.com/fwlink/?LinkId=733558 
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        // 编译
        {
            "type": "shell",
            "label": "build all",
            "command": "make -j8",
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        },
        // 清除编译
        {
            "type": "shell",
            "label": "clear all",
            "command": "make clean",
            "problemMatcher": []
        },
        // 全部重新编译
        {
            "type": "shell",
            "label": "rebuild all",
            "dependsOrder": "sequence",
            "dependsOn": [
                "clear all",
                "build all"
            ],
            "problemMatcher": [
                "$gcc"
            ]
        },
        // 仅下载
        {
            "type": "shell",
            "label": "flash it",
            "command": "make -j8 flash",
            "dependsOn":[
                "build all"
            ],
            "problemMatcher": []
        },
        // 编译并下载
        {
            "type": "shell",
            "label": "build and flash",
            "dependsOrder": "sequence",
            "dependsOn" :[
                "build all",
                "flash it"
            ],
            "problemMatcher": [
                "$gcc"
            ],
        }
    ]
}

Step6:

选择Cortex Debug
launch模板 仅支持swd模式的配置

注1:此处添加了一个"preLaunchTask"和"runToMain"属性,前者是为了进入调试模式前先下载一波程序,后者则是跳过stm32启动代码,直接进入主函数开始调试。

Step7:

上一篇下一篇

猜你喜欢

热点阅读