Setup Zephyr

Golioth can be added to a device with Device SDKs which are based on different embedded Operating Systems. Currenly Golioth targets the Zephyr Project and builds upon the APIs & tools of Zephyr. As such, prior experience with Zephyr will make working with Golioth's Zephyr Device SDK comfortable and familiar. Refer to Zephyr's detailed documentation when running into issues.

Install West and the Zephyr SDK#

Install dependencies with apt:

sudo apt update
sudo apt install --no-install-recommends git cmake ninja-build gperf \
ccache dfu-util device-tree-compiler wget \
python3-dev python3-pip python3-setuptools python3-tk python3-wheel xz-utils file \
make gcc gcc-multilib g++-multilib libsdl2-dev
note

While the official documentation for Zephyr suggests jumping right into installing west, we suggest creating a python3 virtual environment first, to avoid running into tooling incompatibilities.

Install virtualenv and create a new environment:

sudo pip3 install virtualenv
virtualenv -p python3 ~/zephyr-env

Whenever you need to activate this virtual env, run:

source ~/zephyr-env/bin/activate
# OR, if you're using the fish shell, run
source ~/zephyr-env/bin/activate.fish
note

If you'd like to exit out of the virtualenv at the end of the tutorial, run deactivate.

Now, use pip to install west:

note

Because we're in a python3 virtualenv, we don't need to specify pip3 and can just use pip.

pip install west

Installing the Device SDK#

With west installed, grab the Device SDK:

info

Depending on your internet and I/O speed, west update can take upwards of 5 or 10 minutes.

cd ~
west init -m [email protected]:golioth/zephyr.git --mr main ~/zephyrproject
cd zephyrproject/
west update
west patch
note

The patch step is temporary until the Github repo is made public

Tell west to automatically configure CMake:

west zephyr-export

Lastly, install the remaining dependencies:

pip install -r ~/zephyrproject/zephyr/scripts/requirements.txt

Install a device-specific toolchain#

Install Espressif SDK (ESP-IDF)#

west makes it easy to install the Espressif toolchain:

west espressif install

Configure the toolchain with environment variables:

export ZEPHYR_TOOLCHAIN_VARIANT="espressif"
export ESPRESSIF_TOOLCHAIN_PATH="${HOME}/.espressif/tools/xtensa-esp32-elf/esp-2020r3-8.4.0/xtensa-esp32-elf"
export PATH=$PATH:$ESPRESSIF_TOOLCHAIN_PATH/bin
caution

ESPRESSIF_TOOLCHAIN_PATH may be different on your machine. Verify location after the west espressif install step.

Your system is all set up and ready to start building & flashing with Zephyr. Verify by building a minimal sample:

cd ~/zephyrproject/zephyr
west build -b esp32 samples/basic/minimal