Skip to end of banner
Go to start of banner

Debug Zephyr app on Nitrogen board with OpenOCD

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 9 Next »

Setup prerequisites and build Zephyr demo app

Install Prerequisites:

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install git 
sudo apt install build-essential ncurses-dev doxygen dfu-util device-tree-compiler

Download zephyr from git mirror:

git clone https://gerrit.zephyrproject.org/r/zephyr

Download zephyr-sdk from the link below:

https://github.com/zephyrproject-rtos/meta-zephyr-sdk/releases/download/0.9.1/zephyr-sdk-0.9.1-setup.run

chmod +x zephyr-sdk-<version>-setup.run
./zephyr-sdk-<version>-setup.run

To use the Zephyr SDK, export the following environment variables:

export ZEPHYR_GCC_VARIANT=zephyr
export ZEPHYR_SDK_INSTALL_DIR=<zephyr-sdk-path>/zephyr-sdk/

To use the same toolchain in new sessions in the future create file ~/.zephyrrc

cat <<EOF > ~/.zephyrrc
export ZEPHYR_GCC_VARIANT=zephyr
export ZEPHYR_SDK_INSTALL_DIR=<zephyr-sdk-path>/zephyr-sdk/
EOF

Build Zephyr Hello World sample application

cd <zephyr_root_path>
. zephyr-env.sh
cd samples/hello_world/
make BOARD=96b_nitrogen

Flashing, Running and Debugging using pyOCD

Install Prerequisites:

sudo apt-get install python-pip python-dev python-yaml minicom gdb-arm-none-eabi
sudo -H pip install --upgrade pip
sudo -H pip install --pre -U pyocd

Verify board is detected by pyOCD

sudo pyocd-flashtool -l

Erase the flash memory in the nRF52832

sudo pyocd-flashtool -d debug -t nrf52 -ce

Flash the Hello World application

cd <zephyr_root_path>
sudo pyocd-flashtool -d debug -t nrf52 samples/hello_world/outdir/96b_nitrogen/zephyr.hex

Run minicom to listen for output

sudo minicom -D /dev/ttyACM0 -b 115200

Press reset button on nitrogen board to verify following output

Hello World! arm

Start pyocd-gdbserver in a new terminal window and launch debug session

sudo pyocd-gdbserver
arm-none-eabi-gdb outdir/96b_nitrogen/zephyr.elf
target remote localhost:3333

Flashing, Running and Debugging using openOCD

Build OpenOCD: 

Follow Getting started with OpenOCD Development to build openOCD from sources.

Spawn openOCD connection to Nitrogen Board:

/src/openocd -s tcl/ -f interface/cmsis-dap.cfg -c "transport select swd" -f target/nrf52.cf
arm-none-eabi-gdb outdir/96b_nitrogen/zephyr.elf
target remote localhost:3333
target remote localhost:3333

Adding udev rule:

At this point you might be able to use OpenOCD without any issue. However, chances are that you will face with this error message when you try to use OpenOCD on the terminal.


Assuming that you have your board connected, this is likely to be caused by the current user not having the right access permission to your board USB HID driver. You can verify this by running OpenOCD as root using sudo. However, if we are planning on using OpenOCD with an IDE (for example Eclipse) or some other development environment, then to make our life a little easier we should add a system rule that will automatically mount the our board usb with an open permission so that any user can use it. To do this, we need to first find out our board USB vendor and product id. We can do this by running the USB list command. However, we may need to run this command a few times with and without the board connected to identify which of the USB devices listed belong to our board.


lsusb

You should get a message like this.

lsusb

These are two set of hexadecimal characters that you need to make a note of for your device.

lsusb - with lable

Using this command we are going to create a new udev rule for our USB device. This command will simply create a new text file in the udev rule.d folder which will be invoked when ever out board is connected.

sudo nano /etc/udev/rules.d/CMSIS.rules

linux CMSIS rules nano

Type in the following lines into the new file. Make sure that you replace the idVendor and idProduct hexadecimal values between the double quotes with the ones that you noted earlier.


KERNEL=="hidraw*", ATTRS{idVendor}=="0d28", ATTRS{idProduct}=="0204", MODE="0666"
SUBSYSTEM=="usb", ATTRS{idVendor}=="0d28", MODE="0666"
SUBSYSTEM=="usb_device", ATTRS{idVendor}=="0d28", MODE="0666"


CMSIS udev Rule STM32


To save the file, press Ctrl+X. Then Press Y and to accept and exit the editor press Enter. You will need to reboot your computer for the new changes to take effect but apart from that you are ready to start using OpenOCD.

To install the latest development version (master branch), do the following:

pip install --pre -U git+https://github.com/mbedmicro/pyOCD.git#egg=pyOCD

Common Errors:

No connected boards / No available boards are connected

If you don’t use sudo when invoking pyocd-flashtool, you might get any of these errors


To fix the permission issue, simply add the following udev rule for the NXP LPC1768 interface:

echo 'ATTR{idProduct}=="0204", ATTR{idVendor}=="0d28", MODE="0666", GROUP="plugdev"' > /etc/udev/rules.d/50-cmsis-dap.rules

Flashing an Application to 96Boards Nitrogen:

This example uses the Hello World sample with the pyOCD tools. Use the make flash build target to build your Zephyr application, invoke the pyOCD flash tool and program your Zephyr application to flash.

cd <zephyr_root_path>
. zephyr-env.sh
cd samples/hello_world/
make BOARD=96b_nitrogen

References:

  • No labels