-
vscode
下載下傳位址:https://code.visualstudio.com/
安裝插件:Cortec-Debug、Cortex-Debug: Device Support Pack - STM32F1
圖1 vscode插件
-
make
(自由軟體下的一個:介紹:https://www.gnu.org/software/make/、http://gnuwin32.sourceforge.net/packages/make.htm
下載下傳位址:https://sourceforge.net/projects/gnuwin32/files/make/3.81/make-3.81-dep.zip/download?use_mirror=nchc&download=)
下載下傳庫檔案和可執行檔案,将庫檔案放到相對應的檔案夾下面
圖2 make軟體下載下傳
添加環境變量到使用者環境變量PATH下,make安裝路徑\bin,比如我的是C:\Program Files (x86)\GnuWin32\bin
檢視軟體是否可以運作并檢查環境變量是否起作用,輸入make -v(--version),顯示版本資訊既安裝成功,見圖3。
圖3 檢查make版本資訊
-
arm-gcc
交叉編譯工具,下載下傳位址:https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads
根據自己的電腦進行響應下載下傳,安裝後同樣添加到環境變量,D:\Program Files (x86)\GNU Tools ARM Embedded\8 2019-q3-update\bin
圖4 檢查arm-gcc版本資訊
-
vscode的終端選擇
Vscode的終端設定為git bash.exe,如果使用git-bash.exe會在vscode之外重新打開一個一個新的視窗,不會在vscode裡面打開,。
打開vscode設定或者setting.json,輸入終端(注意是使用者,不是工作區)
圖5 搜尋終端
找到内部終端設定,打開settings.json檔案
圖6 終端選項
修改終端設定為git下的bash,或者安裝mingw32,使用windows的cmd和powershell提示錯誤。
"terminal.integrated.shell.windows": "D:/Program Files/Git/bin/bash.exe",
-
建立編譯環境
使用stm32cube生成一個帶有makefile的項目。
在項目中打開vscode(讓vscode的工作目錄和項目的工作目錄一緻)。
打開終端,終端輸入make -j4(-j4指定4線程編譯,提高速度)
出現如圖7即可。
圖7 編譯輸出
-
使用task的方式進行編譯
打開指令面闆(左下角設定、ctrl+shift+p、F1),輸入task
圖8 配置任務
打開task.json檔案
配置build指令,build指令用來生成可執行檔案(.elf、.hex)
配置clean指令,clean指令用來清除build過程的中間檔案以及build目錄
{
"version": "2.0.0",
"tasks": [
{
"label": "clean",
"type": "shell",
"command": "make clean",
},
{
"label": "build",
"type": "shell",
"command": "make -j4"
}
]
}
點選終端運作任務,建立task.json之後會看到兩個task,build和clean
圖9 運作任務
圖10 task.json配置的任務
點選clean(繼續執行而不輸出)執行清除build檔案,如圖12顯示,點選build顯示如圖8,如果已經build過會顯示檔案是最新的無需make: Nothing to be done for `all'.
圖11 make clean
-
安裝openocd
openocd介紹:http://openocd.org/,在Getting OpenOCD中下載下傳發行版本
下載下傳位址:http://www.freddiechopin.info/en/download/category/4-openocd
安裝之後添加bin檔案到環境變量
D:\Program Files (x86)\openocd-0.10.0\bin-x64,
圖12 openocd 檢測
-
設定運作時檔案launch.json
cwd : current working directory for finding dependencies and other files
request: the request type of this launch configuration.
executable:被調試檔案的路徑
svdFile:根據晶片的型号在插件目錄下進行選擇
servertype:調試類型
configFiles:openocd的interface和target目錄下進行選擇
preLaunchTask:運作調試之後先運作task指令生成elf檔案
{
"version": "0.2.0",
"configurations": [
{
"name": "Cortex Debug",
"cwd": "${workspaceRoot}",
"executable": "${workspaceFolder}/build/stm32gccdemo.elf",
"request": "launch",
"type": "cortex-debug",
"svdFile": "C:/Users/sspu2/.vscode/extensions/marus25.cortex-debug-dp-stm32f1-1.0.0/data/STM32F103xx.svd",
"servertype": "openocd",
"configFiles": [
"interface/stlink-v2-1.cfg",
"target/stm32f1x.cfg"
],
"preLaunchTask": "build"
},
]
}
-
進行調試
點選調試按鈕,選擇調試器為Cortex Debug
圖13 打開調試
設定斷點
圖14 設定斷點
-
技巧: