Deploying and building a C++ impulse on custom board with nrf9160

Hi,

I experience some difficulties trying to add an Impulse to my VS Code project for a Zephyr-based custom board (based on nrf9160). When I build multiple errors arise, but the first one is from numpy.hpp: cfloat: No such file or directory.
My project is configured with main.c, I know this is a problem, but it’s not clear to me how I should convert all of my .c files properly. So that I can compile with a C++ compiler (i.e. zephyr toolchain)
So far I have:

  • installed a sufficient nrf SDK version (2.2.0)
  • Merged the configuration from the example-standalone-inferencing-zephyr as best as I could:
    • CMakeList.txt
    • prj.conf
    • utils/utils.cmake

I managed to build example-standalone-inferencing-zephyr after adding my board, application overlay and prj.conf files.

Any Idea’s?

What I find strange is that I can find cfloat, memory, etc. in my zephyr toolchain dir. Why won’t my compiler find those files and instead raise an error.

Thank you in advance.

Oh wow I finally got it all working today. prj_team = happy;

This is for all the desperate newbies out there like me.
I found this worked:

  • First make sure all dependencies are met, so install a nrf SDK >= 1.6.0 using the nrf connect tool manager.
  • Install all necessary VS Code extensions to help you aid in the debugging & build config process (nrf, Cmake, C/C++, Kconfig, etc.)
  • Just merge the CmakeList.txt, prj.conf, etc. files from the example-standalone-inferencing-zephyr-master project with my project files.
  • If you have to mix C & C++: Just only convert the .c files that include the EI SDK directly. I did not have to convert my main.c, but rather the .c file that was referenced by main.c and actually #included you Edge_impulse. This was at first confusing to me, since all documentation by EI and NRF says you need a C++ project with main.cpp, which is not the case necessarily .
    This is why the compiler was throwing: “did not found ”, it was compiling the EI libraries with a C compiler, because my file was named “car_sensor.c”. When I changed the file extension to .cpp all worked. Sounds so obvious now -.-
  • This guide was useful to convert .c and .h files for different C->C++ or C+±>C function references: https://isocpp.org/wiki/faq/mixing-c-and-cpp

Thanks to everyone from Edge Impulse, great platform.

1 Like

Hi @timvanharenMoS,

Glad to hear you got it working, and thank you for putting your notes here to help others!

Hi, can you share the main structure of this implementation? No your code, just the way you implemented the c++ library in your project.

Thanks!

Hi @Juandgarcia,

You mean actual file structure?
│ .gitignore
│ CMakeLists.txt
│ Kconfig
│ my_yaml.yml
│ prj.conf
│ README.md
│ my_conf.conf
├───child_image
│ mcuboot.conf
├───edge-impulse-sdk
├───model-parameters
├───src
│ main.c│
│ └───my_node
│ magnetometer.cpp
│ magnetometer.h
├───tflite-model
└───utils
└───cmake
utils.cmake
I already had a magnetomer.c file, which I used to drive a magnetometer. I changed the name of this file to magnetometer.cpp. And used the guide I linked earlier.

Is this what you mean?

hi, i have worked with ncs/zephyr/samples/sensor/ls6dso sensor code and then built an impulse in edge impulse studio and finally ,i wanna deploy this model on my nrf52840dk but i dont know how ? after i copy these 3 directories : * edge-impulse-sdk/ model-parameters/ tflite-modelin my zephyr project i’dont know exactly what to put in prj.conf and cmakelists.txt and how to update my code in main.c .can you please helpe me and share the prj.con,cmakelists.txt and main.c files

Hi @rania23,

I recommend seeing if you can build this Zephyr example for the nrf52840: GitHub - edgeimpulse/example-standalone-inferencing-zephyr

i tried to build Zephyr example for the nrf52840: GitHub - edgeimpulse/example-standalone-inferencing-zephyr,but i got these errors:Building examplestandalone
C:\Windows\system32\cmd.exe /d /s /c “west build --build-dir c:/examplestandalone/build c:/examplestandalone”

