windows10 vscode+stm32cubemx完成對使stm32的開發和配置


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文件上面那個博主里的教程也給出了鏈接,按照上面一步一步來就可以了。

配置完成之后的項目目錄的樣子為:

配置自己的項目大家只需要修改我上面給出的配置路徑就可以,其他的不需要動。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM