Missing Include Path for nRF Connect v2.00 Build Under Visual Studio Code Using nRF Connect Extension

I am trying to upgrade from nRF Connect SDK v1.6.1, running under Ubuntu 18.04 using the Nordic Edition of SEGGER Embedded Studio as the Integrated Development Environment, to nRF Connect SDK v2.00, running under Ubuntu 20.04 using Microsoft Visual Studio Code. To set up the toolchain and the nRF Connect SDK v2.00 under Ubuntu 20.04, I followed the instructions under Getting Started Assistant v.2.0.2 steps 1-5 (excluding 6-7 which apply to SEGGER Embedded Studio) in nRF Connect for Desktop, then under the Toolchain Manager I installed NRF Connect SDK v2.00. Finally, I opened VS Code from the Toolchain Manager, installing the nRF Connect extensions as recommended.

I have a project that builds and runs under nRF Connect SDK v1.6.1 based on the Bluetooth peripheral UART example. I created a project under nRF Connect SDK 2.00 using the Bluetooth peripheral UART application template in Visual Studio Code, selecting and configuring the same board (nrf52840dk_nrf52840) as I had in 1.6.1, then I copied my source code into the project folder and tried to build it by clicking on Build under ACTIONS in the nRF Connect Extension for VS Code. It builds and links the zephyr objects and libraries successfully, then creates zephyr.elf.

When it gets to my project source, however, it produces this message:

/home/developer/project/prime_master/src/main.c:190:10: fatal error: tinycbor/cbor.h: No such file or directory
190 | #include <tinycbor/cbor.h>

I noticed the include path is missing for tinycbor/cbor.h in build.ninja even though I find that header file in the SDK at /home/developer/ncs/modules/lib/tinycbor/include. The same is true for compile_commands.json. When I try to add this include path for both, the two files get overwritten with the missing include path when I try to rebuild as they are automatically generated.

Why is this path not picked up when build.ninja and compile_commands.json are created? Is there a way for me to manually add the include path so that it doesn't get lost in a pristine build?

Also, do you have an updated set of instructions in nRF Connect for Desktop that shows how to set up nRF Connect SDK v2.00, the toolchain, and Visual Studio Code from scratch?

