Skip to main content

Running FreeRTOS on the Cortex-M4 of an Apalis iMX8

Introduction

The objective of this article is to guide you through case-oriented examples on the implementation of FreeRTOS on the Cortex-M of a Apalis iMX8 System on Module, focusing on the execution of a sample application firmwares leveraging the Heterogeneous Multicore Processing architecture.

The use cases described in this article were tested and validated with FreeRTOS on the Cortex-M running alongside an embedded Linux image (Linux BSP) on the A-cores.

Prerequisites

Preparing the Environment

  1. Download the MCUXpresso SDK as described at Setting Up MCUXpresso SDK and Toolchain for Cortex-M development. For Apalis iMX8 you should download:

    • Apalis iMX8QM and Apalis iMX8QP: MIMX8QM6xxxFF
  2. Verify the source code structure from the boards/mekmimx8qm folder

    $ cd <apalis-imx8-sdk>/boards/
    $ tree -L 2
    .
    └── mekmimx8qm
    ├── cmsis_driver_examples
    ├── demo_apps
    ├── driver_examples
    ├── issdk_examples
    ├── lwip_examples
    ├── mekmimx8qm.png
    ├── mmcau_examples
    ├── multicore_examples
    ├── project_template
    └── rtos_examples
  3. Download and setup the GCC toolchain as explained at Setting Up MCUXpresso SDK and Toolchain for Cortex-M development. We recommend the Arm GNU Toolchain AArch32 bare-metal target (arm-none-eabi) for your host OS.

Case-oriented Examples

Hello World Example

  1. Go to the demo directory on the SDK folder. You might note that there are two folders, one for each Cortex-M4 core. Choose the one you want to build the application for.

    $ cd ./boards/mekmimx8qm/demo_apps/hello_world
    $ tree -L 2
    .
    ├── cm4_core0
    │   ├── armgcc
    │   ├── board.c
    │   ├── board.h
    │   ├── clock_config.c
    │   ├── clock_config.h
    │   ├── empty_rsc_table.c
    │   ├── hello_world.bin
    │   ├── hello_world.c
    │   ├── hello_world_m40_v3_8.xml
    │   ├── hello_world.mex
    │   ├── pin_mux.c
    │   ├── pin_mux.h
    │   └── readme.txt
    └── cm4_core1
    ├── armgcc
    ├── board.c
    ├── board.h
    ├── clock_config.c
    ├── clock_config.h
    ├── hello_world.bin
    ├── hello_world.c
    ├── hello_world_m41_v3_8.xml
    ├── hello_world.mex
    ├── pin_mux.c
    ├── pin_mux.h
    └── readme.tx
  2. Write and compile the necessary devicetree overlays as explained at Run the Firmware.

  3. Run the script to build the demo

    $ export ARMGCC_DIR=<PATH_TO_GCC_TOOLCHAIN>/<GCC_TOOLCHAIN_FOLDER>
    $ cd armgcc/
    $ ./build_debug.sh
  4. Copy the generated binary to your device

    $ scp debug/hello_world.bin root@<board-ip>:/home/root
  5. Load the firmware on Flash. On U-boot terminal, run the following commands

    > setenv load_cmd "ext4load mmc 0:2"
    > setenv m4_0_image "/home/root/hello_world.bin"
    > saveenv

    If you chose to use the Cortex-M4 1 instead of the Cortex-M4 0, just replace m4_0_image with m4_1_image

  6. Start the firmware at boot level

    > run m4boot_0


Send Feedback!