Zephyr Development VisualStudio Code Workspace configuration.
This simple repository provides Visual Studio Code (aka VSCode) necessary configurations and tasks for Zephyr development:
- Configuration of VSCode workspace
- Build, Clean, Debug Launch, Code Style Checks tasks
- OpenOCD STM32 config files
- stm32 SVD files needed for debugger
Here you can find the decription of this repository and it's usage. Depending on new features development new description paragraphs can be added.
Note: Currently only Ubuntu Linux
with zephyr-sdk-0.16.0
were tested!
You're also welcome to made changes on this repository. Just fork it and provide PR with meaningfull changes you need. I will bea ble to review it in couple of days.
Follow this simple steps to simplify your Zephyr development in VSCode:
- Follow Zephyr's latest Getting Started Guide
- Switch to yout
zephyrproject
path from terminal:
cd <some_your_path>/zephyrproject
- Clone this repository in your
zephyrproject
:
git clone https://github.com/Nukersson/zephyr_vscode_workspace.git
- Open Zephyr.code-workspace as a workspace in VSCode:
File -> Open Workspace... (be careful: last opened active workspace must be closed)
Note: This repository must be placed in your zephyrproject
folder!
The Zephyr.code-workspace contains all neccessary workspace configuration accepted by Zephyr project like:
- Folders to open (like
zephyrproject
) - Minimal code styling settings (TABs/SPACES)
- Exclude paths (needed to reduce CPU usage while workspace is opened)
There are some predefined tasks (see .vscode/tasks.json) for simplifying of Build, Clean and Launch operations.
Note: In VSCode a task can be run by typing F1
and choosing the task you need.
HowToRun: Press F1
key and choose Tasks: Run Build Task
, then choose West Build Zephyr
This task removes zephyr/build
folder and compiles the project again.
In the file .vscode/tasks.json following environment variables are important:
BOARD_NAME
- defines name of the board to compile Zephyr appplication forPRJ_NAME
- defines application/project name to compile
Change the above environment variables to the board and application name you need.
Note: This task depend on Clean Build
Task. You can remove it from
dependsOn
list of this task to avoid removing of Zephyr's build folder each
time your application will be compiled!
HowToRun: Press F1
key and choose Tasks: Run Build Task
, then choose Set Zephyr Source
This task just runs following script:
./zephyr-env.sh
This is a service task and needed for West Build Zephyr
Task.
WARNING: Do NOT remove this task from the dependsOn
list of West Build Zephyr
Task!
HowToRun: Press F1
key and choose Tasks: Run Build Task
, then choose Clean Build
This task just runs following comand:
rm -rf build
The task is useful if you need refresh your build folder after switching between
branches for example. In this case CMake
is not able to follow changes, which
are happening.
Note: You may remove this task form dependsOn
list of West Build Zephyr
Task,
if you don't want wait long for compile and work whole the time on same project.
HowToRun: Press F1
key and choose Tasks: Run Task
, then choose Stylcheck (commited only
This task runs GitLint (commited only)
and Checkpatch (commited only)
tasks
one after other. Thus it checks code- and commits-style!
It is useful to run this task before you push your PR.
Note: Uncommited changes will not be checked!
HowToRun: Press F1
key and choose Tasks: Run Task
, then choose GitLint (commited only
This task just runs following comand:
gitlint
The task is used for commits-style checking
Note: Uncommited changes will not be checked!
HowToRun: Press F1
key and choose Tasks: Run Task
, then choose Checkpatch (commited only
This task just runs following comand:
${ZEPHYR_BASE}/scripts/checkpatch.pl -g HEAD-10
The task is used for code-style checking. It checks last 10 commits (see HEAD-10
)
from HEAD
. You may change HEAD-N
to check last N
commits (see .vscode/tasks.json).
Note: Uncommited changes will not be checked!
HowToRun: Press F1
key and choose Tasks: Run Build Task
, then choose Generate Eclipse CDT4(commited only
This task creates Eclipse CDT4
files to import the project into Eclipse.
To launch teh project you need Cortex-Debug extension for Visual Studio Code. Please install it and follow it's installation guide.
While installing Cortex-Debug
extension you may need OpenOCD
config files,
which are placed in openocd_stm32_config_files
folder. Currently there are onyl stm32h745
depending config files (You're welcome to add your own).
It can be also helpfull to follow OpenOCD for Zephyr installation description,
especially if you're using ST-LINK V3
debug adapter.
After installing Cortex-Debug
and OpenOCD
on your system, the debug buttun
should appear in your VSCode GUI.
The .vscode/launch.json
describes launch configuration for Cortex-Debug
. In this file you may choose following settings:
- Current board name
- SVD file name
- Debug interface
- Debugger
Add following line to Zephyr's main CMakeLists.txt:
set_source_file_properties(/<some_source>.c PROPERTIES COMPILE_OPTIONS "-O0")
to compile <path-to>/<some_source>.c
wile with -O0.
Aftersiwtching between different remote repositiries you may want delete local unracked branches. You can do it by typing following command in your terminal, while location in your working git repository:
git fetch -p && git branch --merged | grep -v '*' | grep -v 'master' | xargs git branch -d
Explanation
git fetch -p
- will prune all branches no longer existing on remotegit branch -vv
- will print local branches and pruned branch will be tagged with gonegrep ': gone]'
- selects only branch that are goneawk '{print $1}'
- filter the output to display only the name of the branchesxargs git branch -D
- will loop over all lines (branches) and force remove this branch
taken from this source
The file Zephyr.code-workspace
contains Visual Studio Code workspace
configuration and also TABs/SPACES and line margin configuration according to
Zephyr's coding style Guide