VsCode+OpenOCD 开发stm32系列

通常会用MDK调试stm32等arm cotex平台,但KEIL MDK很多商业公司是不能直接使用的,需要购买授权!VScode
搭配gcc-arm-none-eabi编译工具链和openocd(Open On-Chip Debugger)实现编译、下载、调试!

所需资源
  • VScode
    https://code.visualstudio.com/
  • MinGW64
    https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/Personal%20Builds/mingw-builds/installer/mingw-w64-install.exe/download
  • gcc-arm-none-eabi
    https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads
    https://launchpad.net/gcc-arm-embedded/+download
  • OpenOCD-20211118-0.11.0
    https://gnutoolchains.com/arm-eabi/openocd/
    (最新的openocd 0.11.3可能只支持 cmsis-dapv2,v1版本好像不支持了
    https://github.com/xpack-dev-tools/openocd-xpack/releases)
环境搭建
1、mingw-w64安装(mingw-w64-install.exe)

VsCode+OpenOCD 开发stm32系列_第1张图片

并添加环境变量:C:\Program Files\mingw-w64\i686-8.1.0-release-posix-dwarf-rt_v6-rev0\mingw32\bin
同时将 C:\Program Files\mingw-w64\i686-8.1.0-release-posix-dwarf-rt_v6-rev0\mingw32\bin\mingw32-make.exe 备份并命名为make.exe

2、arm-gcc安装(gcc-arm-none-eabi-10.3-2021.10-win32.exe)

VsCode+OpenOCD 开发stm32系列_第2张图片

同时添加环境变量:C:\Program Files (x86)\GNU Arm Embedded Toolchain\10 2021.10\bin

3、openocd-20211118.7z解压到指定位置

VsCode+OpenOCD 开发stm32系列_第3张图片

并添加环境变量:D:\work\tool\OpenOCD-20211118-0.11.0\bin

4、VScode安装,并安装插件 C/C++,Cortex-Debug

VsCode+OpenOCD 开发stm32系列_第4张图片
VsCode+OpenOCD 开发stm32系列_第5张图片

工程搭建(以stm32h7为例)

1、STM32CubeMX 生成Makefile 工程

VsCode+OpenOCD 开发stm32系列_第6张图片

2、VScode 打开生成的工程,shift+ctrl+p,进入c/c++配置UI,设置如下配置

VsCode+OpenOCD 开发stm32系列_第7张图片
VsCode+OpenOCD 开发stm32系列_第8张图片

3、复制openOCD配置文件到工程目录(和makefile同一路径)

以CMSIS-DAP 为例,如果用ST-link或者Jlink、ulink等,需要复制对应的cfg文件

D:\work\tool\OpenOCD-20211118-0.11.0\share\openocd\scripts\interface\cmsis-dap.cfg
D:\work\tool\OpenOCD-20211118-0.11.0\share\openocd\scripts\target\stm32h7x.cfg

4、VScode配置编译和下载任务(终端->运行任务->添加配置任务)

VsCode+OpenOCD 开发stm32系列_第9张图片

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": [
            ],
            "group": "build"
        },
        {
            "label": "download",
            "type": "shell",
            "command": "openocd",
            "args": [
                "-f",
                "cmsis-dap.cfg",
                "-f",
                "stm32h7x.cfg",
                "-c",
                "program build/stm32h7_demo.elf verify reset exit"
            ],
            "group": "build"
        }
    ]
}
5、运行"build"任务
> Executing task: make <

