Hello, I have a question related to tflite-micro and the STM32F4 MCU.
I’m using Ubuntu and cloned the tflite-micro repo, and in that directory I used this command: " make -f tensorflow/lite/micro/tools/make/Makefile TARGET=cortex_m_generic TARGET_ARCH=cortex-m4 microlite". And also, I generated a tflm-tree by the “python3 create_tflm_tree.py” command.
I transferred all the generated files to Windows to use in my learning project. And now, I have errors in STM32CubeIDE.
Hi, @Saeed_Bazargan ,Welcome to our Google AI Developers Forum, I apologize for the delayed response.
The root cause of the errors is that while the make command and create_tflm_tree.py successfully generate the necessary C++ source files on Ubuntu, the resulting structure requires manual configuration within STM32CubeIDE to correctly map its deep file hierarchy and activate the required C++ toolchain.
Here is a step-by-step resolution plan to address the compilation errors in your learning project:
1. Enable the C++ Toolchain (Critical)
TFLM is an entirely C++ library, but STM32CubeIDE often defaults to a C project. This mismatch is the source of many immediate errors.
-
Rename Entry Point: Rename your main application file, typically
main.c, tomain.cppThis forces the IDE to invoke the GNU C++ compiler (arm-none-eabi-g++) and correctly set up the C++ runtime environment required by TFLM. -
Verify FPU Settings: Ensure your MCU settings are configured to use the hardware Floating Point Unit (FPU) for performance, aligning with the
TARGET_ARCH=cortex-m4flag you used in your Linux build.
2. Resolve Compilation Errors: Include Paths
Errors like “No such file or directory: ‘tensorflow/lite/micro/micro_interpreter.h’” mean the compiler cannot locate the nested headers. You must explicitly tell the C++ compiler where to look.
Navigate to Project Properties→C/C++ General →Paths and Symbols →Includes Tab.
Crucially, ensure the GNU C++ language is selected and add the following directories where TFLM_ROOT is the directory containing the top-level tensorflow folder:
-
TFLM_ROOT(The parent directory of thetensorflowfolder itself). -
TFLM_ROOT/tensorflow/lite/micro/ -
TFLM_ROOT/tensorflow/lite/schema/
By systematically ensuring these paths and the C++ compiler are correctly configured, you should be able to resolve all cross-platform errors and proceed with linking your application and the TFLM library. Please refer this article which may help you to resolve your issue
Please apply these configuration changes and if you encounter any specific new errors share the full console output and we will be happy to provide further targeted assistance.