Personal tools

Running a Cortex-M4 application on visionsom-stm32mp1

From SomLabs Wiki

Jump to: navigation, search

Running a Cortex-M4 application on VisionSOM-STM32MP1

This article explains how to configure the OpenSTLinux system for running a Cortex-M4 application. In this tutorial an example code as well as the required kernel modules from STMicroelectronics will be used. This tutorial was prepared for the openstlinux-5.4-dunfell-mp1-20-06-24 with the SoMLabs dunfell meta-layer available on github:

Modifying the device tree

To configure the Cortex-M4 access from Linux some changes in the SoMlabs meta-layer device tree are required. The following device tree sections need to be added in the following files, depending on the used display version (RGB or DSI):

  • mx/visionsom-dsi-mx/kernel/stm32mp157a-visionsom-dsi-mx.dts
  • mx/visionsom-dsi-mx/u-boot/stm32mp157a-visionsom-dsi-mx.dts


  • mx/visionsom-mx/kernel/stm32mp157a-visionsom-mx.dts
  • mx/visionsom-mx/u-boot/stm32mp157a-visionsom-mx.dts

All changed need to be done in both files - the u-boot and kernel dts. After applying the changes a new system image needs to be built and installed. Alternatively only the dtb file may be copied to the target system by replacing the previous one.

Memory regions definitions

Add the following reserved memory sections (mcuram2, vdev0vring0, vdev0vring1, vdev0buffer, mcuram, retram) in the main device tree node.

        reserved-memory {
                #address-cells = <1>;
                #size-cells = <1>;

                /* USER CODE BEGIN reserved-memory */

                fb_reserved: fb@fd000000 {
                        reg = <0xfd000000 0x8000000>;

                mcuram2: mcuram2@10000000 {
                        compatible = "shared-dma-pool";
                        reg = <0x10000000 0x40000>;

                vdev0vring0: vdev0vring0@10040000 {
                        compatible = "shared-dma-pool";
                        reg = <0x10040000 0x1000>;

                vdev0vring1: vdev0vring1@10041000 {
                        compatible = "shared-dma-pool";
                        reg = <0x10041000 0x1000>;

                vdev0buffer: vdev0buffer@10042000 {
                        compatible = "shared-dma-pool";
                        reg = <0x10042000 0x4000>;

                mcuram: mcuram@30000000 {
                        compatible = "shared-dma-pool";
                        reg = <0x30000000 0x40000>;

                retram: retram@38000000 {
                        compatible = "shared-dma-pool";
                        reg = <0x38000000 0x10000>;

                /* USER CODE END reserved-memory */

M4 remote processor

Modify the &m4_rproc node by setting the mboxes, memory regions and interrupts.

        status = "okay";

        /* USER CODE BEGIN m4_rproc */

        memory-region = <&retram>, <&mcuram>, <&mcuram2>, <&vdev0vring0>,
                        <&vdev0vring1>, <&vdev0buffer>;
        mboxes = <&ipcc 0>, <&ipcc 1>, <&ipcc 2>;
        mbox-names = "vq0", "vq1", "shutdown";
        interrupt-parent = <&exti>;
        interrupts = <68 1>;

        /* USER CODE END m4_rproc */

                status = "okay";

                /* USER CODE BEGIN m4_system_resources */
                /* USER CODE END m4_system_resources */


Add the memory in the &dma1 node.

        status = "okay";

        /* USER CODE BEGIN dma1 */

        sram = <&dma_pool>;

        /* USER CODE END dma1 */


Add the new &ipcc node.

&ipcc {
       status = "okay";


Add the new &sram node with dma_pool.

&sram {
       dma_pool: dma_pool@0 {
                reg = <0x50000 0x10000>;

Running the Cortex-M4 example

A ready to run Cortex-M4 application is available to download from here: This file should be extracted to the /lib/firmware/ directory of the target system. In order to run it, the following commands should be executed:

cd /sys/class/remoteproc/remoteproc0
echo "OpenAMP_TTY_echo.elf" > firmware
echo start > state

This example creates two new devices in /dev directory: ttyRPMSG0 and ttyRPMSG1. They may be used to communicate witn the Cortex-M4 application.

stty -onlcr -echo -F /dev/ttyRPMSG0
cat /dev/ttyRPMSG0 &
stty -onlcr -echo -F /dev/ttyRPMSG1
cat /dev/ttyRPMSG1 &
echo "Hello Virtual UART0" >/dev/ttyRPMSG0
echo "Hello Virtual UART1" >/dev/ttyRPMSG1

The Cortex-M4 logging is redirected to the shared memory which can be read from the trace file:

cat /sys/kernel/debug/remoteproc/remoteproc0/trace0

This example is taken from the STM32CubeMP1-1.2.0 code package available on STMicroelectronics website:

For more information regarding the Cortex-M4 application building please refer to the official STMicroelectronics docummentation:,_rebuild_and_reload_a_firmware

NXP Partner ST Partner Renesas Partner