mocleiri / tensorflow-micropython-examples

A custom micropython firmware integrating tensorflow lite for microcontrollers and ulab to implement the tensorflow micro examples.
MIT License
170 stars 79 forks source link

Try to move tensorflow lite micro build inside of the microlite module #32

Closed mocleiri closed 2 years ago

mocleiri commented 2 years ago

I'm getting linker errors when trying to combine the libtensorflow-microlite.a as built by ci: https://github.com/mocleiri/tensorflow-micropython-examples/actions/workflows/build_tensorflow_arm.yml

I think there is a difference between the toolchain used to build the static library and the firmware.

Lets try to use the create_tflm_tree.py script to generate the tensorflow lite micro files within the microlite module.

micropython needs the files to be called .cpp instead of .cc which is what tensorflow uses so we will have to transform the files into the .cpp naming. If we can find a way to do it in the python generation script we should up stream it for others or maybe use a bit of shell scripting to do the transform.

arm-none-eabi-ld: /usr/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/lib/thumb/v7e-m+dp/hard/libstdc++.a(new_op.o): in function `operator new(un
signed int)':
new_op.cc:(.text._Znwj+0xc): undefined reference to `malloc'
arm-none-eabi-ld: /usr/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/lib/thumb/v7e-m+dp/hard/libstdc++.a(vterminate.o): in function `__gnu_cxx::
__verbose_terminate_handler()':
vterminate.cc:(.text._ZN9__gnu_cxx27__verbose_terminate_handlerEv+0x42): undefined reference to `fwrite'
arm-none-eabi-ld: vterminate.cc:(.text._ZN9__gnu_cxx27__verbose_terminate_handlerEv+0x50): undefined reference to `fputs'
arm-none-eabi-ld: vterminate.cc:(.text._ZN9__gnu_cxx27__verbose_terminate_handlerEv+0x5e): undefined reference to `fwrite'
arm-none-eabi-ld: vterminate.cc:(.text._ZN9__gnu_cxx27__verbose_terminate_handlerEv+0x68): undefined reference to `free'
arm-none-eabi-ld: vterminate.cc:(.text._ZN9__gnu_cxx27__verbose_terminate_handlerEv+0x76): undefined reference to `fputs'
arm-none-eabi-ld: vterminate.cc:(.text._ZN9__gnu_cxx27__verbose_terminate_handlerEv+0x88): undefined reference to `fwrite'
arm-none-eabi-ld: vterminate.cc:(.text._ZN9__gnu_cxx27__verbose_terminate_handlerEv+0x9c): undefined reference to `fwrite'
arm-none-eabi-ld: vterminate.cc:(.text._ZN9__gnu_cxx27__verbose_terminate_handlerEv+0xc0): undefined reference to `fwrite'
arm-none-eabi-ld: vterminate.cc:(.text._ZN9__gnu_cxx27__verbose_terminate_handlerEv+0xca): undefined reference to `fputs'
arm-none-eabi-ld: vterminate.cc:(.text._ZN9__gnu_cxx27__verbose_terminate_handlerEv+0xd4): undefined reference to `fputc'
arm-none-eabi-ld: vterminate.cc:(.text._ZN9__gnu_cxx27__verbose_terminate_handlerEv+0xf4): undefined reference to `_impure_ptr'
arm-none-eabi-ld: /usr/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/lib/thumb/v7e-m+dp/hard/libstdc++.a(cp-demangle.o): in function `d_growable
_string_callback_adapter':
cp-demangle.c:(.text+0x314): undefined reference to `realloc'
arm-none-eabi-ld: cp-demangle.c:(.text+0x32e): undefined reference to `free'
arm-none-eabi-ld: /usr/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/lib/thumb/v7e-m+dp/hard/libstdc++.a(cp-demangle.o): in function `d_append_n
um':
cp-demangle.c:(.text+0x552): undefined reference to `sprintf'
arm-none-eabi-ld: /usr/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/lib/thumb/v7e-m+dp/hard/libstdc++.a(cp-demangle.o): in function `d_print_co
mp_inner':
cp-demangle.c:(.text+0x2b20): undefined reference to `sprintf'
arm-none-eabi-ld: cp-demangle.c:(.text+0x3c5e): undefined reference to `sprintf'
arm-none-eabi-ld: cp-demangle.c:(.text+0x3d72): undefined reference to `sprintf'
arm-none-eabi-ld: cp-demangle.c:(.text+0x3e72): undefined reference to `sprintf'
arm-none-eabi-ld: /usr/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/lib/thumb/v7e-m+dp/hard/libstdc++.a(cp-demangle.o):cp-demangle.c:(.text+0x4
088): more undefined references to `sprintf' follow
arm-none-eabi-ld: /usr/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/lib/thumb/v7e-m+dp/hard/libstdc++.a(cp-demangle.o): in function `__cxa_dema
ngle':
cp-demangle.c:(.text+0x5e50): undefined reference to `free'
arm-none-eabi-ld: cp-demangle.c:(.text+0x5e7a): undefined reference to `free'
arm-none-eabi-ld: cp-demangle.c:(.text+0x5e9e): undefined reference to `free'
arm-none-eabi-ld: /usr/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/lib/thumb/v7e-m+dp/hard/libstdc++.a(del_op.o): in function `operator delete
(void*)':
del_op.cc:(.text._ZdlPv+0x0): undefined reference to `free'
arm-none-eabi-ld: /usr/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/lib/thumb/v7e-m+dp/hard/libstdc++.a(eh_alloc.o): in function `__cxa_allocat
e_exception':
eh_alloc.cc:(.text.__cxa_allocate_exception+0x8): undefined reference to `malloc'
arm-none-eabi-ld: /usr/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/lib/thumb/v7e-m+dp/hard/libstdc++.a(eh_alloc.o): in function `__cxa_free_ex
ception':
eh_alloc.cc:(.text.__cxa_free_exception+0x16): undefined reference to `free'
make[1]: *** [Makefile:713: /opt/tflite-micro-micropython/boards/stm32/NUCLEO_H743ZI2_MICROLITE/build/firmware.elf] Error 1
make[1]: Leaving directory '/opt/tflite-micro-micropython/micropython/ports/

I verified that both the normal build and normal build with user_c_modules worked fine.

mocleiri commented 2 years ago

The linker errors were related to the stm32 micropython port being bare metal so not having a standard library and all memory allocation handled by the micropython garbage collector.

Circuitpython wants us to have the tflm files integrated and compiled as part of the microlite module build.

While #31 can build a firmware there are issues preventing inference from running so internalizing and standardizing the compile options may be a way to solve the issues experienced there.

mocleiri commented 2 years ago

I have the stm32 port build working using the tflm generated directory (still not working right). I just merged this into the stm32 branch but more work is needed for the esp32 build.

34 will track getting the esp32 build to work.