Using Edge Impulse C++ library in C toolchain

I am trying to run the Edge Impulse C++ library on the MAX32660 microcontroller, which I’ve been developing on using the Maxim SDK. The Maxim SDK toolchain is completely in C and so I’m stuck trying to figure out how to get the C++ library to work in C.

I have been trying to convert the Maxim SDK code so I can use a C++ compiler, but I wanted to see if anyone knew (maybe in broad strokes) how to use this C++ library in C code.

I’ve been looking at the example-standalone-inferencing-c example and instructions here. The instructions are very sparse.

It seems to me that the Makefile in the example is looking for the downloaded library folders, so I would unzip and copy in the “edge-impule-sdk”, “tflite-model”, and “model-parameters” folders into the project layout shown on Github. At this point, would I need to modify my current Makefile to include the g++ compiler and all the other sources as shown in the example? I’m not familiar with Makefile configurations, so I’d appreciate some guidance over which are the important parts and/or if this example will still work when I cross compile for a microcontroller.

2 Likes

I got the same integration problem on my project. On way I was thinking of going arround this by building the C++ code generated from edge impulse into a .a or .lib shared library file (standelone project) and link that artifact to the C project with the headers files (necessary for the compiler the symbol defined in the lib object). I did not implemented it so I don’t know if it is feasible.

1 Like

Hello Henry,

We support standalone inference from C, however our recommendation is to use C++. In general, tflite requires C++ and combining it with C application is not straightforward.

Edge Impulse example of C standalone inferencing for PSoC 62 is available here on GitHub - GitHub - edgeimpulse/example-standalone-inferencing-infineon-psoc62: Standalone inferencing on PSoC62

We had to enable extra features and limitations at the same time, complete list of the defines that we use for C standalone inferencing on PSoC62 can be found below. Please take a look and let me know if you have more questions.

Thanks,

Dimi

additional defines to the build process for C standalone inferencing on PSoC 62

DEFINES += TF_LITE_DISABLE_X86_NEON=1

DEFINES += EIDSP_SIGNAL_C_FN_POINTER=1

DEFINES += EI_C_LINKAGE=1

DEFINES += EI_PORTING_INFINEONPSOC62=1

DEFINES += EIDSP_USE_CMSIS_DSP

DEFINES += EIDSP_QUANTIZE_FILTERBANK=0

DEFINES += NDEBUG

DEFINES += EI_CLASSIFIER_TFLITE_ENABLE_CMSIS_NN

DEFINES += ARM_MATH_LOOPUNROLL

DEFINES += EIDSP_LOAD_CMSIS_DSP_SOURCES=1

HI Roy, generating a library and linking to it should be possible, however there might be an easier path using our defines for running from C - On your desktop computer - Edge Impulse Documentation

It is target specific and sometimes adding EIDSP_SIGNAL_C_FN_POINTER=1 and EI_C_LINKAGE=1 is not enough, therefore I encourage you to open a dedicated forum topic where we could discuss what is your use case, SDK, hardware and exact issue(compiler error). I am happy to help :slight_smile:

Thank you for the suggestions. I decided to use C++ as I realized I could build and link C++ code successfully with the MaximSDK libraries. For anyone else in the future who is interested, the iostream.h library does not work in the MaximSDK toolchain, as of right now, but using the default GNU tools compiles C/C++ code using gcc/g++ properly.

I did end up running into a lot more issues trying to modify the Makefile and getting the C++ library to work properly, but I’ve started a new thread for that issue as it’s rather different.

1 Like