Loading Firmware to the M4 Core and Using RPMSG for Inter-core Communications Print

On the STM32MP1 device the M4 core is loaded from Linux running on the Cortex-A core. This application note explains how to run the following M4 demo, included with the Emcraft Linux BSP:


This demo has the M4 talking to Linux using the RPMSG messaging interface. On the Linux side, there is a procfs based interface that is used to load a pre-built binary to the M4 core from a file in the Linux file system.

The following session illustrates load of the demo firmware to the M4 core from the Linux shell on the Emcraft STM32MP1 Starter Kit:

root@stm32mp1-som:~# cd  /usr/local/Cube-M4-examples/STM32MP157C-DK2/Applications/OpenAMP/OpenAMP_TTY_echo
root@stm32mp1-som:OpenAMP_TTY_echo# ./fw_cortex_m4.sh start
start fw_cortex_m4.sh: fmw_name=OpenAMP_TTY_echo.elf
[ 35.633424] remoteproc remoteproc0: powering up m4
[ 35.637482] remoteproc remoteproc0: Booting fw image OpenAMP_TTY_echo.elf, size 216156
[ 35.645776] virtio_rpmsg_bus virtio0: rpmsg host is online
[ 35.650348] virtio_rpmsg_bus virtio0: creating channel rpmsg-tty-channel addr 0x0
[ 35.658268] rpmsg_tty virtio0.rpmsg-tty-channel.-1.0: new channel: 0x400 -> 0x0 : ttyRPMSG0
[ 35.659385] remoteproc remoteproc0: registered virtio0 (type 7)
[ 35.659395] remoteproc remoteproc0: remote processor m4 is now up
[ 35.678164] virtio_rpmsg_bus virtio0: creating channel rpmsg-tty-channel addr 0x1
[ 35.688034] rpmsg_tty virtio0.rpmsg-tty-channel.-1.1: new channel: 0x401 -> 0x1 : ttyRPMSG1

The demo shows use of the Linux RPMSG messaging framework for inter-communications between Linux running on the Cortex-A core and firmware running on the Cortex-M4 core. More specifically:

  • M4 core configures the IPCC peripheral and sets up the RPMSG infrastructure
  • M4 core creates 2 RPMSG channels for 2 virtual UART instances UART0 and UART1
  • M4 waits for messages from the Cortex-A core on these two channels
  • When M4 receives a message on a virtual UART instance, it sends the message back to the Cortex-A core on the same virtual UART interface.

Note that M4 log messages are redirected to a shared memory region in the MCUSRAM and can be displayed from the Linux shell using the following command:

root@stm32mp1-som:~# cat /sys/kernel/debug/remoteproc/remoteproc0/trace0

The following session runs the demo from the Linux serial console:

root@stm32mp1-som:~# stty -onlcr -echo -F /dev/ttyRPMSG0
root@stm32mp1-som:~# cat /dev/ttyRPMSG0 &
root@stm32mp1-som:~# stty -onlcr -echo -F /dev/ttyRPMSG1
root@stm32mp1-som:~# cat /dev/ttyRPMSG1 &
root@stm32mp1-som:~# echo "Hello Virtual UART0" >/dev/ttyRPMSG0
root@stm32mp1-som:~# echo "Hello Virtual UART1" >/dev/ttyRPMSG1

Having executed the above commands, you should see Hello Virtual UART0 and Hello Virtual UART1 in the Linux console.