Thanks for your help.

  • Hello Alec,

    First of all, for NCS 2 and Ubuntu 20.04 and above, the recommended way of installing the SDK is the automatic way using the Toolchain Manager. You don't even have to use the Getting Started Assistant, just open the Toolchain Manager and press "Install".

    Also, do you have an updated set of instructions in nRF Connect for Desktop that shows how to set up nRF Connect SDK v2.00, the toolchain, and Visual Studio Code from scratch?

    Here you are. I believe this series is still up to date, though note that it might look a bit different on Ubuntu (eg. only NCS 2 is available).

    then I copied my source code into the project folder and tried to build it by clicking on Build under ACTIONS in the nRF Connect Extension for VS Code. It builds and links the zephyr objects and libraries successfully, then creates zephyr.elf.

    There can be differences between the different NCS versions, ie. code that works in NCS v1.6 may not work in NCS v2. Could you try running a default UART sample from NCS v2 and see if that gives you a similar error?

    Regards,

    Elfving

  • Thank you, Elfving, for responding so quickly to my question.

    I did build the peripheral_uart sample in nrf/samples/bluetooth/ as a freestanding application successfully.  However, when I added #include <tinycbor/cbor.h> at line 35 in main.c for this sample, I get the same error:

    /home/developer/project/peripheral_uart/src/main.c:35:10: fatal error: tinycbor/cbor.h: No such file or directory35 | #include <tinycbor/cbor.h>
    | ^~~~~~~~~~~~~~~~~
    compilation terminated.
    [16/241] Building C object zephyr/CMakeFiles/zephyr.dir/lib/os/crc16_sw.c.obj
    ninja: build stopped: subcommand failed.
    FATAL ERROR: command exited with status 1

    It cannot seem to find the cbor.h header file, which is located at ncs/modules/lib/tinycbor/include/tinycbor in the Nordic nRFConnect v2.00 SDK.  I believe ncs/modules/lib/tinycbor/include should appear in the include path for main.c in the build.ninja file which is generated during the build process.  Here's what's in build.ninja for main.c, with the include path shown in green:

    build CMakeFiles/app.dir/src/main.c.obj: C_COMPILER__app_ ../src/main.c || cmake_object_order_depends_target_app
    DEFINES = -DKERNEL -DNRF52840_XXAA -DUSE_PARTITION_MANAGER=0 -D_FORTIFY_SOURCE=2 -D__PROGRAM_START -D__ZEPHYR__=1
    DEP_FILE = CMakeFiles/app.dir/src/main.c.obj.d
    FLAGS = -Og -imacros /home/developer/Diversey/peripheral_uart/build/zephyr/include/generated/autoconf.h -ffreestanding -fno-common -g -gdwarf-4 -fdiagnostics-color=always -mcpu=cortex-m4 -mthumb -mabi=aapcs -mfp16-format=ieee -imacros /home/developer/ncs/zephyr/include/zephyr/toolchain/zephyr_stdint.h -Wall -Wformat -Wformat-security -Wno-format-zero-length -Wno-main -Wno-pointer-sign -Wpointer-arith -Wexpansion-to-defined -Wno-unused-but-set-variable -Werror=implicit-int -fno-asynchronous-unwind-tables -fno-pie -fno-pic -fno-reorder-functions -fno-defer-pop -fmacro-prefix-map=/home/developer/Diversey/peripheral_uart=CMAKE_SOURCE_DIR -fmacro-prefix-map=/home/developer/ncs/zephyr=ZEPHYR_BASE -fmacro-prefix-map=/home/developer/ncs=WEST_TOPDIR -ffunction-sections -fdata-sections -std=c99 -nostdinc
    INCLUDES = -I../. -I/home/developer/ncs/nrf/drivers/mpsl/clock_control -I/home/developer/ncs/zephyr/include/zephyr -I/home/developer/ncs/zephyr/include -Izephyr/include/generated -I/home/developer/ncs/zephyr/soc/arm/nordic_nrf/nrf52 -I/home/developer/ncs/zephyr/soc/arm/nordic_nrf/common/. -I/home/developer/ncs/zephyr/subsys/bluetooth -I/home/developer/ncs/zephyr/subsys/settings/include -I/home/developer/ncs/nrf/include -I/home/developer/ncs/nrf/lib/multithreading_lock/. -I/home/developer/ncs/nrf/subsys/bluetooth/controller/. -I/home/developer/ncs/zephyr/drivers/flash -I/home/developer/ncs/modules/hal/cmsis/CMSIS/Core/Include -I/home/developer/ncs/modules/hal/nordic/nrfx -I/home/developer/ncs/modules/hal/nordic/nrfx/drivers/include -I/home/developer/ncs/modules/hal/nordic/nrfx/mdk -I/home/developer/ncs/zephyr/modules/hal_nordic/nrfx/. -I/home/developer/ncs/modules/debug/segger/SEGGER -I/home/developer/ncs/modules/debug/segger/Config -I/home/developer/ncs/zephyr/modules/segger/. -I/home/developer/ncs/modules/crypto/tinycrypt/lib/include -I/home/developer/ncs/nrfxlib/mpsl/include -I/home/developer/ncs/nrfxlib/mpsl/include/protocol -I/home/developer/ncs/nrfxlib/softdevice_controller/include -isystem /home/developer/ncs/zephyr/lib/libc/minimal/include -isystem /home/developer/ncs/toolchains/v2.0.0/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/10.3.0/include -isystem /home/developer/ncs/toolchains/v2.0.0/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/10.3.0/include-fixed -isystem /home/developer/ncs/nrfxlib/crypto/nrf_cc310_platform/include


    There is no -I/home/developer/ncs/modules/lib/tinycbor/include.  And when I try to add it, build.ninja gets regenerated when I go to build the project, with that include path once again missing.

    Could you try to build this on your system with #include <tinycbor/cbor.h> at line 35 in main.c for the peripheral_uart sample in nrf/samples/bluetooth/?  If it builds successfully, could you then check build.ninja in the build folder to see if it contains -I/home/developer/ncs/modules/lib/tinycbor/include in the INCLUDES path?  I am trying to determine if there's something missing in the configuration of my toolchain.

    Thanks,
    Alec

  • Hello again,

    DataMate said:

    Could you try to build this on your system with #include <tinycbor/cbor.h> at line 35 in main.c for the peripheral_uart sample in nrf/samples/bluetooth/?
    DataMate said:
    I am trying to determine if there's something missing in the configuration of my toolchain.

    Yeah, this is a good example of something that is different in this version of NCS. Tinycbor is replaced by Zcbor in this version of Zephyr. (Though I am also a bit uncertain about why Tinycbor is still included as a module.)

    In order to enable Tinycbor you would have to enable the config CONFIG_TINYCBOR, which you won't be allowed to do in NCS 2. You can however enable CONFIG_ZCBOR.

    I would recommend you to take a look at the central smp client sample in order to see an example of how it is used.

    Regards,

    Elfving

    --

    Update for the sake of keeping relevant info in the DevZone case:

    Here is a migration guide for switching from TinyCbor to Zcbor that might be handy. Your FAE has already provided this to you, this is mainly for others who run into the same issue in the future.

  • Thanks Elfving.  The migration document was very helpful.  I was able to implement a workaround for the deprecated Tinycbor module.  The code builds now.

Related