Last edited one month ago

X-LINUX-AI Developer package

Applicable for STM32MP13x lines, STM32MP15x lines, STM32MP25x lines


1. Developer package: build AI application from the X-LINUX-AI add-on SDK[edit | edit source]

In order to easily develop and build an AI application without using the Yocto build system, X-LINUX-AI comes with a SDK add-on extending the OpenSTLinux SDK with AI functionality. To install and use the X-LINUX-AI SDK Add-on please refer to the following steps.

2. Prerequisites[edit | edit source]

2.1. Install the OpenSTLinux SDK[edit | edit source]

First of all, you must download and install the OpenSTLinux SDK, which contains all the basis needed for the X-LINUX-AI add-on. To do this, follow instructions given in STM32MPU Developer Package: Installing the SDK chapter. Once this has been done, you should have a directory containing the OpenSTLinux SDK.

Info white.png Information
Once this is done, if you have follow the example of directory structure the path to the OpenSTLinux SDK should be the following:
<working directory absolute path>/Developer-Package/SDK

3. X-LINUX-AI SDK add-on installation[edit | edit source]

3.1. Download the X-LINUX-AI SDK add-on[edit | edit source]

To add the Artificial Intelligence part into the OpenSTLinux SDK, you must download and install the X-LINUX-AI SDK add-on. The add-on is delivered through a tarball file that can be downloaded here: X-LINUX-AI SDK add-on.

Warning white.png Warning
The X-LINUX-AI SDK add-on version and the STM32MPU board must be the same as the OpenSTLinux SDK. If either the version are not aligned or the board is different, it might not work correctly.

3.2. Install the X-LINUX-AI SDK add-on[edit | edit source]

Host PC package prerequisites

To be able to properly install the X-LINUX-AI SDK add-on on your host computer it is necessary to install the extra package patchelf using the following command (in addition of packages from PC_prerequisites):

 sudo apt-get install patchelf

Install add-on for STM32MP1 series

Once the X-LINUX-AI SDK add-on is downloaded, uncompress the add-on:

Info white.png Information
The name of the tarball depends on the chosen version. In the example below the last uploaded version is used.
  cd  ~/Downloads/
  tar xzf  en.sdk-x86_64-stm32mp1-openstlinux-6.1-yocto-mickledore-mpu-v24.06.26-addon-x-linux-ai-v5.1.0.tar.gz

Then, copy the .sh script to your OpenSTLinux SDK directory:

  cp stm32mp1-openstlinux-6.1-yocto-mickledore-mpu-v24.06.26-addon-x-linux-ai-v5.1.0/st-image-ai-openstlinux-weston-stm32mp1-x86_64-toolchain-4.2.4-openstlinux-6.1-yocto-mickledore-mpu-v24.06.26-addon-x-linux-ai-v5.1.0.sh <working directory absolute path>/Developer-Package/SDK
Warning white.png Warning
It is mandatory run the script inside the OpenSTLinux SDK directory.

Finally, run the script contained in the tarball:

  cd <working directory absolute path>/Developer-Package/SDK
  ./st-image-ai-openstlinux-weston-stm32mp1-x86_64-toolchain-4.2.4-openstlinux-6.1-yocto-mickledore-mpu-v24.06.26-addon-x-linux-ai-v5.1.0.sh

Optionally, once the script is executed, you can delete it.

  rm *.sh

Install add-on for STM32MP25x lines More info.png

Once the X-LINUX-AI SDK add-on is downloaded, uncompress the add-on:

Info white.png Information
The name of the tarball depends on the chosen version. In the example below the last uploaded version is used.
  cd  ~/Downloads/
  tar xzf  en.sdk-x86_64-stm32mp2-openstlinux-6.1-yocto-mickledore-mpu-v24.06.26-addon-x-linux-ai-v5.1.0.tar.gz

Then, copy the .sh script to your OpenSTLinux SDK directory:

  cp stm32mp2-openstlinux-6.1-yocto-mickledore-mpu-v24.06.26-addon-x-linux-ai-v5.1.0/st-image-ai-openstlinux-weston-stm32mp2-x86_64-toolchain-4.2.4-openstlinux-6.1-yocto-mickledore-mpu-v24.06.26-addon-x-linux-ai-v5.1.0.sh <working directory absolute path>/Developer-Package/SDK
Warning white.png Warning
It is mandatory run the script inside the OpenSTLinux SDK directory.

Finally, run the script contained in the tarball:

  cd <working directory absolute path>/Developer-Package/SDK
  ./st-image-ai-openstlinux-weston-stm32mp2-x86_64-toolchain-4.2.4-openstlinux-6.1-yocto-mickledore-mpu-v24.06.26-addon-x-linux-ai-v5.1.0.sh

Optionally, once the script is executed, you can delete it.

  rm *.sh

