zmk_mf68/docs/docs/dev-setup.md

193 lines
4.4 KiB
Markdown
Raw Normal View History

2020-05-26 11:33:21 +10:00
---
id: dev-setup
title: Basic Setup
sidebar_label: Basic Setup
---
## 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
### Debian/Ubuntu
On Debian and Ubuntu, this can be accomplished with:
```bash
apt-get install -y \
git \
wget \
2020-06-10 13:15:02 +10:00
autoconf \
automake \
build-essential \
ccache \
device-tree-compiler \
dfu-util \
g++ \
gcc \
gcc-multilib \
libtool \
make \
cmake \
python3-dev \
python3-pip \
python3-setuptools \
xz-utils
```
### Fedora
TODO
### macOS
TODO
### WSL
TODO
2020-06-10 06:35:47 +10:00
## Setup
### West Build Command
2020-06-10 07:00:22 +10:00
`west` is the [Zephyr™ meta-tool](https://docs.zephyrproject.org/latest/guides/west/index.html) used to configure and build Zephyr™ applications. It can be installed by using the `pip` python package manager:
2020-06-10 06:35:47 +10:00
```bash
2020-06-10 13:15:02 +10:00
pip3 install --user west
2020-06-10 06:35:47 +10:00
```
:::note
If you don't already have it configured, you may need to update your
`PATH` to include the pip install path. See [User Installs](https://pip.pypa.io/en/stable/user_guide/#user-installs) and [Stack Overflow](https://stackoverflow.com/questions/38112756/how-do-i-access-packages-installed-by-pip-user) for more details.
2020-06-10 06:35:47 +10:00
:::
2020-06-10 07:00:22 +10:00
### 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 /opt/toolchains/zephyr-sdk-${ZSDK_VERSION} && \
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-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 Zephy Workspace
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-10 06:35:47 +10:00
#### Initialize West
```bash
west init -l app/
```
#### Update To Fetch Modules
```bash
west update
```
2020-06-10 07:00:22 +10:00
#### Export Zephyr™ Core
2020-06-10 06:35:47 +10:00
```bash
west zephyr-export
```
### 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:
```
source zmk/zephyr/zephyr-env.sh
```
#### All Shells
To load the environment variables for your shell every time,
append the existing `~/.zephyrrc` file to your shell's RC file, e.g.
##### Bash
```
cat ~/.zephyrc >> ~/.bashrc
```
##### ZSH
```
cat ~/.zephyrc >> ~/.zshrc
```
2020-06-10 06:35:47 +10:00
## Build
2020-06-10 13:15:02 +10:00
Actually building the ZMK firmware occurs within the `app/` subdirectory
of the ZMK repository. 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:
```bash
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:
```bash
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
```