Logging to USB serial from firmware

Discussion related to "under the hood" OpenMV topics.
mirkwood
Posts: 12
Joined: Tue Mar 10, 2020 4:08 am

Logging to USB serial from firmware

Postby mirkwood » Wed May 13, 2020 11:47 pm

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?
User avatar
kwagyeman
Posts: 4105
Joined: Sun May 24, 2015 2:10 pm

Re: Logging to USB serial from firmware

Postby kwagyeman » Thu May 14, 2020 1:47 am

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.
Nyamekye,
mirkwood
Posts: 12
Joined: Tue Mar 10, 2020 4:08 am

Re: Logging to USB serial from firmware

Postby mirkwood » Thu May 14, 2020 6:12 am

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

e.g. in imlib.c

Code: Select all

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?
    ...
}
User avatar
kwagyeman
Posts: 4105
Joined: Sun May 24, 2015 2:10 pm

Re: Logging to USB serial from firmware

Postby kwagyeman » Thu May 14, 2020 1:40 pm

Yeah, it will just show up in the IDE window. printf() in c == print() in python.
Nyamekye,
yann
Posts: 10
Joined: Mon May 25, 2020 5:13 am

Re: Logging to USB serial from firmware

Postby yann » Mon May 25, 2020 5:23 am

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,
Yann
User avatar
kwagyeman
Posts: 4105
Joined: Sun May 24, 2015 2:10 pm

Re: Logging to USB serial from firmware

Postby kwagyeman » Mon May 25, 2020 1:23 pm

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()
Nyamekye,
yann
Posts: 10
Joined: Mon May 25, 2020 5:13 am

Re: Logging to USB serial from firmware

Postby yann » Tue May 26, 2020 3:57 am

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.

Code: Select all

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;
}
User avatar
kwagyeman
Posts: 4105
Joined: Sun May 24, 2015 2:10 pm

Re: Logging to USB serial from firmware

Postby kwagyeman » Tue May 26, 2020 1:29 pm

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.
Nyamekye,
yann
Posts: 10
Joined: Mon May 25, 2020 5:13 am

Re: Logging to USB serial from firmware

Postby yann » Tue May 26, 2020 1:58 pm

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 ?
User avatar
kwagyeman
Posts: 4105
Joined: Sun May 24, 2015 2:10 pm

Re: Logging to USB serial from firmware

Postby kwagyeman » Tue May 26, 2020 2:01 pm

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.
Nyamekye,
yann
Posts: 10
Joined: Mon May 25, 2020 5:13 am

Re: Logging to USB serial from firmware

Postby yann » Tue May 26, 2020 2:25 pm

Thanks for your quick answers, I will add logs in the source code which is called.
yann
Posts: 10
Joined: Mon May 25, 2020 5:13 am

Re: Logging to USB serial from firmware

Postby yann » Thu May 28, 2020 10:08 am

Hello,
Looking at the compilation flags used for the TensorFlow library (https://github.com/openmv/openmv/blob/m ... -m7/README), I see the following flag: -DARM_CMSIS_NN_M7.
Does this flag indicate the use of the optimizations provided by CMSIS NN ?
User avatar
kwagyeman
Posts: 4105
Joined: Sun May 24, 2015 2:10 pm

Re: Logging to USB serial from firmware

Postby kwagyeman » Thu May 28, 2020 10:47 am

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.
Nyamekye,
yann
Posts: 10
Joined: Mon May 25, 2020 5:13 am

Re: Logging to USB serial from firmware

Postby yann » Thu May 28, 2020 10:57 am

Ok thank you, I get it.
yann
Posts: 10
Joined: Mon May 25, 2020 5:13 am

Re: Logging to USB serial from firmware

Postby yann » Wed Jun 03, 2020 12:57 pm

Hello,
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.
Thanks,
Yann
User avatar
kwagyeman
Posts: 4105
Joined: Sun May 24, 2015 2:10 pm

Re: Logging to USB serial from firmware

Postby kwagyeman » Wed Jun 03, 2020 2:14 pm

Nyamekye,
yann
Posts: 10
Joined: Mon May 25, 2020 5:13 am

Re: Logging to USB serial from firmware

Postby yann » Thu Jun 04, 2020 3:05 am

Thank you
yann
Posts: 10
Joined: Mon May 25, 2020 5:13 am

Re: Logging to USB serial from firmware

Postby yann » Mon Jun 08, 2020 11:50 am

Hello,

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

Code: Select all

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 ?
Thanks
User avatar
kwagyeman
Posts: 4105
Joined: Sun May 24, 2015 2:10 pm

Re: Logging to USB serial from firmware

Postby kwagyeman » Mon Jun 08, 2020 12:20 pm

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.
Nyamekye,
yann
Posts: 10
Joined: Mon May 25, 2020 5:13 am

Re: Logging to USB serial from firmware

Postby yann » Mon Jun 08, 2020 5:21 pm

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.
User avatar
kwagyeman
Posts: 4105
Joined: Sun May 24, 2015 2:10 pm

Re: Logging to USB serial from firmware

Postby kwagyeman » Mon Jun 08, 2020 6:35 pm

Okay, well, I don't know why the print statement doesn't appear.
Nyamekye,

Return to “Technical Discussion”

Who is online

Users browsing this forum: No registered users and 2 guests