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

Setting up Toolchain on Ubuntu with CLion

I'm trying to set up the nRF Connect SDK Toolchain on Ubuntu 20.04.2 LTS x86_64, following this manual.

https://developer.nordicsemi.com/nRF_Connect_SDK/doc/1.5.1/nrf/gs_installing.html#

To get it to work in combination with CLion I'm also using this tutorial.

https://blog.jetbrains.com/clion/2021/04/using-nrf52-with-cmake-connect-sdk/

I created a project and I'm able to build target "zephyr_final" to compile it.
But when I try to execute the target "flash" afterwards, I get this error:

~/.local/share/JetBrains/Toolbox/apps/CLion/ch-0/211.6693.114/bin/cmake/linux/bin/cmake --build ~/git/Project/cmake-build-zdebug-nrf-connect-sdk-v151 --target flash
[0/1] Flashing nrf52dk_nrf52832
usage: west
       [-h]
       [-z ZEPHYR_BASE]
       [-v]
       [-V]
       <command>
       ...
west: error: argument <command>: invalid choice: 'flash' (choose from 'init', 'update', 'list', 'manifest', 'diff', 'status', 'forall', 'help', 'config', 'topdir', 'selfupdate')
FAILED: zephyr/cmake/flash/CMakeFiles/flash
cd ~/git/Project/cmake-build-zdebug-nrf-connect-sdk-v151 && ~/.local/share/JetBrains/Toolbox/apps/CLion/ch-0/211.6693.114/bin/cmake/linux/bin/cmake -E env /usr/bin/python3.8 -m west flash --skip-rebuild
ninja: build stopped: subcommand failed.

