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
- Set up the SDK and Toolchain as described in the article Setting Up MCUXpresso SDK and Toolchain for Cortex-M development.
- Consider the architecture and memory areas of the specific i.MX-based SoC as explained in the article Cortex-M and Memory Areas Overview on Toradex SoMs
Preparing the Environment
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
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_examplesDownload 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
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.txWrite and compile the necessary devicetree overlays as explained at Run the Firmware.
Run the script to build the demo
$ export ARMGCC_DIR=<PATH_TO_GCC_TOOLCHAIN>/<GCC_TOOLCHAIN_FOLDER>
$ cd armgcc/
$ ./build_debug.shCopy the generated binary to your device
$ scp debug/hello_world.bin root@<board-ip>:/home/root
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"
> saveenvIf you chose to use the Cortex-M4 1 instead of the Cortex-M4 0, just replace
m4_0_image
withm4_1_image
Start the firmware at boot level
> run m4boot_0