Running a Cortex-M4 application on visionsom-stm32mp1 scarthgap
From SomLabs Wiki
Running a Cortex-M4 application on VisionSOM-STM32MP1 and Yocto Scarthgap
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-6.6-yocto-scarthgap-mpu-v24.12.05 with the SoMLabs scarthgap meta-layer available on github: https://github.com/SoMLabs/openst-meta-somlabs/tree/scarthgap
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 (HDMI or DSI):
- mx/stm32mp157a-dsi-rvt70hsmnwc00-emmc-mx/kernel/stm32mp157a-dsi-rvt70hsmnwc00-emmc-mx.dts
- mx/stm32mp157a-dsi-rvt70hsmnwc00-emmc-mx/u-boot/stm32mp157a-dsi-rvt70hsmnwc00-emmc-mx.dts
or
- mx/stm32mp157a-hdmi-lt8912b-emmc-mx/kernel/stm32mp157a-hdmi-lt8912b-emmc-mx.dts
- mx/stm32mp157a-hdmi-lt8912b-emmc-mx/u-boot/stm32mp157a-hdmi-lt8912b-emmc-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 in the main device tree node.
reserved-memory {
#address-cells = <1>;
#size-cells = <1>;
ranges;
fb_reserved: fb@fd000000 {
reg = <0xfd000000 0x8000000>;
no-map;
};
mcuram2: mcuram2@10000000 {
compatible = "shared-dma-pool";
reg = <0x10000000 0x40000>;
no-map;
};
vdev0vring0: vdev0vring0@10040000 {
compatible = "shared-dma-pool";
reg = <0x10040000 0x1000>;
no-map;
};
vdev0vring1: vdev0vring1@10041000 {
compatible = "shared-dma-pool";
reg = <0x10041000 0x1000>;
no-map;
};
vdev0buffer: vdev0buffer@10042000 {
compatible = "shared-dma-pool";
reg = <0x10042000 0x4000>;
no-map;
};
mcu_rsc_table: mcu-rsc-table@10048000 {
compatible = "shared-dma-pool";
reg = <0x10048000 0x8000>;
no-map;
};
mcuram: mcuram@30000000 {
compatible = "shared-dma-pool";
reg = <0x30000000 0x40000>;
no-map;
};
retram: retram@38000000 {
compatible = "shared-dma-pool";
reg = <0x38000000 0x10000>;
no-map;
};
};
M4 remote processor
Add the &m4_rproc node and set the mboxes, memory regions and interrupts.
&m4_rproc{
status = "okay";
memory-region = <&retram>, <&mcuram>, <&mcuram2>, <&vdev0vring0>,
<&vdev0vring1>, <&vdev0buffer>, <&mcu_rsc_table>;
mboxes = <&ipcc 0>, <&ipcc 1>, <&ipcc 2>, <&ipcc 3>;
mbox-names = "vq0", "vq1", "shutdown", "detach";
interrupt-parent = <&exti>;
interrupts = <68 1>;
wakeup-source;
resets = <&scmi_reset RST_SCMI_MCU>,
<&scmi_reset RST_SCMI_MCU_HOLD_BOOT>;
reset-names = "mcu_rst", "hold_boot";
};
Running the Cortex-M4 example
A ready to run Cortex-M4 application is available to download from here: OpenAMP_TTY_echo_CM4.zip. 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_CM4.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.7.0 code package available on STMicroelectronics website: https://www.st.com/en/embedded-software/stm32cubemp1.html.
For more information regarding the Cortex-M4 application building please refer to the official STMicroelectronics docummentation: https://wiki.st.com/stm32mpu/wiki/Getting_started/STM32MP1_boards/STM32MP157x-EV1/Develop_on_Arm%C2%AE_Cortex%C2%AE-M4/Modify,_rebuild_and_reload_a_firmware