This guide is written to help new EEE member to quickly setup development environment on their machine.
Please noted that this guide is first written on 19/12/2022, if any updated is made to the softwares that will be used. Please reference the latest software instruction for configuration details.
Download: https://code.visualstudio.com/
Required Extension
- C/C++
- Cortex-Debug
- IntelliCode
The GNU Compiler Collection (GCC) is an optimizing compiler produced by the GNU Project supporting various programming languages, hardware architectures and operating systems.
Windows
- Download Minimum GCC for Windows (MinGW) : https://sourceforge.net/projects/mingw/
- Copy the
mingw32-make.exe
file and rename it tomake.exe
. - Add the installation path to system path, i.e.
<Path to your installation>/MinGW/bin/
(See Appendix for detail)
Linux
- Type
apt install gcc
in terminal
Mac (Homebrew/Brew)
- Type
brew install gcc
in termial
Minimum required modules
- gcc
- g++
- make
Arm Embeded ToolChain Download: https://developer.arm.com/downloads/-/gnu-rm
Windows
- Add the installation path to system path, i.e.
<Path to your installation>/GNU Arm Embedded Toolchain/bin
Noted: There are two
bin
directory in your installation, DO NOT use thebin
insidearm-none-eabi
folder
Open On Chip Debugger
Offical page: https://openocd.org/
3rd-party build: https://github.com/xpack-dev-tools/openocd-xpack/releases
It is highly recommanded to setup the debugger for troubleshooting. If you don't need a debugger, than you can skip this part.
Windows
- Add the installation path to system path, i.e.
<Path to your installation>/OpenOCD/bin
Linux
- Run script
openocdInstall
for install instruction.
STM32 Cube eco system tool for setting hardware parameter and build the project template.
Download: https://www.st.com/en/development-tools/stm32cubemx.html
Noted: This software required an vaild email to download, after filling the form, the download link will send to your email.
Type the following command to terminal, if you can see the version information than you are fine.
make -v
gcc -v
arm-none-eabi-gcc -v
openocd -v
Configuration is stored inside <ProjectName>.ioc
, do not edit it directly, we only recommended edit it through CubeMX.
Under the Project Manager tab, select Toolchain/IDE as Makefile
There are serval files need to be set. Templates are readied for you. Github
Files
ProjectRoot
|-.vscode
| |-c_cppproperties.json (Manual create)
| |-task.json (Manual create)
| |-launch.json (Manual create)
|
|-build
|-Core
|-Drivers
|-Makefile
|-OpenOCD.cfg (Manual create)
|-...
|-<ProjectName>.ioc
The c_cppproperties.json
file define the IDE highlight and hints setting, it is not a compousery setting, but better set it properly to have a good experience.
There are many item missed here, most of them can find from the Makefile
generated from STM32CubeMX.
IncludePath
and defines
can find in the Makefile
, while CompilerPath
is your ARM-none-eabi-gcc, not regular gcc, otherwise you will miss some header.
Generic template
{
"configurations": [
{
"name": "STM32",
"includePath": [
"${workspaceFolder}/**",
"<Copy the include path from Makefile>"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE",
"<Copy the Marco defined in Makefile>"
],
"compilerPath": "<Path to your ARM-none-eabi-gcc>/GNU Arm Embedded Toolchain/bin/arm-none-eabi-gcc.exe",
"cStandard": "c11",
"cppStandard": "gnu++14",
"intelliSenseMode": "windows-gcc-arm"
}
],
"version": 4
}
Template for STM32H7x
{
"configurations": [
{
"name": "STM32",
"includePath": [
"${workspaceFolder}/**",
"Core/Inc",
"Drivers/STM32H7xx_HAL_Driver/Inc",
"Drivers/STM32H7xx_HAL_Driver/Inc/Legacy",
"Drivers/CMSIS/Device/ST/STM32H7xx/Include"
//"<Other path listed inside Makefile>"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE",
"USE_HAL_DRIVER",
"<STM32 model defined in Makefile>"
],
"compilerPath": "<Path to your ARM-none-eabi-gcc>/GNU Arm Embedded Toolchain/bin/arm-none-eabi-gcc.exe",
"cStandard": "c11",
"cppStandard": "gnu++14",
"intelliSenseMode": "windows-gcc-arm"
}
],
"version": 4
}
The task.json
file define the task that vscode automated for you.
{
// 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",
"detail": "compilerPath: <Path to your ARM-none-eabi-gcc>/GNU Arm Embedded Toolchain/bin/arm-none-eabi-gcc.exe",
"problemMatcher": "$gcc"
},
{
"label": "Download",
"type": "shell",
"command": "openocd",
"args": [
"-f",
"OpenOCD.cfg",
"-c program ./build/${workspaceFolderBasename}.elf verify reset exit"
],
"group": "build",
"dependsOn":[
"Build"
],
"detail": "openocd profile: OpenOCD.cfg",
"problemMatcher": "$gcc"
}
]
}
The launch.json
define debug action.
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"cwd": "${workspaceRoot}",
"executable": "./build/${workspaceFolderBasename}.elf",
"name": "Debug with OpenOCD",
"request": "launch",
"type": "cortex-debug",
"servertype": "openocd",
"configFiles": ["OpenOCD.cfg"],
"searchDir": [],
"runToEntryPoint": "main",
"showDevDebugOutput": "both",
"preLaunchTask": "Build"
},
]
}
#debug probe / debug interface
source [find interface/stlink.cfg]
#target mcu / development board
source [find target/stm32<series>x.cfg]