zephyr/samples/modules/tflite-micro/hello_world
Sudan Landge 3092d96e5b boards: mps3: Add support for corstone300/an552
What is changed?
 - Added a new mps3 board an552 for the soc corstone300.
   The qualifier to build/run application with board mps3/an552 is
   `mps3/corstone300/an552` for secure and
   `mps3/corstone300/an552/ns` for non-secure.
 - Added FVP variant to enable FVP testing with corstone300
   and it uses the ARM FVP `FVP_Corstone_SSE-300_Ethos-U55`.
   The qualifier to build/run application with FVP is
   `mps3/corstone300/fvp` for secure and
   `mps3/corstone300/fvp/ns` for non-secure.
 - Note: the qualifier to build/run application with board mps3/an547
   is now changed to
   `mps3/corstone300/an547` for secure and
   `mps3/corstone300/an547/ns` for non-secure.

How is it changed?
 - Moved common code from mps3/an547 to corstone300.
 - Renamed soc for an547 to corstone300 and added
   a new soc corstone300/an552.

Why do we need this change?
 - This enables FVP support and testing for corstone300.
 - SOC/qualifier for mps3/an547 was renamed to reduce code redundancy
 - A separate FVP variant was added for AN552 because, the TFM board
   used for non-secure variant differs for FPGA and FVP.
   TFM board `arm/mps3/corstone300/fvp` should be used when testing
   AN552 with FVP and `arm/mps3/corstone300/an552` should be used when
   testing with AN552 FPGA.

Signed-off-by: Sudan Landge <sudan.landge@arm.com>
2024-10-26 03:58:05 +01:00
..
images
src
train
CMakeLists.txt
prj.conf samples: tflite-micro: add REQUIRES_FLOAT_PRINTF 2024-06-28 07:50:12 -04:00
README.rst boards: mps3: Add support for corstone300/an552 2024-10-26 03:58:05 +01:00
sample.yaml boards: mps3: Add support for corstone300/an552 2024-10-26 03:58:05 +01:00

.. zephyr:code-sample:: tflite-hello-world
   :name: Hello World

   Replicate a sine wave using TensorFlow Lite for Microcontrollers.

Overview
********

This sample TensorFlow application replicates a sine wave and
demonstrates the absolute basics of using TensorFlow Lite Micro.

The model included with the sample is trained to replicate a
sine function and generates x values to print alongside the
y values predicted by the model. The x values iterate from 0 to
an approximation of 2π.

The sample also includes a full end-to-end workflow of training
a model and converting it for use with TensorFlow Lite Micro for
running inference on a microcontroller.

The sample comes in two flavors. One with TensorFlow Lite Micro
reference kernels and one with CMSIS-NN optimized kernels.

.. Note::
   This README and sample have been modified from
   `the TensorFlow Hello World sample for Zephyr`_.

.. _the TensorFlow Hello World sample for Zephyr:
   https://github.com/tensorflow/tflite-micro/tree/main/tensorflow/lite/micro/examples/hello_world

Building and Running
********************

The sample should work on most boards since it does not rely
on any sensors.

Add the tflite-micro module to your West manifest and pull it:

.. code-block:: console

    west config manifest.project-filter -- +tflite-micro
    west update

The reference kernel application can be built and executed on QEMU as follows:

.. zephyr-app-commands::
   :zephyr-app: samples/modules/tflite-micro/hello_world
   :host-os: unix
   :board: qemu_x86
   :goals: run
   :compact:

Exit QEMU by pressing :kbd:`CTRL+A` :kbd:`x`.

The CMSIS-NN kernel application can be built and executed on any Arm(R) Cortex(R)-M core based platform,
for example based on Arm Corstone(TM)-300 software. A reference implementation of Corstone-300
can be downloaded either as a FPGA bitfile for the
[MPS3 FPGA prototyping board](https://developer.arm.com/tools-and-software/development-boards/fpga-prototyping-boards/mps3),
or as a
[Fixed Virtual Platform](https://developer.arm.com/tools-and-software/open-source-software/arm-platforms-software/arm-ecosystem-fvps)
that can be emulated on a host machine.

Assuming that the Corstone-300 FVP has been downloaded, installed and added to
the :envvar:`PATH` variable, then building and testing can be done with following
commands.

```
$ west build -p auto -b mps3/corstone300/an547 samples/modules/tflite-micro/hello_world/ -T sample.tensorflow.helloworld.cmsis_nn
$ FVP_Corstone_SSE-300_Ethos-U55 build/zephyr/zephyr.elf
```

Sample Output
=============

.. code-block:: console

    ...

    x_value: 1.0995567*2^1, y_value: 1.6951603*2^-1

    x_value: 1.2566366*2^1, y_value: 1.1527088*2^-1

    x_value: 1.4137159*2^1, y_value: 1.1527088*2^-2

    x_value: 1.5707957*2^1, y_value: -1.0849024*2^-6

    x_value: 1.7278753*2^1, y_value: -1.0509993*2^-2

    ...

The modified sample prints 10 generated-x-and-predicted-y pairs. To see
the full period of the sine curve, increase the number of loops in :file:`main.c`.

Modifying Sample for Your Own Project
*************************************

It is recommended that you copy and modify one of the two TensorFlow
samples when creating your own TensorFlow project. To build with
TensorFlow, you must enable the below Kconfig options in your :file:`prj.conf`:

.. code-block:: cfg

    CONFIG_CPP=y
    CONFIG_REQUIRES_FULL_LIBC=y
    CONFIG_TENSORFLOW_LITE_MICRO=y

Note that the CMSIS-NN kernel sample demonstrates how to use CMSIS-NN optimized kernels with
TensorFlow Lite Micro, in that is sets below Kconfig option. Note also that this
Kconfig option is only set for Arm Cortex-M cores, i.e. option CPU_CORTEX_M is set.

.. code-block:: cfg

    CONFIG_TENSORFLOW_LITE_MICRO_CMSIS_NN_KERNELS=y

Training
********
Follow the instructions in the :file:`train/` directory to train your
own model for use in the sample.