mkdir build
arm-none-eabi-gcc -c -mcpu=cortex-m7 -mthumb -mfpu=fpv5-d16 -mfloat-abi=hard -DUSE_HAL_DRIVER -DSTM32H743xx -ICore/Inc -IDrivers/STM32H7xx_HAL_Driver/Inc -IDrivers/STM32H7xx_HAL_Driver/Inc/Legacy -IDrivers/CMSIS/Device/ST/STM32H7xx/Include -IDrivers/CMSIS/Include -Og -Wall -fdata-sections -ffunction-sections -g -gdwarf-2 -MMD -MP -MF"build/main.d" -Wa,-a,-ad,-alms=build/main.lst Core/Src/main.c -o build/main.o
arm-none-eabi-gcc -c -mcpu=cortex-m7 -mthumb -mfpu=fpv5-d16 -mfloat-abi=hard -DUSE_HAL_DRIVER -DSTM32H743xx -ICore/Inc -IDrivers/STM32H7xx_HAL_Driver/Inc -IDrivers/STM32H7xx_HAL_Driver/Inc/Legacy -IDrivers/CMSIS/Device/ST/STM32H7xx/Include -IDrivers/CMSIS/Include -Og -Wall -fdata-sections -ffunction-sections -g -gdwarf-2 -MMD -MP -MF"build/gpio.d" -Wa,-a,-ad,-alms=build/gpio.lst Core/Src/gpio.c -o build/gpio.o
arm-none-eabi-gcc -c -mcpu=cortex-m7 -mthumb -mfpu=fpv5-d16 -mfloat-abi=hard -DUSE_HAL_DRIVER -DSTM32H743xx -ICore/Inc -IDrivers/STM32H7xx_HAL_Driver/Inc -IDrivers/STM32H7xx_HAL_Driver/Inc/Legacy -IDrivers/CMSIS/Device/ST/STM32H7xx/Include -IDrivers/CMSIS/Include -Og -Wall -fdata-sections -ffunction-sections -g -gdwarf-2 -MMD -MP -MF"build/usart.d" -Wa,-a,-ad,-alms=build/usart.lst Core/Src/usart.c -o build/usart.o
arm-none-eabi-gcc -c -mcpu=cortex-m7 -mthumb -mfpu=fpv5-d16 -mfloat-abi=hard -DUSE_HAL_DRIVER -DSTM32H743xx -ICore/Inc -IDrivers/STM32H7xx_HAL_Driver/Inc -IDrivers/STM32H7xx_HAL_Driver/Inc/Legacy -IDrivers/CMSIS/Device/ST/STM32H7xx/Include -IDrivers/CMSIS/Include -Og -Wall -fdata-sections -ffunction-sections -g -gdwarf-2 -MMD -MP -MF"build/stm32h7xx_hal_rcc.d" -Wa,-a,-ad,-alms=build/stm32h7xx_hal_rcc.lst Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_rcc.c -o build/stm32h7xx_hal_rcc.oarm-none-eabi-gcc -c -mcpu=cortex-m7 -mthumb -mfpu=fpv5-d16 -mfloat-abi=hard -DUSE_HAL_DRIVER -DSTM32H743xx -ICore/Inc -IDrivers/STM32H7xx_HAL_Driver/Inc -IDrivers/STM32H7xx_HAL_Driver/Inc/Legacy -IDrivers/CMSIS/Device/ST/STM32H7xx/Include -IDrivers/CMSIS/Include -Og -Wall -fdata-sections -ffunction-sections -g -gdwarf-2 -MMD -MP -MF"build/stm32h7xx_hal_rcc_ex.d" -Wa,-a,-ad,-alms=build/stm32h7xx_hal_rcc_ex.lst Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_rcc_ex.c -o build/stm32h7xx_hal_rcc_ex.oarm-none-eabi-gcc -c -mcpu=cortex-m7 -mthumb -mfpu=fpv5-d16 -mfloat-abi=hard -DUSE_HAL_DRIVER -DSTM32H743xx -ICore/Inc -IDrivers/STM32H7xx_HAL_Driver/Inc -IDrivers/STM32H7xx_HAL_Driver/Inc/Legacy -IDrivers/CMSIS/Device/ST/STM32H7xx/Include -IDrivers/CMSIS/Include -Og -Wall -fdata-sections -ffunction-sections -g -gdwarf-2 -MMD -MP -MF"build/stm32h7xx_hal_flash.d" -Wa,-a,-ad,-alms=build/stm32h7xx_hal_flash.lst Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_flash.c -o build/stm32h7xx_hal_flash.oarm-none-eabi-gcc -c -mcpu=cortex-m7 -mthumb -mfpu=fpv5-d16 -mfloat-abi=hard -DUSE_HAL_DRIVER -DSTM32H743xx -ICore/Inc -IDrivers/STM32H7xx_HAL_Driver/Inc -IDrivers/STM32H7xx_HAL_Driver/Inc/Legacy -IDrivers/CMSIS/Device/ST/STM32H7xx/Include -IDrivers/CMSIS/Include -Og -Wall -fdata-sections -ffunction-sections -g -gdwarf-2 -MMD -MP -MF"build/stm32h7xx_hal_flash_ex.d" -Wa,-a,-ad,-alms=build/stm32h7xx_hal_flash_ex.lst Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_flash_ex.c -o build/stm32h7xx_hal_flash_ex.oarm-none-eabi-gcc -c -mcpu=cortex-m7 -mthumb -mfpu=fpv5-d16 -mfloat-abi=hard -DUSE_HAL_DRIVER -DSTM32H743xx -ICore/Inc -IDrivers/STM32H7xx_HAL_Driver/Inc -IDrivers/STM32H7xx_HAL_Driver/Inc/Legacy -IDrivers/CMSIS/Device/ST/STM32H7xx/Include -IDrivers/CMSIS/Include -Og -Wall -fdata-sections -ffunction-sections -g -gdwarf-2 -MMD -MP -MF"build/stm32h7xx_hal_gpio.d" -Wa,-a,-ad,-alms=build/stm32h7xx_hal_gpio.lst Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_gpio.c -o build/stm32h7xx_hal_gpio.oarm-none-eabi-gcc -c -mcpu=cortex-m7 -mthumb -mfpu=fpv5-d16 -mfloat-abi=hard -DUSE_HAL_DRIVER -DSTM32H743xx -ICore/Inc -IDrivers/STM32H7xx_HAL_Driver/Inc -IDrivers/STM32H7xx_HAL_Driver/Inc/Legacy -IDrivers/CMSIS/Device/ST/STM32H7xx/Include -IDrivers/CMSIS/Include -Og -Wall -fdata-sections -ffunction-sections -g -gdwarf-2 -MMD -MP -MF"build/stm32h7xx_hal_hsem.d" -Wa,-a,-ad,-alms=build/stm32h7xx_hal_hsem.lst Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_hsem.c -o build/stm32h7xx_hal_hsem.o
arm-none-eabi-gcc -c -mcpu=cortex-m7 -mthumb -mfpu=fpv5-d16 -mfloat-abi=hard -DUSE_HAL_DRIVER -DSTM32H743xx -ICore/Inc -IDrivers/STM32H7xx_HAL_Driver/Inc -IDrivers/STM32H7xx_HAL_Driver/Inc/Legacy -IDrivers/CMSIS/Device/ST/STM32H7xx/Include -IDrivers/CMSIS/Include -Og -Wall -fdata-sections -ffunction-sections -g -gdwarf-2 -MMD -MP -MF"build/stm32h7xx_hal_dma.d" -Wa,-a,-ad,-alms=build/stm32h7xx_hal_dma.lst Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_dma.c -o build/stm32h7xx_hal_dma.o
arm-none-eabi-gcc -c -mcpu=cortex-m7 -mthumb -mfpu=fpv5-d16 -mfloat-abi=hard -DUSE_HAL_DRIVER -DSTM32H743xx -ICore/Inc -IDrivers/STM32H7xx_HAL_Driver/Inc -IDrivers/STM32H7xx_HAL_Driver/Inc/Legacy -IDrivers/CMSIS/Device/ST/STM32H7xx/Include -IDrivers/CMSIS/Include -Og -Wall -fdata-sections -ffunction-sections -g -gdwarf-2 -MMD -MP -MF"build/stm32h7xx_hal_dma_ex.d" -Wa,-a,-ad,-alms=build/stm32h7xx_hal_dma_ex.lst Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_dma_ex.c -o build/stm32h7xx_hal_dma_ex.o
arm-none-eabi-gcc -c -mcpu=cortex-m7 -mthumb -mfpu=fpv5-d16 -mfloat-abi=hard -DUSE_HAL_DRIVER -DSTM32H743xx -ICore/Inc -IDrivers/STM32H7xx_HAL_Driver/Inc -IDrivers/STM32H7xx_HAL_Driver/Inc/Legacy -IDrivers/CMSIS/Device/ST/STM32H7xx/Include -IDrivers/CMSIS/Include -Og -Wall -fdata-sections -ffunction-sections -g -gdwarf-2 -MMD -MP -MF"build/stm32h7xx_hal_mdma.d" -Wa,-a,-ad,-alms=build/stm32h7xx_hal_mdma.lst Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_mdma.c -o build/stm32h7xx_hal_mdma.o
arm-none-eabi-gcc -c -mcpu=cortex-m7 -mthumb -mfpu=fpv5-d16 -mfloat-abi=hard -DUSE_HAL_DRIVER -DSTM32H743xx -ICore/Inc -IDrivers/STM32H7xx_HAL_Driver/Inc -IDrivers/STM32H7xx_HAL_Driver/Inc/Legacy -IDrivers/CMSIS/Device/ST/STM32H7xx/Include -IDrivers/CMSIS/Include -Og -Wall -fdata-sections -ffunction-sections -g -gdwarf-2 -MMD -MP -MF"build/stm32h7xx_hal_pwr.d" -Wa,-a,-ad,-alms=build/stm32h7xx_hal_pwr.lst Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_pwr.c -o build/stm32h7xx_hal_pwr.o
arm-none-eabi-gcc -c -mcpu=cortex-m7 -mthumb -mfpu=fpv5-d16 -mfloat-abi=hard -DUSE_HAL_DRIVER -DSTM32H743xx -ICore/Inc -IDrivers/STM32H7xx_HAL_Driver/Inc -IDrivers/STM32H7xx_HAL_Driver/Inc/Legacy -IDrivers/CMSIS/Device/ST/STM32H7xx/Include -IDrivers/CMSIS/Include -Og -Wall -fdata-sections -ffunction-sections -g -gdwarf-2 -MMD -MP -MF"build/stm32h7xx_hal_pwr_ex.d" -Wa,-a,-ad,-alms=build/stm32h7xx_hal_pwr_ex.lst Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_pwr_ex.c -o build/stm32h7xx_hal_pwr_ex.o
arm-none-eabi-gcc -c -mcpu=cortex-m7 -mthumb -mfpu=fpv5-d16 -mfloat-abi=hard -DUSE_HAL_DRIVER -DSTM32H743xx -ICore/Inc -IDrivers/STM32H7xx_HAL_Driver/Inc -IDrivers/STM32H7xx_HAL_Driver/Inc/Legacy -IDrivers/CMSIS/Device/ST/STM32H7xx/Include -IDrivers/CMSIS/Include -Og -Wall -fdata-sections -ffunction-sections -g -gdwarf-2 -MMD -MP -MF"build/stm32h7xx_hal.d" -Wa,-a,-ad,-alms=build/stm32h7xx_hal.lst Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal.c -o build/stm32h7xx_hal.o 
arm-none-eabi-gcc -c -mcpu=cortex-m7 -mthumb -mfpu=fpv5-d16 -mfloat-abi=hard -DUSE_HAL_DRIVER -DSTM32H743xx -ICore/Inc -IDrivers/STM32H7xx_HAL_Driver/Inc -IDrivers/STM32H7xx_HAL_Driver/Inc/Legacy -IDrivers/CMSIS/Device/ST/STM32H7xx/Include -IDrivers/CMSIS/Include -Og -Wall -fdata-sections -ffunction-sections -g -gdwarf-2 -MMD -MP -MF"build/stm32h7xx_hal_i2c.d" -Wa,-a,-ad,-alms=build/stm32h7xx_hal_i2c.lst Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_i2c.c -o build/stm32h7xx_hal_i2c.o
arm-none-eabi-gcc -c -mcpu=cortex-m7 -mthumb -mfpu=fpv5-d16 -mfloat-abi=hard -DUSE_HAL_DRIVER -DSTM32H743xx -ICore/Inc -IDrivers/STM32H7xx_HAL_Driver/Inc -IDrivers/STM32H7xx_HAL_Driver/Inc/Legacy -IDrivers/CMSIS/Device/ST/STM32H7xx/Include -IDrivers/CMSIS/Include -Og -Wall -fdata-sections -ffunction-sections -g -gdwarf-2 -MMD -MP -MF"build/stm32h7xx_hal_i2c_ex.d" -Wa,-a,-ad,-alms=build/stm32h7xx_hal_i2c_ex.lst Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_i2c_ex.c -o build/stm32h7xx_hal_i2c_ex.o
arm-none-eabi-gcc -c -mcpu=cortex-m7 -mthumb -mfpu=fpv5-d16 -mfloat-abi=hard -DUSE_HAL_DRIVER -DSTM32H743xx -ICore/Inc -IDrivers/STM32H7xx_HAL_Driver/Inc -IDrivers/STM32H7xx_HAL_Driver/Inc/Legacy -IDrivers/CMSIS/Device/ST/STM32H7xx/Include -IDrivers/CMSIS/Include -Og -Wall -fdata-sections -ffunction-sections -g -gdwarf-2 -MMD -MP -MF"build/stm32h7xx_hal_exti.d" -Wa,-a,-ad,-alms=build/stm32h7xx_hal_exti.lst Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_exti.c -o build/stm32h7xx_hal_exti.o
arm-none-eabi-gcc -c -mcpu=cortex-m7 -mthumb -mfpu=fpv5-d16 -mfloat-abi=hard -DUSE_HAL_DRIVER -DSTM32H743xx -ICore/Inc -IDrivers/STM32H7xx_HAL_Driver/Inc -IDrivers/STM32H7xx_HAL_Driver/Inc/Legacy -IDrivers/CMSIS/Device/ST/STM32H7xx/Include -IDrivers/CMSIS/Include -Og -Wall -fdata-sections -ffunction-sections -g -gdwarf-2 -MMD -MP -MF"build/stm32h7xx_hal_tim.d" -Wa,-a,-ad,-alms=build/stm32h7xx_hal_tim.lst Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_tim.c -o build/stm32h7xx_hal_tim.o
arm-none-eabi-gcc -c -mcpu=cortex-m7 -mthumb -mfpu=fpv5-d16 -mfloat-abi=hard -DUSE_HAL_DRIVER -DSTM32H743xx -ICore/Inc -IDrivers/STM32H7xx_HAL_Driver/Inc -IDrivers/STM32H7xx_HAL_Driver/Inc/Legacy -IDrivers/CMSIS/Device/ST/STM32H7xx/Include -IDrivers/CMSIS/Include -Og -Wall -fdata-sections -ffunction-sections -g -gdwarf-2 -MMD -MP -MF"build/stm32h7xx_hal_tim_ex.d" -Wa,-a,-ad,-alms=build/stm32h7xx_hal_tim_ex.lst Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_tim_ex.c -o build/stm32h7xx_hal_tim_ex.o
arm-none-eabi-gcc -c -mcpu=cortex-m7 -mthumb -mfpu=fpv5-d16 -mfloat-abi=hard -DUSE_HAL_DRIVER -DSTM32H743xx -ICore/Inc -IDrivers/STM32H7xx_HAL_Driver/Inc -IDrivers/STM32H7xx_HAL_Driver/Inc/Legacy -IDrivers/CMSIS/Device/ST/STM32H7xx/Include -IDrivers/CMSIS/Include -Og -Wall -fdata-sections -ffunction-sections -g -gdwarf-2 -MMD -MP -MF"build/stm32h7xx_hal_uart.d" -Wa,-a,-ad,-alms=build/stm32h7xx_hal_uart.lst Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_uart.c -o build/stm32h7xx_hal_uart.o
arm-none-eabi-gcc -c -mcpu=cortex-m7 -mthumb -mfpu=fpv5-d16 -mfloat-abi=hard -DUSE_HAL_DRIVER -DSTM32H743xx -ICore/Inc -IDrivers/STM32H7xx_HAL_Driver/Inc -IDrivers/STM32H7xx_HAL_Driver/Inc/Legacy -IDrivers/CMSIS/Device/ST/STM32H7xx/Include -IDrivers/CMSIS/Include -Og -Wall -fdata-sections -ffunction-sections -g -gdwarf-2 -MMD -MP -MF"build/stm32h7xx_hal_uart_ex.d" -Wa,-a,-ad,-alms=build/stm32h7xx_hal_uart_ex.lst Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_uart_ex.c -o build/stm32h7xx_hal_uart_ex.o
arm-none-eabi-gcc -c -mcpu=cortex-m7 -mthumb -mfpu=fpv5-d16 -mfloat-abi=hard -DUSE_HAL_DRIVER -DSTM32H743xx -ICore/Inc -IDrivers/STM32H7xx_HAL_Driver/Inc -IDrivers/STM32H7xx_HAL_Driver/Inc/Legacy -IDrivers/CMSIS/Device/ST/STM32H7xx/Include -IDrivers/CMSIS/Include -Og -Wall -fdata-sections -ffunction-sections -g -gdwarf-2 -MMD -MP -MF"build/system_stm32h7xx.d" -Wa,-a,-ad,-alms=build/system_stm32h7xx.lst Core/Src/system_stm32h7xx.c -o build/system_stm32h7xx.o
arm-none-eabi-gcc -x assembler-with-cpp -c -mcpu=cortex-m7 -mthumb -mfpu=fpv5-d16 -mfloat-abi=hard -DUSE_HAL_DRIVER -DSTM32H743xx -ICore/Inc -IDrivers/STM32H7xx_HAL_Driver/Inc -IDrivers/STM32H7xx_HAL_Driver/Inc/Legacy -IDrivers/CMSIS/Device/ST/STM32H7xx/Include -IDrivers/CMSIS/Include -Og -Wall -fdata-sections -ffunction-sections -g -gdwarf-2 -MMD -MP -MF"build/startup_stm32h743xx.d" startup_stm32h743xx.s -o build/startup_stm32h743xx.o
arm-none-eabi-gcc build/main.o build/gpio.o build/usart.o build/stm32h7xx_it.o build/stm32h7xx_hal_msp.o build/stm32h7xx_hal_cortex.o build/stm32h7xx_hal_rcc.o build/stm32h7xx_hal_rcc_ex.o build/stm32h7xx_hal_flash.o build/stm32h7xx_hal_flash_ex.o build/stm32h7xx_hal_gpio.o build/stm32h7xx_hal_hsem.o build/stm32h7xx_hal_dma.o build/stm32h7xx_hal_dma_ex.o build/stm32h7xx_hal_mdma.o build/stm32h7xx_hal_pwr.o build/stm32h7xx_hal_pwr_ex.o build/stm32h7xx_hal.o build/stm32h7xx_hal_i2c.o build/stm32h7xx_hal_i2c_ex.o build/stm32h7xx_hal_exti.o build/stm32h7xx_hal_tim.o build/stm32h7xx_hal_tim_ex.o build/stm32h7xx_hal_uart.o build/stm32h7xx_hal_uart_ex.o build/system_stm32h7xx.o build/startup_stm32h743xx.o -mcpu=cortex-m7 -mthumb -mfpu=fpv5-d16 -mfloat-abi=hard -specs=nano.specs -TSTM32H743IITx_FLASH.ld  -lc -lm -lnosys  -Wl,-Map=build/stm32h7_demo.map,--cref -Wl,--gc-sections -o build/stm32h7_demo.elf
arm-none-eabi-size build/stm32h7_demo.elf
   text    data     bss     dec     hex filename
  13236      24    1712   14972    3a7c build/stm32h7_demo.elf
