Logging to USB serial from firmware

Can I log to the usb serial window in the IDE from within a c firmware function I’m debugging?
What function could I call?

The terminal stores 1M lines of text. Just select all and copy it.

If you use the Open Terminal Feature there’s an explicit save operation if you click on the disk icon.

Hey, I’m actually trying to print some data from within the firmware.

e.g. in imlib.c

void imlib_lens_corr(image_t *img, float strength, float zoom)
    printf("This is some debug text I want to show up in the IDE text window");  // What function should this be, to output data from the open mv firmware to the IDE text window?

Yeah, it will just show up in the IDE window. printf() in c == print() in python.

Hello everybody,

I also try to add logs in the Firmware part of the project and especially in the CMSIS NN part.
I have seen “printf” in the code (CMSIS NN) but I can’t see them during execution. In the Serial Terminal part of the IDE, I can only see the Python script printfs.

Do I have to enable printf in the Firmware part somewhere ? For example in a makefile or somewhere else ?

Thank you,

You just do printf() in the code and it goes to the IDE. If you are inside of our TensorFlow library you have to do: error_reporter->Report()

Ok, thank you for your answer.

I tried it but I cannot get logs. I reflash the firmware part using the IDE (Tools/Run Bootloader and select firmware.bin).
The version is well updated on the camera :
MicroPython v1.12-omv-12-gabc992e94 OpenMV v3.6.3-5-g8feaf6df-dirty 2020-05-26; OPENMV4-STM32H743

For example I add a printf in this function (src/omv/py/py_nn.c) but I can’t see it.

static mp_obj_t py_nn_load(mp_obj_t path_obj)
    const char *path = mp_obj_str_get_str(path_obj);
    py_net_obj_t *net = m_new_obj(py_net_obj_t);
    net->base.type = &py_net_type;
    printf("!!! TEST !!!/n");
    nn_load_network(py_net_cobj(net), path);
    return net;

It should work. I’m guessing that method isn’t executed then.

Also, the old CNN code is about to be removed. TensorFlow is working now. We will likely delete all that code once EdgeImpulse gets up and running.

ok, thanks.

So if i understand well source code located in CMSIS NN (src/cmsis/src/nn) folder is not called ?
When you say “the old CNN code is about to be removed. TensorFlow is working now.” are you talking about the new CMSIS library with TensorFlow API support ?

Yes, we don’t plan to keep that custom code anymore. We will fully switch to just TensorFlow support. TensorFlow has CMSIS-NN under the hood (that said, CMSIS-NN is still broken in TensorFlow, if you try to use it you get a hard crash with memory corruption, but, one day ARM will get their code working). Performance isn’t that bad however using the Non-CMSIS-NN code.

Thanks for your quick answers, I will add logs in the source code which is called.

Looking at the compilation flags used for the TensorFlow library (https://github.com/openmv/openmv/blob/master/src/libtf/cortex-m7/README), I see the following flag: -DARM_CMSIS_NN_M7.
Does this flag indicate the use of the optimizations provided by CMSIS NN ?

No, right now CMSIS-NN is not compiled in. All the defines needed for it to work are added.

If I try to enable it right now with TensorFlow you get hard crashes on the OpenMV Cam with memory corruption. The library is not ready to use yet. This is particularly hard to debug since it’s not our code.

Ok thank you, I get it.

I have an other question, I wanted to know if the libtf.a library was pre-compiled. If yes, is it possible to get the source code ?
I wish I could edit it and recompile it.

Yes, GitHub - openmv/tensorflow-lib: TensorFlow package for Cortex-M4 and Cortex-M7 CPUs with hardware floating point.

Thank you


I am trying to add logs into the TensorFlow library (libTf.a), I use the following code but I cannot see logs on OpenMV IDE :

add.cc file in CMSIS optimized kernels folder

tflite::MicroErrorReporter micro_error_reporter;
tflite::ErrorReporter* error_reporter = &micro_error_reporter;

error_reporter->Report("LOG - TFLIB - add.cc - CalculateOpData\r\n");

Is it the right way to add logs ?

Once you recompile the library did you replace the library in the OpenMV source code and recompile it with the new library?

That is the right way.

Yes I copied the libTf.a in the OpenMv repo and regenerate the firmware.
cp ./libtf/cortex-m7/libtf.a ~/Documents/work/projects/smartCamera/repo/openmv/src/libtf/cortex-m7

I also used md5sum command to be sure of that.