This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Build nRF Connect SDK Project via Command Line

Hi,

I'm working on an application for the nRF9160 using the nRF Connect SDK. I want to integrate this app into our build system and thus would like to be able to build the project via the command line. One thing I'm concerned about is what operations Segger EM Studio is doing behind the scenes when you click "Open nRF Connect SDK Project... ". Doing this links all of the Zephyr files as well as the GNU ARM Embedded Toolchain files.

So my question is, Is there a way to replicate this on our build server using the command line?

- Jack

Parents
  • Hi Jack,

    Just adding to what jbrzozoski is referring to:


    • When using the command line you need to define the environment variables for the GNU Arm Embedded toolchain:

    export ZEPHYR_TOOLCHAIN_VARIANT=gnuarmemb
    export GNUARMEMB_TOOLCHAIN_PATH=/c/gnuarmemb

    • Set up build environment

    cd $NCS_BASE/zephyr
    source zephyr-env.sh

    cd $NCS_BASE/nrf/samples/nrf9160/mqtt_simple/
    mkdir build && cd build
    
    # Use cmake to configure a Ninja-based build system:
    cmake -GNinja -DBOARD=nrf9160_pca10090ns ..
    
    # Now run ninja on the generated build system:
    ninja
    ninja flash

    Also worth noticing that there is a difference when building Secure/Non-Secure Zephyr applications.


    Extra tip:

    To flash precompiled .hex files you can either use the nRF Connect Programmer application or do it via command line nrfjprog:

    nrfjprog --program <application>.hex -f nrf91 --sectorerase -r --verify
    

    Best Regards,
    Martin L.

  • Hi, I'm trying to build the coap_client application using the command line on Windows since I'm having problems using Segger.
    I already flashed the Secure Boot, now I'm trying using this commands

    cd C:\Nordic_SDK\ncs\zephyr

    zephyr-env.cmd

    set ZEPHYR_TOOLCHAIN_VARIANT=gnuarmemb

    set GNUARMEMB_TOOLCHAIN_PATH = “C:\Program Files (x86)\GNU Tools ARM Embedded\8 2018-q4-major”

    cd C:\Nordic_SDK\ncs\nrf\samples\nrf9160\coap_client

    mkdir build && cd build

    cmake .. -DBOARD=nrf9160_pca10090ns -GNinja

    ninja flash

    But then it reports the following message

    C:\Nordic_SDK\ncs\nrf\samples\nrf9160\coap_client\build>cmake .. -DBOARD=nrf9160_pca10090ns -GNinja
    Zephyr version: 1.14.0
    -- Found PythonInterp: C:/Python37/python.exe (found suitable version "3.7.2", minimum required is "3.4")
    -- Selected BOARD nrf9160_pca10090ns
    CMake Error at C:/Nordic_SDK/ncs/zephyr/cmake/extensions.cmake:1104 (message):
    Assertion failed: GNUARMEMB_TOOLCHAIN_PATH is not set
    Call Stack (most recent call first):
    C:/Nordic_SDK/ncs/zephyr/cmake/toolchain/gnuarmemb/generic.cmake:11 (assert)
    C:/Nordic_SDK/ncs/zephyr/cmake/generic_toolchain.cmake:55 (include)
    C:/Nordic_SDK/ncs/zephyr/cmake/app/boilerplate.cmake:395 (include)
    CMakeLists.txt:9 (include)

    It says that the Toolchain Path is not set but I set it with the Gnuarmemb Path I set in the Getting Started Assistant to verify if the Toolchain was correctly installed. Do I have to set a different path?

    Thanks in advance for any clarification you can give me.

    On a side note, will it be possible to build projects using Segger soon? Everytime I try to build a project it gives me an error unless I switch to the v3.0.0 release and then it works.

  • Hello Marco,

    1. I would recommend you to switch to the version 7-2018-q2-update, since the newest version (8-2018-q4-major) has a critical bug and should not be used.
    2. I think the issue can be the same as Hellesvik is experiencing in this thread.

    (There may also be an issue with spaces in the paths)

    Here is my path to the ARM Toolchain: 

    I set:

     export GNUARMEMB_TOOLCHAIN_PATH=/c/gnuarmemb

    and here is what's in this path: C:\gnuarmemb\arm-none-eabi\


    There is a Segger release that is coming very soon, I can update you when it's ready.

    Best Regards,

    Martin L.

  • Thank you for the information, I will try reinstalling the toolchain. 
    It would be great if you could update me on the Segger release. Do you know if it's a matter of weeks or months for its release?

  • Hi, after switching to the version “7-2018-q2-update” of the toolchain I was able to go past that issue but I still cannot compile my project. I tried both using cmake+ninja and west but it reports the same problem.
    This is the output after using cmake (the same issue applies when I try to use the secure_boot application before using coap_client).

    It seems that I cannot compile my project since there is no .hex file in the zephyr folder, even though it writes some build files to the build folder.

    Do you have any ideas on how to solve this problem?