Regards,
Mort

  • Hello!

    Have you made sure to follow the Cloning Repositories step of the installation guide by calling: 

    west init -m https://github.com/nrfconnect/sdk-nrf --mr v1.5.1

    The error you're seeing is related to west being uninitialized somehow. Please check the value of the ZEPHYR_BASE environment variable as well.

    Best regards,
    Carl Richard

  • Hey Carl,

    Thanks for the reply.

    The project is in the folder "~/git/Project".
    I already cloned the repository into "~/nordic/ncs/v1.5.1" via "west init".
    When I run "west status" I get the following:

    $ west status
    === status of manifest (nrf):
    HEAD detached at v1.5.1
    nothing to commit, working tree clean
    === status of zephyr (zephyr):
    HEAD detached at refs/heads/manifest-rev
    Untracked files:
      (use "git add <file>..." to include in what will be committed)
    	share/zephyr-package/cmake/current_path.txt
    
    nothing added to commit but untracked files present (use "git add" to track)
    === status of mcuboot (bootloader/mcuboot):
    HEAD detached at refs/heads/manifest-rev
    nothing to commit, working tree clean
    === status of nrfxlib (nrfxlib):
    HEAD detached at refs/heads/manifest-rev
    nothing to commit, working tree clean
    === status of hal_nordic (modules/hal/nordic):
    HEAD detached at refs/heads/manifest-rev
    nothing to commit, working tree clean
    === status of trusted-firmware-m (modules/tee/tfm):
    HEAD detached at refs/heads/manifest-rev
    nothing to commit, working tree clean
    === status of tfm-mcuboot (modules/tee/tfm-mcuboot):
    HEAD detached at refs/heads/manifest-rev
    nothing to commit, working tree clean
    === status of connectedhomeip (modules/lib/connectedhomeip):
    HEAD detached at refs/heads/manifest-rev
    nothing to commit, working tree clean
    === status of cmock (test/cmock):
    HEAD detached at refs/heads/manifest-rev
    Changes not staged for commit:
      (use "git add <file>..." to update what will be committed)
      (use "git restore <file>..." to discard changes in working directory)
    	modified:   vendor/unity (new commits)
    
    no changes added to commit (use "git add" and/or "git commit -a")
    === status of unity (test/cmock/vendor/unity):
    HEAD detached at refs/heads/manifest-rev
    nothing to commit, working tree clean
    === status of mbedtls-nrf (mbedtls):
    HEAD detached at refs/heads/manifest-rev
    nothing to commit, working tree clean
    === status of nanopb (modules/lib/nanopb):
    HEAD detached at refs/heads/manifest-rev
    nothing to commit, working tree clean
    === status of Alexa-Gadgets-Embedded-Sample-Code (modules/alexa-embedded):
    HEAD detached at refs/heads/manifest-rev
    nothing to commit, working tree clean
    === status of cddl-gen (modules/lib/cddl-gen):
    HEAD detached at refs/heads/manifest-rev
    nothing to commit, working tree clean
    === status of cmsis (modules/hal/cmsis):
    HEAD detached at refs/heads/manifest-rev
    nothing to commit, working tree clean
    === status of canopennode (modules/lib/canopennode):
    HEAD detached at refs/heads/manifest-rev
    nothing to commit, working tree clean
    === status of civetweb (modules/lib/civetweb):
    HEAD detached at refs/heads/manifest-rev
    nothing to commit, working tree clean
    === status of fatfs (modules/fs/fatfs):
    HEAD detached at refs/heads/manifest-rev
    nothing to commit, working tree clean
    === status of hal_st (modules/hal/st):
    HEAD detached at refs/heads/manifest-rev
    nothing to commit, working tree clean
    === status of libmetal (modules/hal/libmetal):
    HEAD detached at refs/heads/manifest-rev
    nothing to commit, working tree clean
    === status of lvgl (modules/lib/gui/lvgl):
    HEAD detached at refs/heads/manifest-rev
    nothing to commit, working tree clean
    === status of mbedtls (modules/crypto/mbedtls):
    HEAD detached at refs/heads/manifest-rev
    nothing to commit, working tree clean
    === status of mcumgr (modules/lib/mcumgr):
    HEAD detached at refs/heads/manifest-rev
    nothing to commit, working tree clean
    === status of net-tools (tools/net-tools):
    HEAD detached at refs/heads/manifest-rev
    nothing to commit, working tree clean
    === status of open-amp (modules/lib/open-amp):
    HEAD detached at refs/heads/manifest-rev
    nothing to commit, working tree clean
    === status of loramac-node (modules/lib/loramac-node):
    HEAD detached at refs/heads/manifest-rev
    nothing to commit, working tree clean
    === status of openthread (modules/lib/openthread):
    HEAD detached at refs/heads/manifest-rev
    nothing to commit, working tree clean
    === status of segger (modules/debug/segger):
    HEAD detached at refs/heads/manifest-rev
    nothing to commit, working tree clean
    === status of tinycbor (modules/lib/tinycbor):
    HEAD detached at refs/heads/manifest-rev
    nothing to commit, working tree clean
    === status of tinycrypt (modules/crypto/tinycrypt):
    HEAD detached at refs/heads/manifest-rev
    nothing to commit, working tree clean
    === status of littlefs (modules/fs/littlefs):
    HEAD detached at refs/heads/manifest-rev
    nothing to commit, working tree clean
    === status of mipi-sys-t (modules/debug/mipi-sys-t):
    HEAD detached at refs/heads/manifest-rev
    nothing to commit, working tree clean
    === status of nrf_hw_models (modules/bsim_hw_models/nrf_hw_models):
    HEAD detached at refs/heads/manifest-rev
    nothing to commit, working tree clean
    === status of edtt (tools/edtt):
    HEAD detached at refs/heads/manifest-rev
    nothing to commit, working tree clean                

    My ZEPHYR_BASE Path points to "~/nordic/ncs/v1.5.1/zephyr"
    Here is a list of the other env variables that I set.

    BOARD=nrf52dk_nrf52832;
    ZEPHYR_BASE=~/nordic/ncs/v1.5.1/zephyr;
    GIT_EXEC_PATH=/usr/bin/git-core;
    ZEPHYR_TOOLCHAIN_VARIANT=gnuarmemb;
    GNUARMEMB_TOOLCHAIN_PATH=~/gnuarmemb;
    DEVICE=S113;
    PATH=~/gnuarmemb/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

    Additionally the output of CMake when I reset the cache and reload the project:

    /home/user/.local/share/JetBrains/Toolbox/apps/CLion/ch-0/211.6693.114/bin/cmake/linux/bin/cmake -DCMAKE_BUILD_TYPE=ZDebug -DCMAKE_C_COMPILER=/home/user/gnuarmemb/bin/arm-none-eabi-gcc -DCMAKE_CXX_COMPILER=/home/user/gnuarmemb/bin/arm-none-eabi-g++ -G Ninja /home/user/git/Project
    Including boilerplate (Zephyr base): /home/user/nordic/ncs/v1.5.1/zephyr/cmake/app/boilerplate.cmake
    -- Application: /home/user/git/Project
    -- Zephyr version: 2.4.99 (/home/user/nordic/ncs/v1.5.1/zephyr)
    -- Found Python3: /usr/bin/python3.8 (found suitable exact version "3.8.5") found components: Interpreter 
    -- Found west (found suitable version "0.10.1", minimum required is "0.7.1")
    -- Board: nrf52dk_nrf52832
    -- Cache files will be written to: /home/user/.cache/zephyr
    -- Found toolchain: gnuarmemb (/home/user/gnuarmemb)
    -- Found BOARD.dts: /home/user/nordic/ncs/v1.5.1/zephyr/boards/arm/nrf52dk_nrf52832/nrf52dk_nrf52832.dts
    -- Generated zephyr.dts: /home/user/git/Project/cmake-build-zdebug-nrf-connect-sdk-v151/zephyr/zephyr.dts
    -- Generated devicetree_unfixed.h: /home/user/git/Project/cmake-build-zdebug-nrf-connect-sdk-v151/zephyr/include/generated/devicetree_unfixed.h
    -- Generated device_extern.h: /home/user/git/Project/cmake-build-zdebug-nrf-connect-sdk-v151/zephyr/include/generated/device_extern.h
    Parsing /home/user/nordic/ncs/v1.5.1/zephyr/Kconfig
    Loaded configuration '/home/user/git/Project/cmake-build-zdebug-nrf-connect-sdk-v151/zephyr/.config'
    No change to configuration in '/home/user/git/Project/cmake-build-zdebug-nrf-connect-sdk-v151/zephyr/.config'
    No change to Kconfig header in '/home/user/git/Project/cmake-build-zdebug-nrf-connect-sdk-v151/zephyr/include/generated/autoconf.h'
    -- The C compiler identification is GNU 9.2.1
    -- The CXX compiler identification is GNU 9.2.1
    -- The ASM compiler identification is GNU
    -- Found assembler: /home/user/gnuarmemb/bin/arm-none-eabi-gcc
    CMake Deprecation Warning at /home/user/nordic/ncs/v1.5.1/modules/lib/civetweb/CMakeLists.txt:2 (cmake_minimum_required):
      Compatibility with CMake < 2.8.12 will be removed from a future version of
      CMake.
    
      Update the VERSION argument <min> value or use a ...<max> suffix to tell
      CMake that the project does not need compatibility with older versions.
    
    
    -- Configuring done
    -- Generating done
    -- Build files have been written to: /home/user/git/Project/cmake-build-zdebug-nrf-connect-sdk-v151
    
    [Finished]
    

    Regards,

    Mort

  • Hi again, Mort!

    Is the ZEPHYR_BASE in this instance the one you passed through in step 5.2 of the JetBrains tutorial or is it globally defined? If only the former it could be that west is unaware of the definition of ZEPHYR_BASE. You can read more about troubleshooting this issue in the documentation.

    Best regards,
    Carl Richard

  • Hi,

    ZEPHYR_BASE was passed like it was described in step 5.2.
    I added the ZEPHYR_BASE variable to "/etc/enviroment".

    $ cat /etc/environment
    PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin"
    ZEPHYR_BASE="/home/user/nordic/ncs/v1.5.1/zephyr" 

    So now when I try use the flash target in CLion:

    ====================[ Build | flash | ZDebug-nRF Connect SDK v1.5.1 ]===========
    /home/user/.local/share/JetBrains/Toolbox/apps/CLion/ch-0/211.6693.114/bin/cmake/linux/bin/cmake --build /home/user/git/Project/cmake-build-zdebug-nrf-connect-sdk-v151 --target flash
    [0/1] Flashing nrf52dk_nrf52832
    usage: west
           [-h]
           [-z ZEPHYR_BASE]
           [-v]
           [-V]
           <command>
           ...
    west: error: argument <command>: invalid choice: 'flash' (choose from 'init', 'update', 'list', 'manifest', 'diff', 'status', 'forall', 'help', 'config', 'topdir', 'selfupdate')
    FAILED: zephyr/cmake/flash/CMakeFiles/flash 
    cd /home/user/git/Project/cmake-build-zdebug-nrf-connect-sdk-v151 && /home/user/.local/share/JetBrains/Toolbox/apps/CLion/ch-0/211.6693.114/bin/cmake/linux/bin/cmake -E env /usr/bin/python3.8 -m west flash --skip-rebuild
    ninja: build stopped: subcommand failed.

    When I use the same command "" CLion used but in my own console: 

    [~/git/Project] $ echo $ZEPHYR_BASE                                                                                                                                                                               
    /home/user/nordic/ncs/v1.5.1/zephyr
    
    [~/git/Project] $ /home/user/.local/share/JetBrains/Toolbox/apps/CLion/ch-0/211.6693.114/bin/cmake/linux/bin/cmake --build /home/user/git/Project/cmake-build-zdebug-nrf-connect-sdk-v151 --target flash
    [0/1] Flashing nrf52dk_nrf52832
    -- west flash: using runner nrfjprog
    Using board 683723195
    -- runners.nrfjprog: Flashing file: /home/user/git/Project/cmake-build-zdebug-nrf-connect-sdk-v151/zephyr/zephyr.hex
    Parsing image file.
    Erasing page at address 0x0.
    Erasing page at address 0x1000.
    Erasing page at address 0x2000.
    Erasing page at address 0x3000.
    Erasing page at address 0x4000.
    Applying system reset.
    Checking that the area to write is not protected.
    Programming device.
    Enabling pin reset.
    Applying pin reset.
    -- runners.nrfjprog: Board with serial number 683723195 flashed successfully.      

    When I simply call "west flash" in the build folder:

    [~/git/Project/cmake-build-zdebug-nrf-connect-sdk-v151] $ west flash
    -- west flash: rebuilding
    [0/1] cd /home/user/git/Project/cmake-build-zdebug-nrf-connect-sdk-v151/zephyr/cmake/flash && /home/user/.local/share/JetBrains/Toolbox/apps/CLion/ch-0/211.6693.114/bin/cmake/linux/bin/cmake -E echo
    
    -- west flash: using runner nrfjprog
    Using board 683723195
    -- runners.nrfjprog: Flashing file: /home/user/git/Project/cmake-build-zdebug-nrf-connect-sdk-v151/zephyr/zephyr.hex
    Parsing image file.
    Erasing page at address 0x0.
    Erasing page at address 0x1000.
    Erasing page at address 0x2000.
    Erasing page at address 0x3000.
    Erasing page at address 0x4000.
    Applying system reset.
    Checking that the area to write is not protected.
    Programming device.
    Enabling pin reset.
    Applying pin reset.
    -- runners.nrfjprog: Board with serial number 683723195 flashed successfully.      

    To me this seems like a problem with CLion and CMake, but I'm not really sure how to debug that.
    Anyway flashing, even if it is via command line works now.

    Thanks for the help,

    Mort

    Edit: I think it is pretty strange, as CLion sees the already set ZEPHYR_BASE Variable. It uses it when loading the CMake Project ("-- Zephyr version: 2.4.99 (/home/user/nordic/ncs/v1.5.1/zephyr)") and builts the target "zephyr_final" without problems. Then, when it should build the target "flash" it does gives the error, as seen in the second snippet.

  • Hi again!

    Great to hear that it works using the command line. I'm not sure how to fix the problem with CLion/CMake either, but I suggest reaching out on to JetBrains on the issue aswell. It's likely just a problem with the project configuration.

    Best regards,
    Carl Richard

Related