3.3. Start the SDK[edit | edit source]

Info white.png Information
The SDK environment setup script must be run once on each new working terminal on which you cross-compile.

The add-on is now installed into the OpenSTLinux SDK. You can start the SDK. Go to your OpenSTLinux SDK directory and source the environment:

  cd <working directory absolute path>/Developer-Package/SDK
  • On STM32MP2 series' boards More info green.png:
  source environment-setup-cortexa35-ostl-linux
  export SYSROOT="<working directory absolute path>/Developer-Package/SDK/sysroots/cortexa35-ostl-linux"
  • On STM32MP1 series' boards More info green.png:
  source environment-setup-cortexa7t2hf-neon-vfpv4-ostl-linux-gnueabi
  export SYSROOT="<working directory absolute path>/Developer-Package/SDK/sysroots/cortexa7t2hf-neon-vfpv4-ostl-linux-gnueabi"

Check that the SDK is properly installed:

  x-linux-ai -v
 X-LINUX-AI version: 5.1.0
Info white.png Information
With the x-linux-ai binary it is possible to check the X-LINUX-AI version and the supported frameworks/applications. Use x-linux-ai --help for more information.

4. Use the SDK[edit | edit source]

4.1. Build an application with the SDK[edit | edit source]

Info white.png Information
In this section, the image classification application is used as an example, but all the applications can be built with this method.

Once the SDK is correctly set up, the applications can be built easily. In this example, it is the image classification application that is built.

Download the github repository:

  git clone https://github.com/STMicroelectronics/meta-st-x-linux-ai
Warning white.png Warning
Be careful to select a tag (for example v5.1.0) in the meta-x-linux-ai GitHub which is aligned with the X-LINUX-AI SDK add-on version used.

Go to the image classification directory:

  cd meta-st-x-linux-ai/recipes-samples/image-classification/files/stai-mpu

[Optional] Modify the application before compiling it. Add for example the following piece of code at the beginning of the main function:

Open the source code using vi or other code editor:

 vi stai_mpu_image_classification.cc 

Add a print function:

 g_print("Application modified using OSTL SDK + X-LINUX-AI add-on \n");

Then, use the make command to build the application:

  make

A new file is displayed, named stai_mpu_image_classification. This is a binary file, which has been generated using the make command. It is compiled for the architecture of the board corresponding to the chosen SDK. It must now be transferred to the board.

4.2. Use the application[edit | edit source]

Warning white.png Warning
To use the application, it is mandatory to have an STM32MPU board with OpenSTLinux and X-LINUX-AI packages installed. If it is not the case, refer to the X-LINUX-AI installation guide.

Once the board is correctly set up and the X-LINUX-AI packages are installed with the right version, it is possible to send the application to the board.

Info white.png Information
The X-LINUX-AI packages versions must be the same as the ones in the X-LINUX-AI SDK add-on.

To do it, use the following command using your own IP address:

  scp -r -p stai_mpu_image_classification root@<ip_address>:/usr/local/x-linux-ai/image-classification/

Then, use the ssh protocol to connect to the board:

  ssh root@<ip_address>

On the board, go to the right directory and use the image classification script to launch the application:

  cd /usr/local/x-linux-ai/image-classification/
  ./launch_bin_image_classification.sh

This script is using the stai_mpu_image_classification application that has been compiled before.

[Optional] If in the previous part you have added the print in the main function, it should be visible in the logs of the application:

root@stm32mp2:/usr/local/x-linux-ai/image-classification# ./launch_bin_image_cla
ssification.sh 
stai wrapper used : 
machine used = stm32mp257f-ev1st
user : weston
Application modified using OSTL SDK + X-LINUX-AI add-on 
model file set to: /usr/local/x-linux-ai/image-classification/models/mobilenet/mobilenet_v2_1.0_224_int8_per_tensor.nb
label file set to: /usr/local/x-linux-ai/image-classification/models/mobilenet/labels_imagenet_2012.txt
camera framerate set to: 30
camera frame width set to: 760
camera frame height set to: 568
dual DCMIPP camera pipeline mode enabled
2 cpu core(s) available
Loading dynamically: /usr/lib/libstai_mpu_ovx.so.5
m_num_inputs 1 
m_num_outputs 1 
m_input_height 224 
m_input_width 224 
m_input_channels 3 
m_sizeInBytes 150528 
check if a CSI or USB camera is connected
/home/weston
dcmipp found
display resolution is : 1024 x 600 
Display config <= 600p 
video source used : /dev/video2 
camera pipeline configuration : video/x-raw, format=RGB16, width=760, height=568, framerate=30/1,framerate=30/1 
nn source used : /dev/video1 
nn pipeline configuration : video/x-raw, format=RGB, width=224, height=224, framerate=30/1