Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ysyyork/9ecffbd761921f83f4fb2d50ffe7328b to your computer and use it in GitHub Desktop.
Save ysyyork/9ecffbd761921f83f4fb2d50ffe7328b to your computer and use it in GitHub Desktop.
Zephyr test ubuntu 22.04 env setup
# 1. Install docker engine
for pkg in docker.io docker-doc docker-compose podman-docker containerd runc; do sudo apt-get remove $pkg; done
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
echo \
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y
sudo usermod -aG docker $USER
# 2. Setup zephyr env on the ubuntu host. Docker needs the udev rules mainly cus USB in docker depends on the host system
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 libmagic1
cd ~
wget https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.16.1/zephyr-sdk-0.16.1_linux-x86_64.tar.xz
wget -O - https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.16.1/sha256.sum | shasum --check --ignore-missing
tar xvf zephyr-sdk-0.16.1_linux-x86_64.tar.xz
cd zephyr-sdk-0.16.1
./setup.sh
sudo cp ~/zephyr-sdk-0.16.1/sysroots/x86_64-pokysdk-linux/usr/share/openocd/contrib/60-openocd.rules /etc/udev/rules.d
sudo udevadm control --reload
# 3. Pull and run the docker image
docker pull ysyyork/zephyr_test:1.0.0
# Plug in your nrf5340 first!
docker run -dit --name=zephyr_test1 -e HTTP_PROXY=http://192.168.0.174:1087 -e HTTPS_PROXY=http://192.168.0.174:1087 --network=host -v /media:/media -v /home:/home --privileged ysyyork/zephyr_test:1.0.0 bash
# 4. Get into docker container to build and flash programs
docker exec -it zephyr_test1 bash
# After running the above command, you will get into the docker container with all the env setup already.
cd ~/zephyrproject/zephyr/
# This will be the main zephyr project folder and you can pick different samples inside to run
## build and flash the netcore hci rpmsg program
west build -p always -b nrf5340dk_nrf5340_cpunet samples/bluetooth/hci_rpmsg
west flash
## build and flash the appcore bluetooth periphral program
west build -p always -b nrf5340dk_nrf5340_cpuapp samples/bluetooth/peripheral
west flash
# To test if it's working, on your phone, search for nRF Toolbox. install that app. Open it, press Heart Rate tab. then Press Connect. You should see a device called "Zephyr Peripheral Sample Long". Tap it and you can connect.
# To run HID example
# Add this line "CONFIG_SAMPLE_BT_USE_AUTHENTICATION=n" to the prj.conf file under samples/bluetooth/peripheral_hids. Then build and flash to cpuapp core
west build -p always -b nrf5340dk_nrf5340_cpuapp samples/bluetooth/peripheral_hids
west flash
# Please note, you need to have the hci_rpmsg flashed to the cpunet core first as stated in 8. Then you should be able to search for this device in your laptop bluetooth panel. Once connected, you can click button 1 on board to
# simulate mouse left click. Since it's a sample, it only has that one button functional.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment