The STM32MP157 SOC platform includes a low-power Cortex-M4 processor with a low gate count and low interrupt latency. The Cortex-M4 implements the ARMv7E-M instruction set architecture (ISA) and adds significant capabilities with digital signal processor (DSP) and single instruction multiple data (SIMD) extensions. The Cortex-M4 operates as a coprocessor, either autonomously as any external microcontroller (such as an STM32F4) could, or by communicating with the main processor (Cortex-A7) via the RPMsg communication pipe.

1. Download the SDK and toolchain

Before building the Cortex-M4 firmware, you must download and install the SDK, which includes example applications and the toolchain to build your firmware application.

STMicroelectronics offers an IDE that facilitates firmware development for the Cortex-M4 core. The SDK provides examples demonstrating how to access the peripherals available on this subsystem.

  1. Go to https://www.st.com/en/development-tools/stm32cubeide.html.

    You may have to register with STMicroelectronics.
  2. Click Get latest for your OS.

2. Install the IDE, SDK and toolchain

Decompress and install the IDE in your PC. The installation includes the SDK and Cortex-M4 examples.

3. Build a demo application

  1. Launch the STM32CubeIDE on your PC.

  2. Go into the workspace project view and import an existing project. Each project example contains a top project and sub project.

  3. Select both projects, for instance OpenAMP_TTY_echo and OpenAMP_TTY_echo_M4, and click the Build button on the IDE. This creates an *.elf file at Applications\OpenAMP\OpenAMP_TTY_echo\STM32CubeIDE\CM4\Debug\OpenAMP_TTY_echo_M4.elf. (This path may vary based on your installation location.)

  4. Load the file onto on the Cortex-M4.

For more information, see Modify, rebuild and reload a firmware.

4. Deploy the application onto the target

There are several ways to deploy the application onto the Cortex-M4:

4.1. Run your application with Remoteproc from Linux

The remote processor (RPROC) framework allows the different platforms/architectures to control (power on, load firmware, power off) remote processors while abstracting the hardware differences. The application must either be stored on a partition of an external device or included in the rootfs image.

The firmware components are stored in the file system, by default in the /lib/firmware/ folder. You can optionally set a different location with the following command:

# echo -n <firmware_path> > /sys/module/firmware_class/parameters/path

Note that if a location is provided, the remoteproc framework parses this path first.

  1. Load the firmware application on the target device, where X is the remoteproc instance number, set to 0 by default:

    # echo -n <firmware_name.elf> > /sys/class/remoteproc/remoteprocX/firmware
  2. Start the firmware:

    # echo start > /sys/class/remoteproc/remoteprocX/state
  3. When the firmware is running, access the output log from the firmware with:

    # cat /sys/kernel/debug/remoteproc/remoteprocX/trace0
  4. Stop the running firmware with:

    # echo stop > /sys/class/remoteproc/remoteprocX/state
  5. Start Linux and let it run the firmware automatically at boot if the st,auto_boot property is defined in the remoteproc device tree node.

    Linux device tree
      &m4_rproc {
        st,auto-boot = <1>;
    };

For more information about the STM32CubeIDE, see https://wiki.st.com/stm32mpu/wiki/Category:STM32CubeIDE.

4.2. Boot your application from U-Boot

You can load and start the firmware application from U-Boot with the rproc command. Note that this example is reading the file from a USB stick into RAM memory.

=> usb start
=> fatload usb 0:1 ${loadaddr} <firmware_name.elf>
=> rproc init
=> rproc load 0 ${loadaddr} ${filesize}

Once you have loaded the firmware application, you can run the firmware from U-Boot:

=> rproc start 0

Launch and debug your application using a debugger

You can use this ST-LINK debuggerV2 or this ST-LINK_debuggerV3 debugger to download and debug the firmware through the IDE.

To download and debug your application, first create a debug connection in the IDE.

  1. Select your CM4 project

  2. Right click on the project and select Debug As > Debug configurations This opens the debug configuration panel

  3. If not already created, create your debug configuration by clicking on the STM32 C/C++ Application and opening the Debugger panel.

  4. On the Debugger tab, select thru Linuxcore (Production mode) This requires that your target is running a Linux OS.

  5. Select the ST-Link serial port available on the Serial Port. The IDE will automatically detect ST-Link serial port and use it to manage the firmware download.

  6. Set the IP address of your target in the Inet Address field. The IDE will create a SSH connection to the target for the firmware download.

  7. When all configurations are done, click Apply.

For the best GDB debug experience, Digi recommends you upgrade the onboard ST-Link version with the latest release by going to Help > ST-Link Upgrade in the STM32CubeIDE menu.

For more information, refer to the STM32CubeIDE documentation.