Reply
  • Hi, after switching to the version “7-2018-q2-update” of the toolchain I was able to go past that issue but I still cannot compile my project. I tried both using cmake+ninja and west but it reports the same problem.
    This is the output after using cmake (the same issue applies when I try to use the secure_boot application before using coap_client).

    It seems that I cannot compile my project since there is no .hex file in the zephyr folder, even though it writes some build files to the build folder.

    Do you have any ideas on how to solve this problem?

Children
  • Hi Marco,

    Does this happen for every sample?

    If not, then there may be an issue with the build files.

    Please clean the folder:

    rm *-r

    and try to build again.


    Another suggestion is to update the master branch in the nrf repo.

    git pull

    And the rest of the repoes (easiest if you have west).

    west update


    Extra tip:

    Optional, you can use the West tool to build/flash applications as well.

    #using west to build
    west build -b nrf9160_pca10090ns -d build
    
    #using west to flash
    west flash -d build

    (b = board; d = directory)

    (another neat thing when using west is that you do not need to set up the build environment before you build the application)

  • Hi, thanks again for the help.

    I tried reinstalling the SDK and checked out if all the repositories were up to date, then I used west to build both the secure_boot sample and the at_client but I got the same result. This is what I get with the secure_boot (same error as when using cmake and ninja).

    Could it be a problem with my computer and not with the build files?

    • Does this happen for every sample?
    • Can you confirm the build folder is clean?
  • Yes, it does happen for every sample and the build folder is clean.

    Here is my input (here I was building the coap_client)

    and I get the same result

    With this CMakeError file written in the build folder

    Compiling the C compiler identification source file "CMakeCCompilerId.c" failed.
    Compiler: C:/gnuarmemb/bin/arm-none-eabi-gcc.exe 
    Build flags: 
    Id flags:  
    
    The output was:
    1
    c:/gnuarmemb/bin/../lib/gcc/arm-none-eabi/7.3.1/../../../../arm-none-eabi/lib\libc.a(lib_a-exit.o): In function `exit':
    exit.c:(.text.exit+0x2c): undefined reference to `_exit'
    collect2.exe: error: ld returned 1 exit status
    
    
    Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" failed.
    Compiler: C:/gnuarmemb/bin/arm-none-eabi-gcc.exe 
    Build flags: 
    Id flags:  
    
    The output was:
    1
    c:/gnuarmemb/bin/../lib/gcc/arm-none-eabi/7.3.1/../../../../arm-none-eabi/lib\libc.a(lib_a-exit.o): In function `exit':
    exit.c:(.text.exit+0x2c): undefined reference to `_exit'
    collect2.exe: error: ld returned 1 exit status
    
    
    

  • Hi Marco, 
    I appreciate that you have made a seperate ticket for your issue since it's unrelated to the original post.
    I will follow up the other case!

    Best Regards,

    Martin L.

Related