Debug Zephyr app on Nitrogen board with OpenOCD

Nitrogen is a 96Boards compliant IoT Edition board and is a low cost option for debugging Arm Cortex M support in OpenOCD. This guide provides a quick setup guide for Nitrogen board with the outcome of debugging OpenOCD code related to Arm Cortex M support.

Prerequisite: Set up OpenOCD development environment

Host Environment: Ubuntu version 18.04

Hardware requirements:

  • Nitrogen Board
  • Micro USB cable

Build Zephyr Blinky demo for Nitrogen board:

Zephyr getting started guide[1] provides a step by step guide to set up Zephyr build environment and build a LED blinking demo for Nitrogen board. Following steps are taken from Zephyr getting started guide and more details can be found here[1].

Install dependencies:

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: Update cmake version if cmake --version returns < 3.13.1

Get Zephyr and install Python dependencies:

# Install west, and make sure ~/.local/bin is on your PATH environment variable:
pip3 install --user -U west
echo 'export PATH=~/.local/bin:"$PATH"' >> ~/.bashrc
source ~/.bashrc

# Get the Zephyr source code:
west init ~/zephyrproject
cd ~/zephyrproject
west update

# Export a Zephyr CMake package. This allows CMake to automatically load boilerplate code    # required for building Zephyr applications.
west zephyr-export

# Zephyr's scripts/requirements.txt file declares additional Python dependencies. Install them    # with pip3.
pip3 install --user -r ~/zephyrproject/zephyr/scripts/requirements.txt

Install a Toolchain:

# Download the latest SDK installer:
wget https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.11.3/zephyr-sdk-0.11.3-setup.run

# Run the installer, installing the SDK in /opt/zephyr-sdk-0.11.3:
chmod +x zephyr-sdk-0.11.3-setup.run
Sudo ./zephyr-sdk-0.11.3-setup.run -- -d /opt/zephyr-sdk-0.11.3

Build blinky demo and load it up using GDB via OpenOCD:

# Run from the root of the zephyr repository eg: ~/zephyrproject/zephyr
west build -p auto -b 96b_nitrogen samples/basic/blinky

# Connect Nitrogen board to host computer via micro usb cable
# Wait for the MBED folder to mount automatically
# Run OpenOCD from its source folder
./src/openocd -s tcl/ -f interface/cmsis-dap.cfg -c "transport select swd" -f target/nrf52.cfg

# Start gdb and load blinky demo onto Nitrogen board's flash memory
/opt/zephyr-sdk-0.11.3/arm-zephyr-eabi/bin/arm-zephyr-eabi-gdb ~/zephyrproject/zephyr/build/zephyr/zephyr.elf -ex 'target remote :3333' -ex 'monitor halt' -ex 'monitor reset' -ex load

Expected output of OpenOCD console after successfully connecting with Nitrogen board


Expected output of GDB console after successfully loading blinky demo: 

References:

  1. https://docs.zephyrproject.org/latest/getting_started/index.html
  2. https://docs.zephyrproject.org/latest/boards/arm/96b_nitrogen/doc/index.html