### Running TensorFlow Lite Inference with X-LINUX-AI Package Source: https://context7.com/stmicroelectronics/stm32mpu_embsw_overall_offer/llms.txt This snippet demonstrates how to add the X-LINUX-AI layer to a Yocto build, build an image with AI support, and then run a TensorFlow Lite inference example on the target device using Python. ```bash # Add X-LINUX-AI layer to your Yocto build cd layers git clone https://github.com/STMicroelectronics/meta-st-stm32mpu-ai.git # Add layer to bblayers.conf bitbake-layers add-layer meta-st-stm32mpu-ai # Build image with AI support DISTRO=openstlinux-weston MACHINE=stm32mp1 bitbake st-image-weston # On target: Run TensorFlow Lite inference example python3 -c " import tflite_runtime.interpreter as tflite import numpy as np # Load model interpreter = tflite.Interpreter(model_path='model.tflite') interpreter.allocate_tensors() # Get input/output details input_details = interpreter.get_input_details() output_details = interpreter.get_output_details() # Run inference input_data = np.array(np.random.random_sample(input_details[0]['shape']), dtype=np.float32) interpreter.set_tensor(input_details[0]['index'], input_data) interpreter.invoke() output_data = interpreter.get_tensor(output_details[0]['index']) print(f'Inference result: {output_data}') " ``` -------------------------------- ### Initializing GPIO with STM32Cube HAL for STM32MP1 Cortex-M4 Source: https://context7.com/stmicroelectronics/stm32mpu_embsw_overall_offer/llms.txt This C code example demonstrates how to initialize the HAL library, configure a GPIO pin (GPIOA, pin 14) as an output, and toggle an LED in a loop using STM32Cube HAL drivers for STM32MP1 Cortex-M4 processors. ```c #include "stm32mp1xx_hal.h" int main(void) { /* Initialize HAL library */ HAL_Init(); /* Configure GPIO pin for LED control */ GPIO_InitTypeDef GPIO_InitStruct = {0}; __HAL_RCC_GPIOA_CLK_ENABLE(); GPIO_InitStruct.Pin = GPIO_PIN_14; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); /* Toggle LED in main loop */ while (1) { HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_14); HAL_Delay(500); } } ``` -------------------------------- ### Inter-Processor Communication with OpenAMP/RPMsg Source: https://context7.com/stmicroelectronics/stm32mpu_embsw_overall_offer/llms.txt Facilitates communication between Cortex-A (Linux) and Cortex-M processors using OpenAMP and RPMsg. This includes example code for both the Cortex-M4 firmware and the Linux host, demonstrating message sending and receiving over the RPMsg TTY interface. ```c /* Cortex-M4 firmware example using OpenAMP/RPMsg */ #include "openamp/open_amp.h" #include "metal/alloc.h" static struct rpmsg_endpoint rp_ept; static char rx_buffer[512]; static int rpmsg_endpoint_cb(struct rpmsg_endpoint *ept, void *data, size_t len, uint32_t src, void *priv) { memcpy(rx_buffer, data, len); /* Process received message from Linux */ /* Send response back */ const char *response = "ACK from M4"; rpmsg_send(ept, response, strlen(response) + 1); return RPMSG_SUCCESS; } int main(void) { struct metal_device *device; struct rpmsg_virtio_device *rpmsg_vdev; /* Initialize metal library and create virtio device */ metal_init(&metal_params); /* Create RPMsg endpoint for communication */ rpmsg_create_ept(&rp_ept, rpmsg_vdev, "stm32-rpmsg", RPMSG_ADDR_ANY, RPMSG_ADDR_ANY, rpmsg_endpoint_cb, NULL); while (1) { /* Handle virtio callbacks */ rproc_virtio_notified(rpmsg_vdev->vdev, VRING_NOTIFY_HOST); } } ``` ```bash # Linux side: Load remoteproc firmware and communicate echo stop > /sys/class/remoteproc/remoteproc0/state echo firmware.elf > /sys/class/remoteproc/remoteproc0/firmware echo start > /sys/class/remoteproc/remoteproc0/state # Send message via RPMsg TTY echo "Hello M4" > /dev/ttyRPMSG0 cat /dev/ttyRPMSG0 # Read response ``` -------------------------------- ### Secure Storage Trusted Application with OP-TEE Source: https://context7.com/stmicroelectronics/stm32mpu_embsw_overall_offer/llms.txt Example of a Trusted Application (TA) for secure storage using OP-TEE. This C code demonstrates how to create and manage persistent objects in a secure environment, handling commands for writing and reading data. It relies on the OP-TEE internal API. ```c #include #include #define TA_SECURE_STORAGE_CMD_WRITE 0 #define TA_SECURE_STORAGE_CMD_READ 1 TEE_Result TA_CreateEntryPoint(void) { return TEE_SUCCESS; } TEE_Result TA_InvokeCommandEntryPoint(void *sess_ctx, uint32_t cmd_id, uint32_t param_types, TEE_Param params[4]) { TEE_ObjectHandle object; TEE_Result res; switch (cmd_id) { case TA_SECURE_STORAGE_CMD_WRITE: res = TEE_CreatePersistentObject(TEE_STORAGE_PRIVATE, params[0].memref.buffer, params[0].memref.size, TEE_DATA_FLAG_ACCESS_WRITE, TEE_HANDLE_NULL, params[1].memref.buffer, params[1].memref.size, &object); if (res == TEE_SUCCESS) TEE_CloseObject(object); return res; case TA_SECURE_STORAGE_CMD_READ: res = TEE_OpenPersistentObject(TEE_STORAGE_PRIVATE, params[0].memref.buffer, params[0].memref.size, TEE_DATA_FLAG_ACCESS_READ, &object); if (res == TEE_SUCCESS) { TEE_ReadObjectData(object, params[1].memref.buffer, params[1].memref.size, ¶ms[1].memref.size); TEE_CloseObject(object); } return res; default: return TEE_ERROR_BAD_PARAMETERS; } } ``` -------------------------------- ### Device Tree Overlay for I2C Peripheral on STM32MP1 Source: https://context7.com/stmicroelectronics/stm32mpu_embsw_overall_offer/llms.txt This device tree snippet shows an overlay configuration for enabling the I2C1 peripheral on an STM32MP1 platform. It configures the necessary pins, enables the peripheral, and defines an example I2C sensor (tmp102) at address 0x48. ```dts /dts-v1/; /plugin/; &i2c1 { status = "okay"; pinctrl-names = "default", "sleep"; pinctrl-0 = <&i2c1_pins_a>; pinctrl-1 = <&i2c1_sleep_pins_a>; i2c-scl-rising-time-ns = <100>; i2c-scl-falling-time-ns = <7>; /* Example I2C sensor device */ sensor@48 { compatible = "ti,tmp102"; reg = <0x48>; }; }; ``` -------------------------------- ### Setting up OpenSTLinux Distribution for STM32MPU Source: https://context7.com/stmicroelectronics/stm32mpu_embsw_overall_offer/llms.txt This snippet outlines the steps to initialize the STM32MPU development environment using the repo tool, sync the OpenEmbedded manifest, set up the build environment, build the complete st-image-weston image, and flash it to an SD card. ```bash mkdir stm32mpu-openstlinux && cd stm32mpu-openstlinux repo init -u https://github.com/STMicroelectronics/oe-manifest.git -b refs/tags/openstlinux-6.1-yocto-mickledore-mpu-v24.06.26 repo sync DISTRO=openstlinux-weston MACHINE=stm32mp1 source layers/meta-st/scripts/envsetup.sh bitbake st-image-weston dd if=tmp-glibc/deploy/images/stm32mp1/st-image-weston-stm32mp1.wic of=/dev/sdX bs=1M conv=fdatasync status=progress ``` -------------------------------- ### Building and Flashing STM32DDRFW-UTIL for DDR Initialization Source: https://context7.com/stmicroelectronics/stm32mpu_embsw_overall_offer/llms.txt This bash script shows how to clone the STM32DDRFW-UTIL repository, build the firmware for STM32MP1, and flash it to the device using STM32CubeProgrammer for interactive DDR testing. ```bash # Clone and build DDR firmware utility git clone https://github.com/STMicroelectronics/STM32DDRFW-UTIL.git cd STM32DDRFW-UTIL # Build for STM32MP1 make CROSS_COMPILE=arm-none-eabi- DEVICE=stm32mp1 clean all # Flash DDR firmware for interactive testing via STM32CubeProgrammer STM32_Programmer_CLI -c port=usb1 -w build/stm32mp1/tf-a-stm32mp157c-ev1-ddr.stm32 0x01 -s # DDR test commands available in firmware console: # > help - Display available commands # > test - Run all DDR tests # > test 0 - Run basic read/write test # > test 1 - Run data bus test # > test 2 - Run address bus test ``` -------------------------------- ### OTP Programming Utility for STM32MPU Source: https://context7.com/stmicroelectronics/stm32mpu_embsw_overall_offer/llms.txt Manages One-time Programmable (OTP) memory on STM32MPU devices. This utility allows reading, writing, and locking OTP memory words, essential for device configuration and security. It requires cloning the repository and building the utility using a cross-compiler. ```bash git clone https://github.com/STMicroelectronics/STM32PRGFW-UTIL.git cd STM32PRGFW-UTIL make CROSS_COMPILE=arm-none-eabi- DEVICE=stm32mp1 clean all # Example OTP commands: # > otp read all - Read all OTP values # > otp read 0 - Read OTP word 0 # > otp write 57 0x00000001 - Write value to OTP word 57 # > otp lock 57 - Permanently lock OTP word 57 # Example: Read MAC address from OTP (words 57-58) # > otp read 57 # OTP 57: 0x12345678 # > otp read 58 # OTP 58: 0x00009ABC # MAC Address: 78:56:34:12:BC:9A ``` -------------------------------- ### OTP Programming Utility Source: https://context7.com/stmicroelectronics/stm32mpu_embsw_overall_offer/llms.txt Interface for reading, writing, and locking One-time Programmable (OTP) memory words on STM32MPU devices. ```APIDOC ## OTP Management Commands ### Description Provides access to the OTP memory controller for reading, writing, and securing specific memory words. ### Method CLI/Serial Console ### Endpoint otp [command] [args] ### Parameters #### Path Parameters - **command** (string) - Required - The operation to perform: read, write, or lock. - **word_index** (integer) - Required - The target OTP word index. - **value** (hex) - Optional - The data value to write (for write command). ### Request Example > otp write 57 0x00000001 ### Response #### Success Response (200) - **output** (string) - Confirmation message or requested OTP word value. ``` -------------------------------- ### OP-TEE Secure Storage API Source: https://context7.com/stmicroelectronics/stm32mpu_embsw_overall_offer/llms.txt Trusted Application interface for performing secure read and write operations within the TEE environment. ```APIDOC ## TA_InvokeCommandEntryPoint ### Description Handles secure storage commands within a Trusted Application (TA) running in OP-TEE. ### Method TEE_InvokeCommand ### Parameters #### Request Body - **cmd_id** (uint32) - Required - Command identifier (0 for WRITE, 1 for READ). - **params** (TEE_Param[4]) - Required - Buffer references for data and object identifiers. ### Request Example { "cmd_id": 0, "params": [ { "buffer": "data_id" }, { "buffer": "payload" } ] } ### Response #### Success Response (0) - **result** (TEE_Result) - Returns TEE_SUCCESS upon completion. ``` -------------------------------- ### OpenAMP RPMsg Communication Source: https://context7.com/stmicroelectronics/stm32mpu_embsw_overall_offer/llms.txt Enables messaging between the Linux host and the Cortex-M4 co-processor using the RPMsg protocol. ```APIDOC ## RPMsg TTY Interface ### Description Allows Linux user-space applications to send and receive messages from the Cortex-M4 firmware via a TTY device. ### Method File I/O ### Endpoint /dev/ttyRPMSG0 ### Request Example echo "Hello M4" > /dev/ttyRPMSG0 ### Response #### Success Response (200) - **output** (string) - Data read from /dev/ttyRPMSG0 representing the M4 response. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.