zmk_mf68/docs/docs/dev-setup.md

473 lines
11 KiB
Markdown
Raw Normal View History

2020-05-26 11:33:21 +10:00
---
id: dev-setup
title: Basic Setup
sidebar_label: Basic Setup
---
2020-07-07 00:22:43 +10:00
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
export const OsTabs = (props) => (<Tabs
groupId="operating-systems"
defaultValue="linux"
values={[
{label: 'Debian/Ubuntu', value: 'debian'},
{label: 'Raspberry OS', value: 'raspberryos'},
{label: 'Fedora', value: 'fedora'},
{label: 'Windows', value: 'win'},
{label: 'macOS', value: 'mac'},
]
}>{props.children}</Tabs>);
## Prerequisites
2020-06-10 06:35:47 +10:00
2020-06-10 13:15:02 +10:00
A unix-like environment with the following base packages installed:
- Git
2020-06-10 13:15:02 +10:00
- Python 3
- `pip`
- `wget`
- devicetree compiler
- CMake
- `dfu-util`
- Various build essentials, e.g. gcc, automake, autoconf
2020-07-07 00:22:43 +10:00
<OsTabs>
<TabItem value="debian">
On Debian and Ubuntu, we'll use apt to install our base dependencies:
2020-07-07 00:22:43 +10:00
First, if you haven't updated recently, or if this is a new install,
you should update to get the latest package information:
2020-06-10 13:15:02 +10:00
2020-07-14 20:40:53 +10:00
```sh
sudo apt update
```
With the latest package information, you can now install the base dependencies:
2020-07-14 20:40:53 +10:00
```sh
sudo apt install -y \
2020-06-16 13:13:44 +10:00
git \
wget \
autoconf \
2020-06-10 13:15:02 +10:00
automake \
build-essential \
ccache \
device-tree-compiler \
dfu-util \
g++ \
gcc \
libtool \
make \
2020-06-16 13:13:44 +10:00
ninja-build \
cmake \
2020-06-10 13:15:02 +10:00
python3-dev \
python3-pip \
python3-setuptools \
xz-utils
```
:::note
Ubuntu 18.04 LTS release packages a version of CMake that is too old. Please upgrade to Ubuntu 20.04 LTS
or download and install CMake version 3.13.1 or newer manually.
:::
2020-07-07 00:22:43 +10:00
</TabItem>
<TabItem value="raspberryos">
On Raspberry OS, we'll use apt to install our base dependencies:
2020-07-07 00:22:43 +10:00
First, if you haven't updated recently, or if this is a new install,
you should update to get the latest package information:
2020-06-10 13:15:02 +10:00
2020-07-14 20:40:53 +10:00
```sh
2020-07-07 00:22:43 +10:00
sudo apt update
```
2020-06-10 13:15:02 +10:00
2020-07-07 00:22:43 +10:00
With the latest package information, you can now install the base dependencies:
2020-06-10 13:15:02 +10:00
2020-07-14 20:40:53 +10:00
```sh
2020-07-07 00:22:43 +10:00
sudo apt install -y \
git \
wget \
autoconf \
automake \
build-essential \
ccache \
device-tree-compiler \
dfu-util \
g++ \
gcc \
libtool \
make \
ninja-build \
cmake \
python3-dev \
python3-pip \
python3-setuptools \
xz-utils
```
</TabItem>
<TabItem value="fedora">
On Fedora, we'll use `dnf` to install our base dependencies:
#### DNF Update
2020-07-07 00:22:43 +10:00
First, if you haven't updated recently, or if this is a new install,
you should update to get the latest package information:
2020-07-14 20:40:53 +10:00
```sh
2020-07-07 00:22:43 +10:00
sudo dnf update
```
#### Install Dependencies
With the latest package information, you can now install the base dependencies:
2020-07-14 20:40:53 +10:00
```sh
2020-07-07 00:22:43 +10:00
sudo dnf install -y \
git \
wget \
autoconf \
automake \
ccache \
dtc \
dfu-util \
g++ \
gcc \
libtool \
make \
ninja-build \
cmake \
python3-devel \
python3-pip \
python3-setuptools \
xz
```
</TabItem>
<TabItem value="win">
:::note
2020-07-07 00:22:43 +10:00
Use `cmd.exe` with these instructions rather than PowerShell.
:::
2020-06-10 06:35:47 +10:00
2020-07-07 00:22:43 +10:00
Chocolatey is recommended and used for the following instructions. You can manually install each of these applications and add them to your `PATH` if you don't want to use Chocolatey.
1. [Install Chocolatey](https://chocolatey.org/install)
2. Open `cmd.exe` as **Administrator**
3. Run the following `choco` commands:
```shell
choco install cmake --installargs 'ADD_CMAKE_TO_PATH=System'
choco install ninja gperf python git
```
</TabItem>
<TabItem value="mac">
#### Homebrew
Homebrew is required to install the system dependencies. If you haven't done so, visit [Homebrew](https://brew.sh/) for instructions. Once installed, use it to install the base dependencies:
```
brew install cmake ninja python3 ccache dtc git wget
```
</TabItem>
</OsTabs>
2020-06-10 06:35:47 +10:00
## Setup
### West Build Command
2020-07-07 00:22:43 +10:00
`west` is the [Zephyr™ meta-tool](https://docs.zephyrproject.org/latest/guides/west/index.html) used to configure and build Zephyr™ applications.
West can be installed by using the `pip` python package manager.
2020-06-10 06:35:47 +10:00
2020-07-14 20:40:53 +10:00
```sh
2020-07-07 00:22:43 +10:00
pip3 install --user -U west
```
:::tip pip user packages
If you haven't done so yet, you may need to add the Python Pip user package directory to your `PATH`, e.g.:
```
echo 'export PATH=~/.local/bin:"$PATH"' >> ~/.bashrc
source ~/.bashrc
2020-06-10 06:35:47 +10:00
```
:::
2020-07-07 00:22:43 +10:00
### Toolchain Installation
The toolchain provides the compiler, linker, etc necessary to build for the target
platform.
<OsTabs>
<TabItem value="debian">
#### Zephyr™ ARM SDK
2020-06-10 06:35:47 +10:00
2020-06-10 07:00:22 +10:00
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:
2020-06-10 06:35:47 +10:00
```
export ZSDK_VERSION=0.11.2
2020-06-10 06:35:47 +10:00
wget -q "https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v${ZSDK_VERSION}/zephyr-toolchain-arm-${ZSDK_VERSION}-setup.run" && \
sh "zephyr-toolchain-arm-${ZSDK_VERSION}-setup.run" --quiet -- -d ~/.local/zephyr-sdk-${ZSDK_VERSION} && \
2020-06-10 06:35:47 +10:00
rm "zephyr-toolchain-arm-${ZSDK_VERSION}-setup.run"
```
2020-06-10 13:15:02 +10:00
The installation will prompt with several questions about installation location, and creating a default `~/.zephyrrc` for you with various variables. The defaults shouldn normally work as expected.
2020-07-07 00:22:43 +10:00
</TabItem>
<TabItem value="raspberryos">
Because Raspberry OS (Raspbian) runs on the same architecture (but different ABI) as the keyboard MCUs,
the operating system's installed [cross compilers](https://docs.zephyrproject.org/latest/getting_started/toolchain_other_x_compilers.html) can be used to target the different ABI.
First, the cross compiler should be installed:
2020-07-14 20:40:53 +10:00
```sh
2020-07-07 00:22:43 +10:00
sudo apt install gcc-arm-none-eabi
```
Next, we'll configure Zephyr™ with some extra environment variables needed to find the cross compiler by adding the following to `~/.zephyrrc`:
2020-07-14 20:40:53 +10:00
```sh
2020-07-07 00:22:43 +10:00
export ZEPHYR_TOOLCHAIN_VARIANT=cross-compile
export CROSS_COMPILE=/usr/bin/arm-none-eabi-
```
</TabItem>
<TabItem value="fedora">
#### 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:
```
export ZSDK_VERSION=0.11.2
wget -q "https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v${ZSDK_VERSION}/zephyr-toolchain-arm-${ZSDK_VERSION}-setup.run" && \
sh "zephyr-toolchain-arm-${ZSDK_VERSION}-setup.run" --quiet -- -d ~/.local/zephyr-sdk-${ZSDK_VERSION} && \
rm "zephyr-toolchain-arm-\${ZSDK_VERSION}-setup.run"
```
The installation will prompt with several questions about installation location, and creating a default `~/.zephyrrc` for you with various variables. The defaults shouldn normally work as expected.
</TabItem>
2020-07-14 14:12:54 +10:00
<TabItem value="win">
#### GNU ARM Embedded
Since the Zephyr™ SDK is not available for Windows, we recommending following the steps to install the [GNU ARM Embedded](https://docs.zephyrproject.org/latest/getting_started/toolchain_3rd_party_x_compilers.html#gnu-arm-embedded).
</TabItem>
2020-07-07 00:22:43 +10:00
<TabItem value="mac">
2020-07-14 14:12:54 +10:00
#### 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:
```
export ZSDK_VERSION=0.11.2
wget -q "https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v${ZSDK_VERSION}/zephyr-toolchain-arm-${ZSDK_VERSION}-setup.run" && \
sh "zephyr-toolchain-arm-${ZSDK_VERSION}-setup.run" --quiet -- -d ~/.local/zephyr-sdk-${ZSDK_VERSION} && \
rm "zephyr-toolchain-arm-\${ZSDK_VERSION}-setup.run"
```
The installation will prompt with several questions about installation location, and creating a default `~/.zephyrrc` for you with various variables. The defaults shouldn normally work as expected.
2020-07-07 00:22:43 +10:00
</TabItem>
</OsTabs>
2020-06-10 06:35:47 +10:00
### Source Code
Next, you'll need to clone the ZMK source repository if you haven't already:
```
git clone https://github.com/zmkfirmware/zmk.git
```
### Initialize & Update Zephyr Workspace
2020-06-10 06:35:47 +10:00
2020-06-10 07:00:22 +10:00
Since ZMK is built as a Zephyr™ application, the next step is
2020-06-10 06:35:47 +10:00
to use `west` to initialize and update your workspace. The ZMK
2020-06-10 07:00:22 +10:00
Zephyr™ application is in the `app/` source directory:
2020-06-11 00:30:28 +10:00
2020-06-11 01:07:20 +10:00
#### Step into the repository
2020-07-14 20:40:53 +10:00
```sh
cd zmk
```
2020-06-10 06:35:47 +10:00
#### Initialize West
2020-07-14 20:40:53 +10:00
```sh
2020-06-10 06:35:47 +10:00
west init -l app/
```
:::note
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](#west-build-command)
section again for links to how to do this
:::
2020-06-10 06:35:47 +10:00
#### Update To Fetch Modules
2020-07-14 20:40:53 +10:00
```sh
2020-06-10 06:35:47 +10:00
west update
```
2020-06-10 07:00:22 +10:00
#### Export Zephyr™ Core
2020-06-10 06:35:47 +10:00
2020-07-14 20:40:53 +10:00
```sh
2020-06-10 06:35:47 +10:00
west zephyr-export
```
2020-06-10 14:13:55 +10:00
#### Install Zephyr Python Dependencies
2020-07-14 20:40:53 +10:00
```sh
pip3 install --user -r zephyr/scripts/requirements-base.txt
2020-06-10 14:13:55 +10:00
```
### Environment Variables
By default, the Zephyr™ SDK will create a file named `~/.zephyrrc` with the correct environment variables to build ZMK.
We suggest two main [options](https://docs.zephyrproject.org/latest/guides/env_vars.html?highlight=zephyrrc) for how to load those settings.
#### Per Shell
To load the Zephyr environment properly for just one transient shell, run the following from your ZMK checkout directory:
2020-07-14 14:12:54 +10:00
<OsTabs>
<TabItem value="debian">
```
source zephyr/zephyr-env.sh
```
</TabItem>
<TabItem value="raspberryos">
```
source zephyr/zephyr-env.sh
```
</TabItem>
<TabItem value="fedora">
```
source zephyr/zephyr-env.sh
```
2020-07-14 14:12:54 +10:00
</TabItem>
<TabItem value="mac">
```
source zephyr/zephyr-env.sh
```
</TabItem>
<TabItem value="win">
```
source zephyr/zephyr-env.cmd
```
</TabItem>
</OsTabs>
#### All Shells
To load the environment variables for your shell every time,
2020-06-10 14:13:55 +10:00
append the existing `~/.zephyrrc` file to your shell's RC file and then start a new shell.
2020-07-14 14:12:54 +10:00
<Tabs
groupId="shell"
defaultValue="bash"
values={[
{label: 'bash', value: 'bash'},
{label: 'zsh', value: 'zsh'},
{label: 'cmd.exe', value: 'cmd'},
]
}>
<TabItem value="bash">
```
2020-06-11 00:30:28 +10:00
cat ~/.zephyrrc >> ~/.bashrc
```
2020-07-14 14:12:54 +10:00
</TabItem>
<TabItem value="zsh">
```
2020-06-11 00:30:28 +10:00
cat ~/.zephyrrc >> ~/.zshrc
```
2020-07-14 14:12:54 +10:00
</TabItem>
<TabItem value="cmd">
`cmd.exe` instructions coming soon!
</TabItem>
</Tabs>
2020-06-10 06:35:47 +10:00
## Build
From here on, building and flashing ZMK should all be done from the `app/` subdirectory of the ZMK checkout:
2020-07-14 20:40:53 +10:00
```sh
cd app
```
To build for your particular keyboard, the behaviour varies slightly depending on if you are building for a keyboard with
2020-06-10 06:35:47 +10:00
an onboard MCU, or one that uses a MCU board addon.
### Keyboard (Shield) + MCU Board
ZMK treats keyboards that take a MCU addon board as [shields](https://docs.zephyrproject.org/latest/guides/porting/shields.html), and treats the smaller MCU board as the true [board](https://docs.zephyrproject.org/latest/guides/porting/board_porting.html)
Given the following:
- MCU Board: Proton-C
- Keyboard PCB: kyria
- Keymap: default
You can build ZMK with the following:
2020-07-14 20:40:53 +10:00
```sh
2020-06-10 06:35:47 +10:00
west build -b proton_c -- -DSHIELD=kyria -DKEYMAP=default
```
### Keyboard With Onboard MCU
2020-06-10 07:00:22 +10:00
Keyboards with onboard MCU chips are simply treated as the [board](https://docs.zephyrproject.org/latest/guides/porting/board_porting.html) as far as Zephyr™ is concerned.
2020-06-10 06:35:47 +10:00
Given the following:
- Keyboard: Planck
- Keymap: default
you can build ZMK with the following:
2020-07-14 20:40:53 +10:00
```sh
2020-06-10 06:35:47 +10:00
west build -b planck -- -DKEYMAP=default
```
## Flashing
Once built, the previously supplied parameters will be remember, so you can simply run the following to flash your
board, with it in bootloader mode:
```
west flash
```