Search by Tags

Compiling examples from command line

 

Your progress

 

Overview

The Colibri iMX7 module features one or two ARM Cortex-A7 cores and one ARM Cortex-M4 core.

In this section, you will set up your board, download the FreeRTOS source code (along with drivers and examples) and run one of the sample applications on the M4 core of the Colibri iMX7 SoM.

In this module, you will:

  • Set up your board to see the M4 core output via serial interface
  • Set up the toolchain for building M4 applications
  • Clone the FreeRTOS repository from the Toradex git repository
  • Build a demo application and upload it to the M4 core

This guide is based on the FreeRTOS on the Cortex-M4 of a Colibri iMX7 Toradex Knowledge Base article

Materials required

  • Serial-to-USB converter

Step 1

Install the dependencies for the GNU Arm Embedded toolchain. You will need the libc and libncurses 32-bit binaries:

$ sudo dpkg --add-architecture i386
$ sudo apt-get update
$ sudo apt-get install libc6:i386 libncurses5:i386

You will also need GNU Make and CMake:

$ sudo apt-get install make cmake

Step 2

Install the GNU Arm Embedded toolchain.

Download the latest version of the toolchain from the Arm website here and install it manually


  • Arm toolchain download

    Arm toolchain download

Download the .tar.bz2 file, extract it and install it to ${HOME}/opt/. You will use this same toolchain on later sections with Eclipse and the GNU MCU Eclipse plugin:

$ mkdir -p ${HOME}/opt
$ cd ${HOME}/opt
$ tar xjf ~/Downloads/gcc-arm-none-eabi-7-2017-q4-major-linux.tar.bz2 
$ chmod -R -w ${HOME}/opt/gcc-arm-none-eabi-7-2017-q4-major

Test if the compiler works by executing the following command:

$ ${HOME}/opt/gcc-arm-none-eabi-7-2017-q4-major/bin/arm-none-eabi-gcc --version
arm-none-eabi-gcc (GNU Tools for Arm Embedded Processors 7-2017-q4-major) 7.2.1 20170904 (release) [ARM/embedded-7-branch revision 255204]
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Also test if the debugging server is functional, since we'll use it later:

$ ${HOME}/opt/gcc-arm-none-eabi-7-2017-q4-major/bin/arm-none-eabi-gdb --version
GNU gdb (GNU Tools for Arm Embedded Processors 7-2017-q4-major) 8.0.50.20171128-git
Copyright (C) 2017 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=x86_64-linux-gnu --target=arm-none-eabi".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".

Step 3

Export the ARMGCC_DIR environment variable on your shell:

$ export ARMGCC_DIR=${HOME}/opt/gcc-arm-none-eabi-7-2017-q4-major/

Attention: You will need to export this variable every time a new shell window is opened.

If you want to automatically export the variable when opening a new shell window, add the export command to your .bashrc file:

$ echo 'export ARMGCC_DIR=${HOME}/opt/gcc-arm-none-eabi-7-2017-q4-major/' >> ~/.bashrc

Step 4

Clone the Toradex FreeRTOS repository:

$ cd
$ git clone -b colibri-imx7-m4-freertos-v8 git://git.toradex.com/freertos-toradex.git freertos-colibri-imx7/
$ cd freertos-colibri-imx7/

The FreeRTOS directory is structured as follows:

Directory Content
doc/ NXP/Freescale's FreeRTOS BSP Documentation
examples/ Application examples
examples/imx7_colibri_m4/ Examples ported to Toradex Colibri iMX7
middleware/multicore/open-amp/ OpenAMP based RPMsg stack (remote messaging framework)
platform/ Driver library, startup code and utilities
platform/CMSIS/ Cortex Microcontroller Software Interface Standard (CMSIS) ARM Cortex®-M header files, DSP library source
platform/devices/MCIMX7D/linker/ Linker control files for each supported toolchain
platform/drivers/ Peripheral Drivers
platform/utilities/ Utilities such as debug console
rtos/FreeRTOS/ FreeRTOS Kernel folder

Step 5

Enter the examples/imx7_colibri_m4/demo_apps/hello_world directory, which has the source files for the example along with the armgcc and ds5 subdirectories. Since we are compiling manualy using the GNU ARM Embedded toolchain, enter the armgcc subdirectory and run the build_all.sh script to build the example:

$ cd examples/imx7_colibri_m4/demo_apps/hello_world/armgcc
$ ./build_all.sh
-- TOOLCHAIN_DIR: /home/toradex/opt/gcc-arm-none-eabi-7-2017-q4-major/
-- BUILD_TYPE: Debug
-- Generating done
-- Build files have been written to: /home/toradex/prjs/colibri_imx7/freertos-colibri-imx7/examples/imx7_colibri_m4/demo_apps/hello_world/armgcc/debug
[  8%] Building ASM object CMakeFiles/hello_world.dir/home/toradex/prjs/colibri_imx7/freertos-colibri-imx7/platform/devices/MCIMX7D/startup/gcc/startup_MCIMX7D_M4.S.obj
[  8%] Building C object CMakeFiles/hello_world.dir/home/toradex/prjs/colibri_imx7/freertos-colibri-imx7/rtos/FreeRTOS/Source/portable/GCC/ARM_CM4F/port.c.obj
...
[100%] Linking C executable hello_world.elf
[100%] Built target hello_world

After building, the binaries will be located within the debug/ and release/ directories.

Step 6

Copy the hello_world.elf binary located on the debug/ directory to an SD card.

$ cp debug/hello_world.elf /media/toradex/SDCARD

Insert the SD card into the SD card slot on your carrier board.

Step 7

Connect both UART_A and UART_B ports of your board to your computer. You will use UART_A to access the U-Boot console. By default, UART_B is used as a console for the M4 core.

Start two separate serial terminal emulator (such as minicom) instances with a 115200 baud rate. For example:

$ sudo minicom -D /dev/ttyUSB0 -b 115200

And in another shell window:

$ sudo minicom -D /dev/ttyUSB1 -b 115200

Step 8

Power on your board and immediately stop the booting process to access the U-Boot console by pressing any key on the UART_A terminal:

On the U-Boot console, use the following commands to load the firmware from the SD card into the memory:

Colibri iMX7 # fatload mmc 0:1 ${loadaddr} hello_world.elf
...
Colibri iMX7 # bootaux ${loadaddr}
...
## Starting auxiliary core at 0x1FFF8311 ...
Colibri iMX7 # 

If you set up TFTP according to How to setup Networking for Embedded Linux Application Development, you can also load the file via TFTP:

Colibri iMX7 # tftp ${loadaddr} hello_world.elf
...
Colibri iMX7 # bootaux ${loadaddr}
...
## Starting auxiliary core at 0x1FFF8311 ...
Colibri iMX7 # 

Immediately after running the bootaux command, you should see a "Hello World" message printed on the UART_B serial terminal.


  • Running Hello World application on the M4 core

    Running Hello World application on the M4 core

FAQ

Which UART port is used for debugging the M4 core
Can I use another UART port for debugging the M4 core