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
  • Let me add some background here. When I started using nRF Connect I chose the automatic installation method. This seems like the best choice to get started quickly. Then I enrolled in the nRF Connect SDK Fundamentals course. So far so good. But now I started using some of the sample projects and they all seem to use the command line to build & flash. This works fine if you open the terminal from the toolchain manager. What is not clear to me is how to switch between command line and VS Code on the same project. For example, some of the example projects use kconfig overlay files which are listed on the build commands. If I switch over to VS Code I guess I need to edit the application setup and add the kconfig file there? This behavior is new to me. I'm used to running 'make' from the command line with no options because all the details are stored in the makefiles. Then your IDE can just run the same make command. 

    In short, I was hoping to learn how to use VS Code and the command line on the same project. In the short term I want to make this work for the sample projects but later I need to get the same behavior working with my own project.

  • Hello,

    The thing that happens when you start the shell from toolchain manager is that it sets up the environmental variables for a given SDK version.

    You can add those variables by yourself if desired in your ~/.bashrc file for example.

    VS Code runs the same west commands under the hood as you would in the terminal. There should be no need to do things differently.

    When you build in VS Code you should be able to see the exact command used to build the application in the compiler output.

    Best regards,

    Michal

  • I compared the env vars between a regular shell and the ‘ncs’ shell and manually copied over the changes to my shell. Seems crude but so far it seems to work. As for vs code, I did figure out how to build the app using vs code, but the trick was manually configuring the extra kconfig files required by the app. You can close this out. 

  • Hello,

    Thank you for the information, I will close it then.

    Best regards,

    Michal

  • Is there a script or batch file we can execute that is equivalent to starting the shell from the toolchain manager? This way, we can always just execute that script or batch file and it will work with any updates/changes from Nordic.

  • I could not find one so I made my own. 

    # nRF Connect
    export NCS_SDK=/opt/nordic/ncs/v2.1.0
    export NCS_TOOLCHAIN=/opt/nordic/ncs/toolchains/v2.1.0
    export ZEPHYR_SDK_INSTALL_DIR=$NCS_TOOLCHAIN/opt/zephyr-sdk
    export PATH=$PATH:$NCS_TOOLCHAIN/bin:$NCS_TOOLCHAIN/usr/bin:$NCS_TOOLCHAIN/usr/local/bin:$NCS_TOOLCHAIN:/opt/bin:$NCS_TOOLCHAIN/opt/nanopb/generator-bin:$NCS_TOOLCHAIN/opt/zephyr-sdk/arm-zephyr-eabi/bin
    # source $NCS_SDK/zephyr/zephyr-env.sh

  • Thank you for sharing. Unfortunately, this will break if you update the SDK. I really would like to see Nordic provide a script file.

    The Toolchain manager uses the Nordic script and also VSCode->Terminal->+->nRF Connect does.

    I tried to find the script location but was not able to.

Reply Children
  • This is the source for Toolchain Manager v1.2.1 that launches the terminal:

    github.com/.../terminal.ts

    For Windows, looks like they use: nrfutil-toolchain-manager.exe in:
    c:\Users\<YOUR ALIAS>>\.nrfconnect-apps\node_modules\pc-nrfconnect-toolchain-manager\resources\nrfutil-toolchain-manager\win32

    There is a similar directory for Linux, Apple, etc. The "win32" changes to the appropriate name for the OS.

    I really hope Nordic will provide a "nRFCmdStart" or something like that that does the equivalent of above.

Related