windows10 vscode+stm32cubemx完成對使stm32的開發和配置
阿新 • • 發佈:2021-08-29
windows10 vscode+stm32cubemx完成對使stm32的開發和配置
學習stm32的時候發現keil的顏值太低,而且程式碼提示很差勁,因此想到使用自己喜歡的vscode來進行開發。經過在網上的一番折騰終於找到了可靠的教程。
用VS Code開發STM32(一)——軟體安裝 - 知乎 (zhihu.com)
用VS Code開發STM32(二)——編譯 - 知乎 (zhihu.com)
用VS Code開發STM32(三)——除錯 - 知乎 (zhihu.com)
用VS Code開發STM32(四)——增加SEGGER RTT日誌輸出支援 - 知乎 (zhihu.com)
將環境配置好的話,每次建立專案只需要完成以下工作:
建立.vscode資料夾以及相關配置檔案
c_cpp_properties.json
{ "configurations": [ { "name": "Win32", "includePath": [ "D:/Software/GNU/10 2021.07/lib/gcc/arm-none-eabi/10.3.1/include", "${workspaceFolder}/Inc", "${workspaceFolder}/Drivers/STM32F4xx_HAL_Driver/Inc", "${workspaceFolder}/Drivers/STM32F4xx_HAL_Driver/Inc/Legacy", "${workspaceFolder}/Drivers/CMSIS/Device/ST/STM32F4xx/Include", "${workspaceFolder}/Drivers/CMSIS/Include" ], "defines": [ "USE_HAL_DRIVER", "STM32F407xx" ], "compilerPath": "D:/Software/GNU/10 2021.07/bin/arm-none-eabi-gcc.exe", "intelliSenseMode": "gcc-x64", "browse": { "limitSymbolsToIncludedHeaders": true, "databaseFilename": "", "path": [ "${workspaceFolder}" ] } } ], "version": 4 }
launch.json
{ // 使用 IntelliSense 瞭解相關屬性。 // 懸停以檢視現有屬性的描述。 // 欲瞭解更多資訊,請訪問: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "Cortex Debug", "cwd": "${workspaceRoot}", "executable": "${workspaceRoot}/build/${workspaceFolderBasename}.elf", "request": "launch", "type": "cortex-debug", "device":"STM32F407VE", //使用J-link GDB Server時必須;其他GBD Server時可選(有可能幫助自動選擇SVD檔案)。支援的裝置見 https://www.segger.com/downloads/supported-devices.php "svdFile": "./STM32F407.svd", //svd檔案,有這個檔案才能檢視暫存器的值,每個微控制器都不同。可以在以下地址找到 https://github.com/posborne/cmsis-svd "servertype": "openocd", //使用的GDB Server "configFiles": [ "${workspaceRoot}/openocd.cfg" ], "preLaunchTask": "build", "armToolchainPath": "D:/Software/GNU/10 2021.07/bin" } ] }
settings.json
{
"terminal.integrated.shell.windows": "D:/Software/Git/bin/bash.exe",
"files.associations": {
"stm32f4xx_hal.h": "c"
}
}
tasks.json
{
// 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": [
"-j4"
]
},
{
"label": "clean",
"type": "shell",
"command": "make",
"args": [
"clean"
]
}
]
}
配置的具體含義大家看上面博主的教程就可以了。雖然有點麻煩,但是配置好之後就簡單了。
最後就是我在執行gdb server的時候發現執行報錯了。我的分析是沒有插入jlink並安裝相關驅動造成的,並不是配置出錯。
在專案根目錄下配置openocd.cfg檔案
# 選擇偵錯程式為jlink
source [find interface/jlink.cfg]
#source [find interface/cmsis-dap.cfg]
# 選擇介面為SWD
transport select swd
# 選擇目標晶片
source [find target/stm32f4x.cfg]
複製對應的svd檔案到根目錄
svd檔案上面那個博主裡的教程也給出了連結,按照上面一步一步來就可以了。
配置完成之後的專案目錄的樣子為:
配置自己的專案大家只需要修改我上面給出的配置路徑就可以,其他的不需要動。