Setting Up MCUXpresso SDK and Toolchain for Cortex-M development
Introduction
MCUXpresso SDK is a collection of software responsible for compiling bare metal C and FreeRTOS to Cortex-M on HMP NXP processors. In addition to these base software, it includes many examples of different applications for Cortex-M. Check the MCUXpresso Software Development Kit (SDK) for more information.
Download MCUXpresso SDK
You will need a NXP account to continue with the steps below.
Go to MCUXpresso SDK Builder.
Click on Select Development Board.
Search for the right version based on the processor of your module.
Below you can see all MCUXpresso SDK based on the module you are using.
Product MCUXpresso SDK Apalis iMX8QM MIMX8QM6xxxFF Apalis iMX8QP MIMX8QM6xxxFF Colibri iMX8DX MIMX8UX5xxxFZ Colibri iMX8QXP MIMX8QX5xxxFZ Colibri iMX7S/iMX7D Toradex Github: FreeRTOS-Colibri-iMX7 Verdin iMX8M Mini DualLite MIMX8MM3xxxLZ Verdin iMX8M Mini DualLite WB IT MIMX8MM3xxxKZ Verdin iMX8M Mini Quad MIMX8MM6xxxKZ Verdin iMX8M Plus Quad MIMX8ML8xxxKZ Verdin iMX8M Plus QuadLite MIMX8ML4xxxKZ infoSDK for Colibri iMX7 is not available on MCUXpresso SDK website anymore. You will need to clone the repository in your computer to compile the examples.
After selecting your SDK, click on Build MCUXpresso SDK.
Select your Host and Toolchain options. For this article, we used Linux as the host and GCC as the toolchain.
Select which configurations you want to add to your SDK. Here we used the multicore and FreeRTOS SDKs, which are the default options. Then, click on DOWNLOAD SDK.
Accept the software terms and conditions and download the file.
Extract the downloaded file to a folder in your host machine. For this guide, we extracted the contents to the
~/cortex-m/
directory.
Download the GCC Toolchain
Go to Arm GNU Toolchain Downloads and choose AArch32 bare-metal target (arm-none-eabi) for your host OS. Download the latest version for your OS. In this guide, we used gcc-arm-11.2-2022.02-x86_64-arm-none-eabi.tar.xz for Linux OS.
Extract the file into a folder on your computer. We used the
~/cortex-m/toolchain/<GCC_TOOLCHAIN_FOLDER>/
folder for this example.
Compile your first binary
Before starting, make sure you have cmake
installed in your system. In Debian based OSs, this can be achieved by running
$ sudo apt install cmake
Go to the folder where you extracted your SDK.
$ cd ~/cortex-m/<SDK_FOLDER>/
[OPTIONAL] Create a git repository inside of it. This will help keep track of any modifications done to the software.
$ git init
$ git add .
$ git commit -m "Initial Commit"This
.gitignore
file will help you with your build files, you can place it inside<SDK_FOLDER>
:CMakeCache.txt
build_log.txt
CMakeFiles
boards/*/**/armgccGo to the build directory of the hello-world project.
infoIf you are compiling this code for Apalis iMX8, you will see an additional folder to choose for which Cortex-M core you want to build your code. You can choose either core 1 or core 0.
$ cd ./boards/<PROCESSOR_ID>/demo_apps/hello_world/armgcc/
In this folder there are several build scripts. We will use the
build_debug.sh
for this tutorial, but you can use the others scripts as well. Before running the script tough, we need to export theARMGCC_DIR
environment variable to<GCC_TOOLCHAIN_FOLDER>
. This variable must store the root directory of the GCC toolchain.$ export ARMGCC_DIR=~/cortex-m/toolchain/<GCC_TOOLCHAIN_FOLDER>
$ ./build_debug.shThe final compiled binary will be inside the
armgcc/debug
folder. If everything worked, you should this output:-- TOOLCHAIN_DIR: /home/user/cortex-m/toolchain/gcc-arm-11.2-2022.02-x86_64-arm-none-eabi
-- BUILD_TYPE: debug
-- TOOLCHAIN_DIR: /home/user/cortex-m/toolchain/gcc-arm-11.2-2022.02-x86_64-arm-none-eabi
-- BUILD_TYPE: debug
-- The ASM compiler identification is GNU
-- Found assembler: /home/user/cortex-m/toolchain/gcc-arm-11.2-2022.02-x86_64-arm-none-eabi/bin/arm-none-eabi-gcc
-- The C compiler identification is GNU 11.2.1
-- The CXX compiler identification is GNU 11.2.1
-- Configuring done
-- Generating done
-- Build files have been written to: /home/user/cortex-m/SDK_2_9_0_MIMX8QX5xxxFZ/boards/mekmimx8qx/demo_apps/hello_world/armgcc
Scanning dependencies of target hello_world.elf
[ 16%] Building C object CMakeFiles/hello_world.elf.dir/home/user/cortex-m/SDK_2_9_0_MIMX8QX5xxxFZ/boards/mekmimx8qx/demo_apps/hello_world/clock_config.c.obj
[ 16%] Building C object CMakeFiles/hello_world.elf.dir/home/user/cortex-m/SDK_2_9_0_MIMX8QX5xxxFZ/boards/mekmimx8qx/demo_apps/hello_world/pin_mux.c.obj
[ 16%] Building C object CMakeFiles/hello_world.elf.dir/home/user/cortex-m/SDK_2_9_0_MIMX8QX5xxxFZ/boards/mekmimx8qx/demo_apps/hello_world/hello_world.c.obj
[ 16%] Building C object CMakeFiles/hello_world.elf.dir/home/user/cortex-m/SDK_2_9_0_MIMX8QX5xxxFZ/boards/mekmimx8qx/demo_apps/hello_world/empty_rsc_table.c.obj
[ 20%] Building C object CMakeFiles/hello_world.elf.dir/home/user/cortex-m/SDK_2_9_0_MIMX8QX5xxxFZ/devices/MIMX8QX6/utilities/debug_console_lite/fsl_debug_console.c.obj
[ 24%] Building C object CMakeFiles/hello_world.elf.dir/home/user/cortex-m/SDK_2_9_0_MIMX8QX5xxxFZ/boards/mekmimx8qx/demo_apps/hello_world/board.c.obj
[ 32%] Building C object CMakeFiles/hello_world.elf.dir/home/user/cortex-m/SDK_2_9_0_MIMX8QX5xxxFZ/devices/MIMX8QX6/drivers/fsl_common.c.obj
[ 32%] Building C object CMakeFiles/hello_world.elf.dir/home/user/cortex-m/SDK_2_9_0_MIMX8QX5xxxFZ/components/uart/fsl_adapter_lpuart.c.obj
[ 36%] Building C object CMakeFiles/hello_world.elf.dir/home/user/cortex-m/SDK_2_9_0_MIMX8QX5xxxFZ/devices/MIMX8QX6/drivers/fsl_clock.c.obj
[ 40%] Building C object CMakeFiles/hello_world.elf.dir/home/user/cortex-m/SDK_2_9_0_MIMX8QX5xxxFZ/devices/MIMX8QX6/scfw_api/main/ipc_imx8qx.c.obj
[ 44%] Building C object CMakeFiles/hello_world.elf.dir/home/user/cortex-m/SDK_2_9_0_MIMX8QX5xxxFZ/devices/MIMX8QX6/scfw_api/svc/pad/pad_rpc_clnt.c.obj
[ 48%] Building C object CMakeFiles/hello_world.elf.dir/home/user/cortex-m/SDK_2_9_0_MIMX8QX5xxxFZ/devices/MIMX8QX6/scfw_api/svc/misc/misc_rpc_clnt.c.obj
[ 60%] Building C object CMakeFiles/hello_world.elf.dir/home/user/cortex-m/SDK_2_9_0_MIMX8QX5xxxFZ/devices/MIMX8QX6/scfw_api/svc/timer/timer_rpc_clnt.c.obj
[ 60%] Building C object CMakeFiles/hello_world.elf.dir/home/user/cortex-m/SDK_2_9_0_MIMX8QX5xxxFZ/devices/MIMX8QX6/scfw_api/svc/pm/pm_rpc_clnt.c.obj
[ 60%] Building C object CMakeFiles/hello_world.elf.dir/home/user/cortex-m/SDK_2_9_0_MIMX8QX5xxxFZ/devices/MIMX8QX6/scfw_api/svc/rm/rm_rpc_clnt.c.obj
[ 64%] Building C object CMakeFiles/hello_world.elf.dir/home/user/cortex-m/SDK_2_9_0_MIMX8QX5xxxFZ/devices/MIMX8QX6/scfw_api/svc/seco/seco_rpc_clnt.c.obj
[ 68%] Building C object CMakeFiles/hello_world.elf.dir/home/user/cortex-m/SDK_2_9_0_MIMX8QX5xxxFZ/devices/MIMX8QX6/scfw_api/svc/irq/irq_rpc_clnt.c.obj
[ 72%] Building C object CMakeFiles/hello_world.elf.dir/home/user/cortex-m/SDK_2_9_0_MIMX8QX5xxxFZ/devices/MIMX8QX6/drivers/fsl_lpuart.c.obj
[ 76%] Building C object CMakeFiles/hello_world.elf.dir/home/user/cortex-m/SDK_2_9_0_MIMX8QX5xxxFZ/devices/MIMX8QX6/utilities/debug_console_lite/fsl_assert.c.obj
[ 80%] Building C object CMakeFiles/hello_world.elf.dir/home/user/cortex-m/SDK_2_9_0_MIMX8QX5xxxFZ/components/lists/fsl_component_generic_list.c.obj
[ 84%] Building ASM object CMakeFiles/hello_world.elf.dir/home/user/cortex-m/SDK_2_9_0_MIMX8QX5xxxFZ/devices/MIMX8QX6/gcc/startup_MIMX8QX6_cm4.S.obj
[ 88%] Building C object CMakeFiles/hello_world.elf.dir/home/user/cortex-m/SDK_2_9_0_MIMX8QX5xxxFZ/devices/MIMX8QX6/system_MIMX8QX6_cm4.c.obj
[ 92%] Building C object CMakeFiles/hello_world.elf.dir/home/user/cortex-m/SDK_2_9_0_MIMX8QX5xxxFZ/devices/MIMX8QX6/drivers/fsl_gpio.c.obj
[ 96%] Building C object CMakeFiles/hello_world.elf.dir/home/user/cortex-m/SDK_2_9_0_MIMX8QX5xxxFZ/devices/MIMX8QX6/utilities/fsl_sbrk.c.obj
[100%] Linking C executable debug/hello_world.elf
Now you completed your first build of a hello-world program for the Cortex-M. Follow the next guides to check what modifications are needed to run the examples based on each module.