天天看點

VSCODE+CORTEX-DEGBU+JLINK~~~STM32開發模闆建立記錄!!

1 需要工具:VSCODE  STM32CUBEMX  ,gcc-arm-none-eabi 插件:cortex-debug  , jlink 驅動,  C/C++ VS makertplace.(工具安裝及插件安裝百度即可)

2  首先先用STM32CUBEMX生成 STM32F103RCT6的makefile工程。

3  makefile 工程導入到VSCODE中,點選新終端,進行MAKE。

4 make 成功完成後,自動生成BUILD檔案。

5 點選調試,VSCODE 自動建立.VSCODE 目錄及LAUNCH.JSON,(我們隻需配置這個檔案,就可以實作調試功能)。

6 配置LAUNCH.JSON:

{

    // 使用 IntelliSense 了解相關屬性。

    // 懸停以檢視現有屬性的描述。

    // 欲了解更多資訊,請通路: https://go.microsoft.com/fwlink/?linkid=830387

    "version": "0.2.0",

    "configurations": [

        {

            "name": "Debug (J-Link)",

            "type": "cortex-debug",

            "request": "launch",

            "servertype": "jlink",

            "cwd": "${workspaceFolder}",//work directory

            "executable": "build/stm32f103rct6-test.elf",

            "device": "STM32F103RC",

            "interface": "swd",

            "preLaunchTask": "Build",//先運作Build任務

        }

    ]

}

(按照自己需求,進行修改後使用)

7 點選調試,提示需要BUILD任務,點選任務模本進行生成,TASKS.JSON,後寫入BUILD任務:

    // See https://go.microsoft.com/fwlink/?LinkId=733558

    // for the documentation about the tasks.json format

    "version": "2.0.0",

    "tasks": [

            "label": "echo",

            "type": "shell",

            "command": "echo Hello"

        },

            "label": "Build",

            "options": {

                "cwd": "${workspaceRoot}"

            },

            "command": "mingw32-make",

            "group": {

                "kind": "build",

                "isDefault": true

            "problemMatcher": [

                "$gcc"

            ]

            "label": "Clean",

            "command": "mingw32-make -f makefile clean",

            "problemMatcher": []

        }        

8  這時應該可以進行調試,如果不行,請進入檔案-首選項-設定-CORTEX-DEBUG插件, 設定:

GDBServer Path的自己電腦上的位址:

"cortex-debug.JLinkGDBServerPath": "C:/Program Files (x86)/SEGGER/JLink_V490/JLinkGDBServer.exe",

以上為我的電腦位址。

9以上設定完成後,應該可以正常編寫程式了。

10 添加c_cpp_properties,主要為宏定義及包含路徑:

            "name": "ARM",

            "intelliSenseMode": "gcc-x64",

             // 注意下面這個指定好 gcc-arm 編譯器後,c/c++ 插件會智能分析,不會按照桌面平台進行語義分析,一定要指明

             // 後面的編譯參數可以從 makefile 裡抄

            "compilerPath": "arm-none-eabi-gcc.exe",

            "defines": [

                "STM32F103xB",

                "USE_HAL_DRIVER"

            ],

            "includePath": [

                // 工程代碼的頭檔案路徑

                "Core/Inc",

                "Drivers/STM32F1xx_HAL_Driver/Inc",

                "Drivers/STM32F1xx_HAL_Driver/Inc/Legacy",

                "Drivers/CMSIS/Device/ST/STM32F1xx/Include",

                "Drivers/CMSIS/Include",

                // gcc 自己 std_lib 的路徑

                "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",

                "D:/Program Files (x86)/GNU Tools ARM Embedded/5.4 2016q3/arm-none-eabi/include"

            "cStandard": "c11",

            "cppStandard": "c++14",

            "forcedInclude": [

                // 不同系列的晶片選擇不同的

                "./Drivers/STM32F1XX_HAL_Driver/Inc/stm32f1xx_hal.h"

    ],

    "version": 4

11 以上方法是我認為新手最快速的建立方式,是以進行記錄。