Skip to content

Using the Cortex-M Cores#

Several of our SoCs contain a Cortex-M microcontroller core next to the Cortex-A application cores. The Yocto BSP (meta-ked-bsp) provides everything to run firmware on this core from Linux and to exchange messages with it:

  • the Linux remoteproc framework loads, starts and stops the firmware,
  • the rpmsg framework provides the communication channel. The demo firmware shows up as a TTY device /dev/ttyRPMSG* in Linux,
  • the mcore-autoload service starts a firmware automatically at boot,
  • a demo firmware that echoes back every message it receives.
SoC Core Default demo firmware
i.MX8M Mini Cortex-M4 imx8mm_m4_echo.elf
i.MX8M Plus Cortex-M7 imx8mp_m7_echo.elf
i.MX93 Cortex-M33 imx93_cm33_echo.elf
STM32MP157 Cortex-M4 stm32mp1_cm4_echo.elf

The images built with the BSP contain these packages:

Package Content
mcore-autoload The mcore-autoload service and its configuration
mcore-autoload-demos The rpmsg0 and rpmsg1 helper scripts
mcore-firmware-imx, mcore-firmware-stm32mp1 The demo firmware in /usr/share/mcore-application

1. Enable the Cortex-M Core#

The Cortex-M core is disabled by default. To enable it, set the U-Boot environment variable enable_mcore and reboot:

=> setenv enable_mcore 1
=> saveenv
=> boot

With enable_mcore=1 the boot script:

  • applies the devicetree overlay <soc>-kontron-rpmsg.dtbo, which adds the remoteproc node and the reserved memory for the rpmsg buffers,
  • adds clk-<soc>.mcore_booted=1 to the kernel command line, so Linux does not disable clocks the Cortex-M core needs.

To disable the core again, set enable_mcore back to 0. The mcore-autoload service then does nothing.

The Cortex-M4 core is enabled in the board devicetree. No configuration is needed.

After booting, check that the remoteproc device exists:

root@kontron-mx8mm:~# cat /sys/class/remoteproc/remoteproc0/name

2. Run the Echo Demo#

At boot, the mcore-autoload service loads and starts the default demo firmware. Check that it is running:

root@kontron-mx8mm:~# cat /sys/class/remoteproc/remoteproc0/state
running
root@kontron-mx8mm:~# cat /sys/class/remoteproc/remoteproc0/firmware
imx8mm_m4_echo.elf

The firmware announces an rpmsg channel, which Linux provides as /dev/ttyRPMSG0. The STM32MP1 demo announces a second one, /dev/ttyRPMSG1. The helper scripts rpmsg0 and rpmsg1 send a message to the firmware over the respective channel and print the answer:

root@kontron-mx8mm:~# rpmsg0 hello world
hello world

You can also use the TTY device directly:

root@kontron-mx8mm:~# stty -onlcr -echo -F /dev/ttyRPMSG0
root@kontron-mx8mm:~# cat /dev/ttyRPMSG0 &
root@kontron-mx8mm:~# echo "hello world" > /dev/ttyRPMSG0
hello world

3. Load a Different Firmware#

Using mcore-autoload#

mcore-autoload stops the running firmware and starts the given one. It takes a file name from /usr/share/mcore-application or an absolute path:

root@kontron-mx8mm:~# mcore-autoload start /home/root/my_app.elf

Other commands are stop and restart.

Using the remoteproc sysfs Interface#

The firmware file must be in /lib/firmware:

root@kontron-mx8mm:~# cp my_app.elf /lib/firmware/
root@kontron-mx8mm:~# echo stop > /sys/class/remoteproc/remoteproc0/state
root@kontron-mx8mm:~# echo -n my_app.elf > /sys/class/remoteproc/remoteproc0/firmware
root@kontron-mx8mm:~# echo start > /sys/class/remoteproc/remoteproc0/state

4. Change the Firmware Started at Boot#

mcore-autoload reads its configuration from /etc/default/mcore-autoload.conf. It takes the name of the firmware to start from the first of these that is set:

  1. APPLICATION_NAME in the configuration file, if set,
  2. the devicetree property /mcore-application, if present,
  3. APPLICATION_DEFAULT in the configuration file.

To start your own firmware at boot, set APPLICATION_NAME:

/etc/default/mcore-autoload.conf
APPLICATION_NAME="my_app.elf"

To start no firmware at boot, set it to an empty value:

/etc/default/mcore-autoload.conf
APPLICATION_NAME=

In your own Yocto layer, provide the configuration file with a mcore-autoload.bbappend.

5. Build Your Own Firmware#

The source code of the demo firmware is in the cortex-m-demos repository. It contains a minimal copy of the NXP MCUXpresso SDK and the ST STM32CubeMP1 package and a build system for all supported SoCs. Use it as starting point for your own application. The README.md explains how to add an application.

The BSP builds the echo demo from this repository with the recipes mcore-firmware-imx and mcore-firmware-stm32mp1.

Platform Notes#

Peripheral Access#

The demo firmware only uses memory and the messaging unit. If your firmware uses peripherals (UART, GPIO, timers, ...), they must be:

  • disabled in the Linux devicetree, so Linux does not use them, and
  • assigned to the Cortex-M core in the SoC's resource isolation unit, if it is configured:
    • i.MX8M: RDC, configured in TF-A,
    • i.MX93: TRDC, configured in TF-A,
    • STM32MP1: ETZPC, configured in the devicetree. For peripherals in the m4_system_resources node, enable the respective subnode.

Accessing a peripheral the core has no access to usually locks up the system.

Memory Layout#

The firmware must be linked for the memory reserved for it in the devicetree. The demo firmware and the devicetree overlays of the BSP match. If you change the memory layout, change both.

Debug Output#

The NXP demo firmware does not use a debug UART, because all UARTs are assigned to Linux by default. Use the rpmsg channel for output, or assign a UART to the Cortex-M core as described above.

References#