5.6 VSCode + STM32 one
Compile the project using cmake.
1. Softwares and Tools
1.1 STM32 development kits
STM32CubeMX download link:https://www.st.com.cn/zh/development-tools/stm32cubemx.html
STM32CubeCLT download link:https://www.st.com.cn/zh/development-tools/stm32cubeclt.html
When using STM32CubeMX, if you encounter issues such as inability to connect to the network, missing fields in .ld files causing compilation errors, please choose to install an older version.This is because the STM32 development kit depends on the jar environment, which needs to match the current system version on your computer.
1.2 VS Code and Extension Plugins
VS Code download link:https://code.visualstudio.com/
Extension Plugins:
C/C++、C/C++ Extension Pack、C/C++ Themes、CMake、CMake Tools、LLVM、STM32 VS Code Extension
STM32 VS Code Extension (@ext:STMicroelectronics.stm32-vscode-extension):
Absolute path to the STM32CubeMX executable:(STM32CubeMX executable path) C:\ST\SetupSTM32CubeMX\STM32CubeMX.exe
Absolute path to the STM32CubeCLT folder:(STM32CubeCLT installation path)
C:\ST\STM32CubeCLT_1.16.0
1.3 Openocd-esp
Openocd-esp download link:https://github.com/espressif/openocd-esp32/releases
Configuring the System Environment Variable PATH:
C:\Openocd-esp\openocd-esp32-win64-0.12.0-esp32-20240821\openocd-esp32\bin
C:\Openocd-esp\openocd-esp32-win64-0.12.0-esp32-20240821\openocd-esp32\share\openocd\scripts
2. Setting Up the Compilation Environment
2.1 Configure Project
【Pinout&Configuration】-> 【SYS】->【Debug】->【 JTAG (5 pins) 】;
【Project Manager】 ->【Project】->【Toolchain/IDE】->Cmake;
2.2【GENERATE CODE】
2.3 Import project to VSCODE
1)STM32 VS Code Extension -> Import CMake project;
2)Select the project folder;
3)Follow the wizard for setup;
Project directory:xxx\xxx\xxx\ (Default);
Project type: CMake (Default);
Hardware: Device > STM32XXXX (Default);
ToolChain:GCC;
4)Click" Import project";xxx\xxx\xxx\;
2.4 Debug with OpenOCD
1)Open "launch.json ";
2)Add settings,choosing :Cortex Debug:OpenOCD ;
3)Modify words;
{
"cwd": "${workspaceRoot}",
"executable": "${command:cmake.launchTargetPath}", // modify,the path after building: xxx.elf
"name": "Debug with OpenOCD",
"request": "attach",
"type": "cortex-debug",
"servertype": "openocd",
"svdFile": "${config:STM32VSCodeExtension.cubeCLT.path}/STMicroelectronics_CMSIS_SVD/STM32G474.svd", // modify,the register setting
"gdbPath":"${config:STM32VSCodeExtension.cubeCLT.path}/GNU-tools-for-STM32/bin/arm-none-eabi-gdb", // modify,assign gdb path
"armToolchainPath": "${config:STM32VSCodeExtension.cubeCLT.path}/GNU-tools-for-STM32/bin", // modify,assign tool path
"configFiles": [
"interface/cmsis-dap.cfg", // modify,Degubber settings under the path of openocd or scripts: xxx.cfg
"target/stm32g4x.cfg", // modify,MCU settings under the path of openocd or scripts: xxx.cfg
],
"searchDir": [],
"runToEntryPoint": "main",
"showDevDebugOutput": "none"
},
2.5 Choose " Debug mode"
3. Build、Debug
Build:VS Code 【Terminal】 -> 【Run task...】 -> Build + Flash;
Debug:choosing "Debug with OpenOCD " -> Run;