– west build: generating a build system
Including boilerplate (Zephyr base (cached)): C:/ncs/v1.9.1/zephyr/cmake/app/boilerplate.cmake
– Application: C:/examplestandalone
– Zephyr version: 2.7.99 (C:/ncs/v1.9.1/zephyr), build: b05b8ad63acf
– Found west (found suitable version “0.12.0”, minimum required is “0.7.1”)
– Board: nrf52840dk_nrf52840
– Cache files will be written to: C:/ncs/v1.9.1/zephyr/.cache
– Found dtc: C:/ncs/toolchains/v1.9.1/opt/bin/dtc.exe (found suitable version “1.4.7”, minimum required is “1.4.6”)
– Found toolchain: gnuarmemb (c:/ncs/toolchains/v1.9.1/opt)
– Found BOARD.dts: C:/ncs/v1.9.1/zephyr/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840.dts
– Generated zephyr.dts: C:/examplestandalone/build/zephyr/zephyr.dts
– Generated devicetree_unfixed.h: C:/examplestandalone/build/zephyr/include/generated/devicetree_unfixed.h
– Generated device_extern.h: C:/examplestandalone/build/zephyr/include/generated/device_extern.h
– Including generated dts.cmake file: C:/examplestandalone/build/zephyr/dts.cmake
Parsing C:/ncs/v1.9.1/zephyr/Kconfig
Loaded configuration ‘C:/ncs/v1.9.1/zephyr/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840_defconfig’
Merged configuration ‘c:/examplestandalone/prj.conf’

c:/examplestandalone/prj.conf:3: warning: attempt to assign the value ‘y’ to the undefined symbol CPP

c:/examplestandalone/prj.conf:4: warning: attempt to assign the value ‘y’ to the undefined symbol GLIBCXX_LIBCPP

error: Aborting due to Kconfig warnings

CMake Error at C:/ncs/v1.9.1/zephyr/cmake/kconfig.cmake:272 (message):
command failed with return code: 1
Call Stack (most recent call first):
C:/ncs/v1.9.1/zephyr/cmake/app/boilerplate.cmake:544 (include)
C:/ncs/v1.9.1/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:24 (include)
C:/ncs/v1.9.1/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:40 (include_boilerplate)
CMakeLists.txt:6 (find_package)

– Configuring incomplete, errors occurred!
FATAL ERROR: command exited with status 1: ‘c:\ncs\toolchains\v1.9.1\opt\bin\cmake.EXE’ ‘-DWEST_PYTHON=c:\ncs\toolchains\v1.9.1\opt\bin\python.exe’ ‘-Bc:\examplestandalone\build’ ‘-Sc:\examplestandalone’ -GNinja

Hi @rania23,

Please update NCS to version 2.x.x (e.g. 2.2.0) and try again. It looks like you are using version 1.9.1.

you mean just intall another toolchain and sdk version or delete the old one and install the new ,cause i’m tring to install sdk v 2.0.0 in ncs directory (where is v1.9.1) and it’s not being installed

Hi @rania23,

I don’t know Nordic’s build system very well. My guess is that you will need to delete 1.9.1 and reinstall 2.x.x

hi again ,i changed the sdk version to 2.1.0 and still have errors when i build the example-standalone-inferencing-zephyr

i added my nrf52840dk overlay file to the boards directory ,is there another thing i have to add?

Hi @rania23,

Can you please try with 2.4.0. This is currently officially supported version.
Regarding NCS installation, you can have multiple versions installed in the vs code with Nordic extensions.
Please be sure to check if you have desired (2.4.0) version selected and build directory deleted before
new build.

hi @vojislav while i’m still using the v2.1.0 ,but after i updated the prj file like this :CONFIG_STDOUT_CONSOLE=y CONFIG_I2C=y CONFIG_SENSOR=y CONFIG_LSM6DSO=y CONFIG_LSM6DSO_TRIGGER_GLOBAL_THREAD=y CONFIG_CBPRINTF_FP_SUPPORT=y CONFIG_NEWLIB_LIBC=y CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y CONFIG_MAIN_STACK_SIZE=8192 CONFIG_CPLUSPLUS=y CONFIG_LIB_CPLUSPLUS=y
it kinda built but with error like this :

do i still need to change sdk version to 2.4.0?

I would say go for it and test on device to verify everything is working correctly.