Federico Fuga

Engineering, Tech, Informatics & science

Fixing Zephyr Environment on Linux

03 Dec 2022 11:58 CET

I’m actually experimenting with Zephyr, a Real Time O.S. for IoT devices.

It seems very impressive for many aspects, that, out of the topic of this blog post, I list here.

  • It’s a fully fledged microkernel with many drivers for peripherals and protocols
  • It supports many important protocols like Wifi, Bluetooth Low Energy, OpenThread (and Matter) and many others
  • It’s supported and financed by Nordic Semiconductors,
  • It’s open source
  • It has many hardware supporting it, including Nordic chipset, STM, Espressif, Raspberry, etc…
  • It has an extension for Visual Studio and others IDE are supporting it, like, for example, Jetbrain’s CLion

So I decided it’s time to test it. I have a couple of pet projects ongoing, many supported boards, and a couriosity to test OpenThread, why not starting with Zephyr?

So I followed the Nordic’s instructions for installing the Nrf Connect SDK on my linux box, but.. it didn’t work.

The Issue

Once you have followed all the instructions from Nordic on how to start with the Microsoft Visual Studio Extension, you follow the getting started chapter to start esperimenting, but first you get in trouble.

After having compiled and tested a sample from the sdk, you may want to build an application from scratch.

Unfortunately here starts the issues.

The Wizard for creating a new app

When you complete the Wizard, see image above, and click on the Create Application Button, the procedure stops with an error.

[west]: updating /home/user/Tutorial/hello/hello_world...

[west]: === updating sdk-nrf (nrf):
[west]: --- sdk-nrf: initializing
[west]: warning: templates not found in /opt/ncs/toolchains/v2.1.2/usr/share/git-core/templates
[west]: Initialized empty Git repository in /home/user/Tutorial/hello/nrf/.git/
[west]: --- sdk-nrf: fetching, need revision v2.2.0-rc1
[west]: fatal: unable to find remote helper for 'https'
[west]: FATAL ERROR: command exited with status 128: fetch -f --tags --depth 1 -- https://github.com/nrfconnect/sdk-nrf v2.2.0-rc1

[west]: exited with code 128.

Reinstalling / upgrading / swearing will not help and fix the issue, because the SDK installation is broken.

Investigating the issue you, you can spot that the problem seems related to git. Indeed there’s a script that is launched when updating the sdk, that is the git-remote-http.

Let’s open a nrf connect terminal - use the “terminal” pad and switch to “nrf connect” by hitting the proper entry in the dropdown menu.

The Wizard for creating a new app

Do you spot the issue? No? PYTHONHOME and PYTHONPATH points to a virtual environment but the program name points to the system executable. If the versions differ, you have trouble.

The issue was notified in the Nordic Forum 6 months ago, by the way. Ehi, Nordic, are you listening?

Unfortunately it is not very easy to fix this. It seems the sdk is a bit screwed so the best solution is to install everything manually as explained in this zephyr page.

The step is after 6, “Installing nRF Connect Visual Studio Extesion” not clear: you need to install the nrf command line tools manually. They simply mention that the nrfjprog command should (really, must) be reachable in PATH. But Visual Studio disagrees and is not happy:

Visual Studio is unable to reach nrfjprog.

Unfortunately there’s a nrfjprog.py in the Nrf Connect SDK, but it’s not what they intend.

To fix this, you must manually install the Nrf Command Line Tools bundle by downloading it from Nordic Download Page, and use whatever method fits with your system - in my case, dpkg with the .deb package works well.

After this, problem fixed. Visual Studio doesn’t complain anymore about the missing nrfjprog, but… it will silently accept the situation and fail afterwards, when it will fail to detect the SDK! You need to manually add the path of the SDK, or install the SDK using the Nordic Installer.

After that, you should be able to compile some sample code from the Zephyr SDK.