nRF Connect: How to build from command line after doing automatic install

I followed the instructions to install the nRF Connect SDK using the automatic method:

http://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/gs_assistant.html

That worked and I was able to build sample applications and run them on the DK. Now I would also like the ability to build from the command line. The instructions say you need to start a new shell from the toolchain manager. This also works. However I cannot build from the shell if I start the shell without using the toolchain manager. How can I do that?

It seems my build problems are fixed if I set the environment variable ZEPHYR_SDK_INSTALL_DIR. I noticed this variable is set when I start my shell from the Toolchain Manager but it is not set when I launch a shell normally. 

ZEPHYR_SDK_INSTALL_DIR=/opt/nordic/ncs/toolchains/v2.1.0/opt/zephyr-sdk

So.. If I start a regular shell (without using toolchain manager) and set this variable the builds are working. Is this a valid way to use the SDK? 

Parents Reply Children
  • Wow! Thank you for noting this!

    Now, if only they would allow us to just have it update the environment so different builds could actually work again that would be nice. Or am I missing something?

  • When using docker with sdk 2.5.1 I found the execution of single unit tests via west build no longer worked. Changing to the right folder was no longer possible as the launching of a shell via the entry point meant I would either have a shell with environment that did not handle the commands, or a shell without the environment that would.

    Using the nrfutil command Peter posted allowed preparing the shell and then west build could run the specific unit tests again. The big question is, what is the intended way of running a single test seeing how this seems like a workaround?

  • OMG, what a mission. Here's what worked for me on macOS, based on your excellent suggestion:

    1. I couldn't find nrfutil anywhere on my system despite much searching, so I downloaded it fresh from https://www.nordicsemi.com/Products/Development-tools/nrf-util
    2. It just comes as a binary, so then I put it on my path with:  sudo mv ~/Downloads/nrfutil /usr/local/bin/
    3. And made it executable: sudo chmod 755 /usr/local/bin/nrfutil
    4. And then worked around the developer signing issue by opening the folder in Finder with open /usr/local/bin , right-clicking the file, selecting "Open", and approving the unverified executable.
    5. I still couldn't run the command until I installed toolchain manager with nrfutil install toolchain-manager
    6. Finally, the command worked and the output looked good: nrfutil toolchain-manager env --as-script
    7. Then to tie it all together, I exported the contents to the file that gets picked up by zephyr-env.sh with nrfutil toolchain-manager env --as-script > ~/.zephyrrc
    8. Now "all" I need to do is open a terminal and run one command to get a build environment: source /opt/nordic/ncs/v2.3.0/zephyr/zephyr-env.sh

    Phew! I don't know why these basics are so hard...

Related