Basic Setup
Prerequisites
ZMK requires the following base packages to first be installed:
- Git
- Python 3
pip
wget
- devicetree compiler
- CMake
dfu-util
- Various build essentials, e.g. gcc, automake, autoconf
- Debian/Ubuntu
- Windows
- macOS
- Raspberry OS
- Fedora
- VS Code & Docker
On Debian and Ubuntu, we'll use apt
to install our base dependencies:
First, if you haven't updated recently, or if this is a new install, you should update to get the latest package information:
With the latest package information, you can now install the base dependencies:
note
Recent LTS releases of Debian and Ubuntu may include outdated CMake versions. If the output of cmake --version
is older than 3.15, upgrade your distribution (e.g., from Ubuntu 18.04 LTS to Ubuntu 20.04 LTS), or else install CMake version 3.15 or newer manually (e.g, from Debian backports or by building from source).
There is also a zephyr bug with cmake 3.19.x. You'll need a version below 3.19.
Setup
West Installation
west
is the Zephyrâ„¢ meta-tool used to configure and build Zephyrâ„¢ applications.
West can be installed by using the pip
python package manager. The Zephyrâ„¢ instructions are summarized here:
- Linux
- Windows
pip
user packages
If you haven't done so yet, you may need to add the Python pip
package directory to your PATH
otherwise your computer will not be able to find the west
command.
- Linux
- Windows
Toolchain Installation
The toolchain provides the compiler, linker, etc., necessary to build for the target platform.
- Debian/Ubuntu
- Windows
- macOS
- Raspberry OS
- Fedora
- VS Code & Docker
Zephyrâ„¢ ARM SDK
To build firmwares for the ARM architecture (all supported MCUs/keyboards at this point), you'll need to install the Zephyrâ„¢ ARM SDK to your system:
The installation will prompt with several questions about installation location, and creating a default ~/.zephyrrc
for you with various variables. The defaults should normally work as expected.
note
If you intend to build firmware straight away, make sure to correctly setup the current shell.
Notes on setting this up can be found in the Environment Variables section. The transient instructions can be used to setup the current shell, and the automatic instructions can setup any newly made shells automatically.
The transient instructions must be run to build firmware using the current shell.
Source Code
Next, you'll need to clone the ZMK source repository if you haven't already. Navigate to the folder you would like to place your zmk
directory in and run the following command:
Initialize & Update Zephyr Workspace
Since ZMK is built as a Zephyrâ„¢ application, the next step is
to use west
to initialize and update your workspace. The ZMK
Zephyrâ„¢ application is in the app/
source directory:
Step into the repository
- Debian/Ubuntu
- Windows
- macOS
- Raspberry OS
- Fedora
- VS Code & Docker
Initialize West
Command Not Found?
If you encounter errors like command not found: west
then your PATH
environment variable is likely
missing the Python 3 user packages directory. See the West Build Command
section again for links to how to do this
Update To Fetch Modules
tip
This step pulls down quite a bit of tooling. Go grab a cup of coffee, it can take 10-15 minutes even on a good internet connection!
info
If you're using Docker, you're done with setup! You must restart the container at this point. The easiest way to do so is to close the VS Code window, verify that the container has stopped in Docker Dashboard, and reopen the container with VS Code.
Once your container is restarted, proceed to Building and Flashing.
Export Zephyrâ„¢ Core
Install Zephyr Python Dependencies
Environment Variables
- Windows
- Other OS
For GNU ARM Embedded on Windows
On Windows, only two environment variables need to be set for ZMK to build properly: ZEPHYR_TOOLCHAIN_VARIANT
and GNUARMEMB_TOOLCHAIN_PATH
.
- Open Start Menu and type 'env' to find the 'Edit the system environment variables' option. Open it.
- Click 'Environment Variables...'.
- Click "New..." under System variables to create a new system variable.
- Set the variable name to 'ZEPHYR_TOOLCHAIN_VARIANT' and value to 'gnuarmemb'. Click OK to save.
- Create another variable with variable name 'GNUARMEMB_TOOLCHAIN_PATH' and value set to wherever you installed your toolchain. Make sure this path does not contain any spaces. If it does, rename the folder and update here. Click OK to save.
- Close Command Prompt and reopen, or run
refreshenv
to apply the changes.