arm-none-eabi-objcopy -O ihex build/stm32h7_demo.elf build/stm32h7_demo.hex
arm-none-eabi-objcopy -O binary -S build/stm32h7_demo.elf build/stm32h7_demo.bin        

终端将被任务重用,按任意键关闭。

显示编译成功

6、运行"download"任务
> Executing task: openocd -f cmsis-dap.cfg -f stm32h7x.cfg -c 'program build/stm32h7_demo.elf verify reset exit' <

Open On-Chip Debugger 0.11.0 (2021-11-18) [https://github.com/sysprogs/openocd]
Licensed under GNU GPL v2
libusb1 09e75e98b4d9ea7909e8837b7a3f00dda4589dc3
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
Info : auto-selecting first available session transport "swd". To override use 'transport select '.
Info : CMSIS-DAP: SWD  supported
Info : CMSIS-DAP: FW Version = 1.0
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : SWCLK/TCK = 1 SWDIO/TMS = 1 TDI = 0 TDO = 0 nTRST = 0 nRESET = 0
Info : CMSIS-DAP: Interface ready
Info : clock speed 1800 kHz
Info : SWD DPIDR 0x6ba02477
Info : stm32h7x.cpu0: Cortex-M7 r1p1 processor detected
Info : stm32h7x.cpu0: target has 8 breakpoints, 4 watchpoints
Info : gdb port disabled
Info : starting gdb server for stm32h7x.cpu0 on 3333
Info : Listening on port 3333 for gdb connections
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x0800328c msp: 0x20020000
** Programming Started **
Info : Device: STM32H74x/75x
Info : flash size probed value 2048k
Info : STM32H7 flash has dual banks
Info : Bank (0) size is 1024 kb, base address is 0x08000000
Info : Padding image section 1 at 0x080033cc with 20 bytes (bank write end alignment)
Warn : Adding extra erase range, 0x080033e0 .. 0x0801ffff
** Programming Finished **
** Verify Started **
** Verified OK **
** Resetting Target **
shutdown command invoked

终端将被任务重用,按任意键关闭。

显示下载成功

7、配置单步调试功能

左侧debug标签中,新增配置文件,会自动生成launch.json,修改launch.json内容如下:
VsCode+OpenOCD 开发stm32系列_第10张图片

{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "cwd": "${workspaceRoot}",
            "executable": "./build/stm32h7_demo.elf",
            "name": "Debug Microcontroller",
            "request": "launch",
            "type": "cortex-debug",
            "showDevDebugOutput": false,
            "servertype": "openocd",
            "configFiles": [
                "cmsis-dap.cfg",
                "stm32h7x.cfg"
            ]
        }
    ]
}

8、运行调试

VsCode+OpenOCD 开发stm32系列_第11张图片


你可能感兴趣的:(笔记收藏,vscode,stm32,openocd)