How to Use MCUXpresso SDK to Develop iMX8MQ?
Forlinx iMX8MQ platform has a Cortex M4 core, supporting using the MCUXpresso SDK to develop.
MCUXpresso SDK is a collection of microcontroller software support that includes peripheral drivers, RPMSG multicore communications, and FreeRTOS support. You can view the SDK API documentation to learn about the functions and structures it implements.
Using the following toolchain:OKMX8MQ platform can be developed with SDK
Linux Environment: Makefiles support with GCC revision v7-2017-q4-major from Arm Embedded
Windows Environment: IAR Embedded Workbench for ARM version 8.30.2
1, Use ARM GCC tools to compile applications
In a Linux environment, the MCUXpresso SDK compiles using GCC tools, and the process is illustrated by hello_world demo.
First of all, you need to build a Linux compilation environment:
a, Install cmake
$ sudo apt-get install cmake
$ cmake --version
The version of cmake is larger than 3.0.x. If your version is less than 3.0, you can update it by following these steps.
$ cd /tmp
$ wget https://cmake.org/files/v3.11/cmake-3.11.0-rc4-Linux-x86_64.tar.gz
$ tar zxvf cmake-3.11.0-rc4-Linux-x86_64.tar.gz
$ sudo mv cmake-3.11.0-rc4-Linux-x86_64 /opt/cmake-3.11
$ sudo ln -sf /opt/cmake-3.11/bin/* /usr/bin/
$ cmake --version
b, Install the GCC compiler
Copy the gcc-arm-none-eabi-7-2017-major-linux .tar.bz2 of the user profile tool catalog to the virtual machine/tmp directory.
$ cd /tmp
$ sudo tar xvf gcc-arm-none-eabi-7-2017-q4-major-linux.tar.bz2 -C /opt
c, Set the environment variables
$ export ARMGCC_DIR=/opt/gcc-arm-none-eabi-7-2017-q4-major
$ export PATH=/opt/gcc-arm-none-eabi-7-2017-q4-major/bin:$PATH
When the setup is complete, you can see if the setting is successful:
$ echo $ARMGCC_DIR
$ echo $PATH
d, Compilation
Copy the SDK_2.8.0_EVK-MIMX8MQ .zip from the user profile to the virtual machine /home/forlinx/ imx8mq directory:
$ cd /home/forlinx/imx8mq
$ mkdir SDK_2.8.0_EVK-MIMX8MQ
$ mv SDK_2.8.0_EVK-MIMX8MQ.zip SDK_2.8.0_EVK-MIMX8MQ
$ cd SDK_2.8.0_EVK-MIMX8MQ
$ unzip SDK_2.8.0_EVK-MIMX8MQ.zip
$ cd boards/evkmimx8mq/demo_apps/hello_world/armgcc
$ ./build_debug.sh
The compiled hello_world.bin file is in the ./debug directory.
Note: Other versions, such as build_ddr_debug.sh, can also be compiled here, except that they will make a difference when running.
2, Compile and debug using IAR and J link
Refer to the official manual "SDK_2.8.0_EVK-MIMX8MQdocs/getting started with MCUXpresso SDK for EVK-MIMX8MQ".
A, IAR and Jlink official tool version requirements
IAR please use IAR embedded Workbench 8.30.2 or later, jlink official tool version please use the version containing MIM8M6_M4 device, we use the version is JLink_Windows_V654c. IAR embedded Workbench is a paid software that users are asked to purchase their own installation. Jlink official tool users can download it on jlink's official website.
There is also a need for SDK_2.8.0_EVK-MIMX8MQ provided by NXP, which is already available in the user profile.
B, IAR through Jlink to run the test program
Step one, open the project
a.Open IAR
b.Select Open Workspace under the File menu and select SDK_2.8.0_EVK-MIMX8MQ/boards/evkmimx8mq/demo_apps/hello_world/iar/hello_world.eww.
c.Select the debug option
Step two, configuration engineering
Press the ALT-F7 shortcut to open the configuration interface.
a.Set the General Options option configuration:
b.Set the linker option configuration:
Click on "Edit..."
Select MIMX8MQ6xxxJZ_cm4_ddr_ram.icf, MIMX8MQ6xxxJZ_cm4_ram.icf, and the resulting images will run in different stores (ddr, ram).
c. Set the Debugger option configuration:
d.Set up the J-Link/J-Trace option configuration
Click OK when the configuration is complete.
Step three, compile and run the project
Note: Debug M4 program, iMX8MQ board can not start to the Linux kernel stage, need to stop at uboot (start, press the space bar at the debug serial).
a. Click on "Make" to compile the project, the project is completed without errors:
b. Click the "Download and Debug" button:
c. Prompt to set up J-Link to select a device:
d. Select the "MIMX8MQ6_M4" device:
e.Run the test program:
3, use U -boot to run the application
You can go to the u-boot command line when the iMX8MQ board starts, load the bin file into M4 and run it with the u-boot command, and use the hello_world.bin program as an example to illustrate the running process.
Note: The M4 program may have a resource conflict with A53, and if an interface is already in use in M4, do not call it again in A53. The M4 program runs in the DDR and requires this memory to be reserved in Linux. Configured in the system-burned device tree ok8mq-evk-rpmsg.dtb. We are testing the M4 program using this device tree.
Enter the following commands on the uboot command line to modify the device tree:
$ setenv fdt_file ok8mq-evk-rpmsg.dtb
$ saveenv
1, ready to test the M4 program
The methods in the first or second are used to generate hello_world.bin running on DDR and ram, and name them hello_world_ddr.bin and hello_world_ram.bin, respectively.
2, serial connection
Because uart2 is used in hello_world program, connect the serial port from uart2 to PC before you begin testing. And use the serial debugging tool to open the corresponding COM port, Baud rate and other parameters set the same as OKMX8MQ Debug port parameters.
3, will compile the hello_world_ddr.bin and hello_world_ram.bin copy to the U disk (Fat32) under the root directory, the USB stick plug into the board, restart the iMX8MQ board, stop at the u-boot command line.
4, execute the following command on the u-boot command line
For the debug/release version of the bin file, it runs on TCM and executes the following commands:
$ usb start
$ fatload usb 0:1 0x48000000 hello_world_ram.bin
$ cp.b 0x48000000 0x7e0000 0x20000
$ bootaux 0x7e0000
Execution of the terminal:
The print information can be seen on the uart2 debug serial tool as follows:
For ddr_debug/ddr_release version of the bin file, which runs on DDR4, perform the following commands:
$setenv fdt_file ok8mq-evk-rpmsg.dtb
$ saveenv
$ usb start
$ fatload usb 0:1 0x80000000 hello_world_ddr.bin
$ dcache flush
$ bootaux 0x80000000
Execution of the terminal:
The print information can be seen on the uart2 debug serial tool as follows:
4, Uboot automatically start M4 program
When making a system image, files under the images/m4/folder in the source package are written to the boot.img image, which is part of rootfs.sdcard. After we burned the image to emmc, the mirror of these m4 programs is in the fat32 partition of emmc. The Uboot startup process runs m4_run, setting the m4_run to start the m4 program, and the uboot starts the M4 program.
With hello_world example of a routine, uboot automatically starts the M4 program when you set the ubot environment variable as follows.
hello_world the mirror of the program, we have added the images/m4/folder to the source code by default, so our mirror contains the mirror of the hello_world under the m4 folder within the partition 1 of emmc, hello_world_ram.bin and hello_world_ddr.bin.
Start the M4 program in ram.
$ setenv m4_run 'mmc dev 0; fatload mmc 0:1 0x48000000 m4/hello_world_ram.bin; cp.b 0x48000000 0x7e0000 0x20000; bootaux 0x7e0000 '
$ saveenv
Start the M4 program at ddr.
$ setenv m4_run 'mmc dev 0; fatload mmc 0:1 0x80000000 m4/hello_world_ddr.bin; dcache flush; bootaux 0x80000000'
$ saveenv
Note 1: The user adds their own compiled image to the image/m4/folder, edits the generated image, burns it will be in the fat sub-region of emmc, start the time according to the compiled m4_run settings for the ddr or ram version, and replace the m4 mirror name with the name of the m4 mirror compiled by itself in the m4_run command.
Note 2: You can view the mirrors contained in the fat zone after the system starts, or you can add the images with the cp command.
View the image:
$ ls /run/media/mmcblk0p1/m4
Copy mirror to folder:
$ cp /run/media/sda1/m4_flash.bin /run/media/mmcblk0p1/m4/
5. Heterogeneous multicore communication test
Use Remote Processor Messaging to enable Cortex A53 to communicate with Cortex M4.
RPMsg is a virtio-based messaging bus that allows the kernel driver to communicate with a remote processor available on the system, such as Cortex M4. The following image is a multi-core communications architecture:
The MCUXpresso SDK of the Flygt iMX8MQ has a demo: rpmsg_lite_pingpong_rtos that enables data transceivers between Cortex A53 and Cortex M4, which use shared memory and run a FreeRTOS Task on Cortex M4.
This is done on the Cortex A53 side via a kernel module at the drivers/rpmsg/imx_rpmsg_pingpong.c.,
The following is an example compiled in arm GCC mode.
Go to the following directory:
$ cd boards/evkmimx8mq/multicore_examples/rpmsg_lite_pingpong_rtos/linux_remote/armgcc
Compile the debug version of the bin file:
$ ./build_debug.sh
$ cd debug
$ ls -l
Copy the compiled bin file rpmsg_lite_pingpong_rtos_linux_remote.bin under the root of the USB stick (Fat32), and the startup board stops at the u-boot command line.
$ setenv fdt_file ok8mq-evk-rpmsg.dtb
$ saveenv
$ usb start
$ fatload usb 0:1 0x48000000 rpmsg_lite_pingpong_rtos_linux_remote.bin
$ cp.b 0x48000000 0x7e0000 0x20000
$ bootaux 0x7e0000
After running the bin file, you can see the following output at the serial terminal of uart2:
The A53 U-boot command line then enters boot start-up kernel, where you can see the following output at the Cortex M4 serial terminal:
The following kernel modules are then loaded at the Cortex A53 serial terminal:
$ modprobe imx_rpmsg_pingpong
Once the module is loaded, the Cortex A53 begins data transfer with Cortex M4, where the following outputs can be seen at the Cortex M4 serial terminal:
The following outputs can be seen at the Cortex A53 serial terminal:
6, FreeRTOS application testing
Forlinx iMX8MQ board has a Cortex M4 core inside that allows you to run the FreeRTOS application on it.
Let's test FreeRTOS with freertos_swtimer demo as an example.
Go to the catalog:
$ cd boards/evkmimx8mq/rtos_examples/freertos_swtimer/armgcc
Compile the debug version of the bin file:
$ ./build_debug.sh
$ cd debug
$ ls -l
Copy the compiled bin file freertos_swtimer.bin below the root of the USB stick (FAT32). Plug the USB Host connector into the board and the startup board stops at the u-boot command line.
$ setenv fdt_file ok8mq-evk-rpmsg.dtb
$ saveenv
$ usb start
$ fatload usb 0:1 0x48000000 freertos_swtimer.bin
$ cp.b 0x48000000 0x7e0000 0x20000
$ fbootaux 0x7e0000
The following outputs can be seen at the Cortex M4 serial terminal:
You can see that the terminal periodically prints out the Tick character, indicating that the timer task in the FreeRTOS application is running.