This is the 9th day of my participation in the August More Text Challenge
Here is an introduction to stm32 development under Windows using vscode and jflash
Install vscode
Install vscode without further details.
Installing the make tool
Windows does not have a make tool. You need to download mingw, mingw-w64-install.exe, and add the bin directory to the environment variables
Mingw32-make = mingw32-make = mingw32-make = mingw32-make = mingw32-make = mingw32-make = mingw32-make = mingw32-make
Install the cross-compile toolchain
We need to install ARM GCC Toolchain (developer.arm.com/open-source…)
Once installed, add the environment variables and verify on the command line: arm-none-eabi-gcc -v
Install jflash
Jflash is installed normally, which is usually installed when you install the JLink driver, and then you need to add environment variables
Install the clang LLVM
Clang is installed to provide visual studio Code with syntax completion, code formatting and other functions. After installation, environment variables are added
Generate and compile code
After configuring the project in STM32CubeMX, select the makefile type and generate the code.
To compile and generate downloadable binaries, run make on the command line in the folder.
Configuration vscode
Installing a plug-in
You need to install C/C ++, ARM, and Cortex-Dubug. The ARM plug-in is used to format ARM assembly code, and the Cortex-Debug plug-in is used to simplify debugging configuration files
The configuration file
Open the project folder with vscode and save it as a workspace.
c_cpp_properties.json
Use CTRL + Shift + P and type C/C++:Edit Configurations(UI) to open the configuration screen
- Adding a New Configuration
- Add arm-none-eabi-gcc compilation path
- Open the Makefile and add the macro definitions to the configuration screen
- Select C99 for the C language version
- Open the. Vscode \c_cpp_properties.json file to delete the c++ version configuration
.vscode\c_cpp_properties.json is used to configure C/C++ syntax hints
{
"configurations": [{"name": "npc"."includePath": [
"${workspaceFolder}/**",]."defines": [
"_DEBUG"."UNICODE"."_UNICODE"."USE_HAL_DRIVER"."STM32F103xB"]."compilerPath": "\"D:/GNU Tools ARM Embedded/5.4 2016q3/bin/arm-none-eabi-gcc.exe\"."cStandard": "c99"."intelliSenseMode": "clang-x86"}]."version": 4
}
Copy the code
launch.json
This file is used to configure debugging tasks, CTRL + Shift + P, Debug:Open launch.json, select Cortex Debug, as shown below
{
"trace": true."configurations": [{"cwd": "${workspaceRoot}"."executable": "./build/npc.elf"."name": "Debug Microcontroller"."request": "launch"."type": "cortex-debug"."device": "STM32F103C8"."servertype": "jlink"."svdFile": "./STM32F103.svd"}}]Copy the code
The places that need to be configured in the file are
- “Executable “: “./build/npc.elf” should be the executable file that just compiled
- Device Changes the type of its own chip
- SvdFile, used to describe chip peripherals. After configuration, the registers of the peripherals can be read during debugging
Download and debug code
After configuring launch.json, you can see the debug just configured in vscode debug interface. Click “run” to debug