Transclusion: CL-SOM-iMX7: FreeRTOS: Demos Usage Guide

From Compulab Mediawiki
Revision as of 14:50, 22 March 2018 by Nikita (talk | contribs) (Example run)
Jump to: navigation, search

Introduction and Preparations

This article provides a usage guide for the various FreeRTOS demo images that come with the CL-SOM-iMX7 BSP.
To run a demo:

Serial connections

The FreeRTOS demos for CL-SOM-iMX7 were setup so that the M4 serial connection is set to the P4-31 (RX) and P4-33 (TX) pins on the carrier baseboard, using UART2. The A7 core serial port is using UART1, and is located on the P8 connector of the carrier baseboard. For more information about the A7 serial port, please see the HOWTO: RS-232 Console article.

To communicate with both the M4 and A7 cores using the serial interface, start a terminal emulation program (such as HyperTerminal) for each serial port, with the following port settings:

Baud Rate Data Bits Stop Bits Parity Flow Control
115200 8 1 none none

SD-card media

In this article, all the demos are loaded using U-Boot from a filesystem formatted SD-card. The SD card must be FAT or EXT filesystems formatted. For other methods of loading the demo images, see the See also section.

Linux installation

Some of the demos require a Linux installation. In order to boot Linux alongside FreeRTOS, a special device tree blob must be used to prevent Linux and FreeRTOS from interfering with one another.

  • Follow the automatic installation procedure in the see also section.
  • Copy the precompiled imx7d-sbc-imx7-m4.dtb device tree blob to the SD-card (or use your own modified dtb).
  • Run the following commands to make sure that U-Boot boot command will load the special device tree blob:
CL-SOM-iMX7 # setenv fdtaddr 0x83000000
CL-SOM-iMX7 # setenv fdtfile imx7d-sbc-imx7-m4.dtb
CL-SOM-iMX7 # setenv loadfdt 'mmc rescan; load mmc 0 ${fdtaddr} ${fdtfile}'
CL-SOM-iMX7 # saveenv

Demos usage examples

Blinking LED with GPT demo

The blinking GPT demo utilizes GPT to blink the CL-SOM-iMX7 LED at variable intervals. The length of the interval can be changed by sending anykey presses into the M4 console.

Example run

Running the demo via U-Boot:

CL-SOM-iMX7 # mmc rescan && load mmc 0 7F8000 blinking_imx_demo_gpt.bin && dcache flush; bootaux 7F8000

M4 serial output (key presses not echoed back):

================= Blinking Demo ==================

====== Blinking interval 100ms ======

====== Press any key to change blinking interval ======

Wait 5 seconds to switch blinking frequency:

====== Blinking interval 200ms ======

====== Press any key to change blinking interval ======

Wait 5 seconds to switch blinking frequency:

====== Blinking interval 300ms ======

====== Press any key to change blinking interval ======

Wait 5 seconds to switch blinking frequency:

====== Blinking interval 400ms ======

====== Press any key to change blinking interval ======

Wait 5 seconds to switch blinking frequency:

====== Blinking interval 500ms ======

====== Press any key to change blinking interval ======

Wait 5 seconds to switch blinking frequency:

Hello World demo

The various hello world demos simply output "Hello World!" on the M4 console, and echo any keypresses made by the user.

Example run

Running the demo via U-Boot:

  • To run the hello_world application in TCM memory:
CL-SOM-iMX7 # mmc rescan && load mmc 0 7F8000 hello_world.bin && dcache flush; bootaux 7F8000
  • To run the hello_world application in DDR memory:
CL-SOM-iMX7 # mmc rescan && load mmc 0 9FF00000 hello_world_ddr.bin && dcache flush; bootaux 9FF00000
  • To run the hello_world application in OCRAM memory:
CL-SOM-iMX7 # mmc rescan && load mmc 0 910000 hello_world_ocram.bin && dcache flush; bootaux 910000

The M4 serial output:

Hello World!

These words were typed by the user and echoed back!

Rand WFI demo

In this demo a GPT will change the M4 Power Mode with random period. The power mode changes do not happen until Linux boot is initiated.

Example run

Run the demo via U-Boot, and then boot linux:

CL-SOM-iMX7 # mmc rescan && load mmc 0 7F8000 rand_wfi_imx7d.bin && dcache flush; bootaux 7F8000
...
CL-SOM-iMX7 # boot

M4 serial output:

 ************************************************************************
 *          i.MX 7Dual Dual Core Low Power Demo - M4 side               *
 *                                                                      *
 *        A GPT will change the M4 Power Mode with random period        *
 *                                                                      *
 ************************************************************************

Low Power Demo
********************************
Please wait :
    1) A7 peer is ready
Then press "S" to start the demo
********************************

Press "S" to start the demo : s
GPT will triggle interrupt in 18s
go to mode WAIT
GPT Event! Total time 18s
GPT will triggle interrupt in 18s
go to mode STOP
GPT Event! Total time 36s
GPT will triggle interrupt in 17s
go to mode RUN
GPT Event! Total time 53s
GPT will triggle interrupt in 19s
go to mode WAIT
GPT Event! Total time 72s
GPT will triggle interrupt in 15s
go to mode STOP
GPT Event! Total time 87s
GPT will triggle interrupt in 18s
go to mode RUN
GPT Event! Total time 105s
GPT will triggle interrupt in 17s
go to mode WAIT
GPT Event! Total time 122s
GPT will triggle interrupt in 16s
go to mode STOP
GPT Event! Total time 138s
GPT will triggle interrupt in 16s
go to mode RUN

SEMA4 demo

This demo demonstrates locking and unlocking of the SEMA4 lock. The user can initiate locking manually or set M4 to lock the SEMA4 every 5 seconds.

Example run

Running the demo via U-Boot:

CL-SOM-iMX7 # mmc rescan && load mmc 0 7F8000 sema4_demo.bin && dcache flush; bootaux 7F8000

M4 serial output:

================== SEMA4 demo ==================
Enter command:
----- 'm' to manually trigger a SEMA4 lock
----- 'a' to automatically trigger SEMA4 lock every 5 seconds
m
...SEMA4 mutex lock successfully!
Enter command:
----- 'm' to manually trigger a SEMA4 lock
----- 'a' to automatically trigger SEMA4 lock every 5 seconds
m
...SEMA4 mutex lock successfully!
Enter command:
----- 'm' to manually trigger a SEMA4 lock
----- 'a' to automatically trigger SEMA4 lock every 5 seconds
a
...SEMA4 mutex lock successfully!
Wait for 5 seconds......

...SEMA4 mutex lock successfully!
Wait for 5 seconds......

...SEMA4 mutex lock successfully!
Wait for 5 seconds......

RPMSG ping-pong demo

This demo demonstrates synchronization between the A7 and M4 cores by printing a series of messages, with an incrementing index, such that even messages are printed on one core, and odd messages on another core. This demo requires booting into Linux and loading a special driver. It is available in two configurations: the "bare metal" (bm) configuration, which implements the demo functionality without FreeRTOS kernel code, and the freertos version, which does use freertos kernel code.

Example run

Run the demo via U-Boot:

  • To run the bare metal version:
CL-SOM-iMX7 # mmc rescan && load mmc 0 7F8000 rpmsg_pingpong_bm_example.bin && dcache flush; bootaux 7F8000
  • To run the freertos kernel version:
CL-SOM-iMX7 # mmc rescan && load mmc 0 7F8000 rpmsg_pingpong_freertos_example.bin && dcache flush; bootaux 7F8000

...and then boot into Linux:

CL-SOM-iMX7 # boot

While Linux boots, the below messages can be seen on the M4 core terminal:

RPMSG PingPong Bare Metal Demo...
RPMSG Init as Remote

After Linux finished booting, run the ping pong rpmsg driver.

root@cl-debian:~# modprobe imx_rpmsg_pingpong

With both A7 and M4 terminals side by side, the following output can be observed (A7 to the left, M4 to the right):

                                        Name service handshake is done, M4 has setup a rpmsg channel [0 ---> 1024]
get 1 (src: 0x0)                        Get Data From Master Side : 0
get 3 (src: 0x0)                        Get Data From Master Side : 2
get 5 (src: 0x0)                        Get Data From Master Side : 4
get 7 (src: 0x0)                        Get Data From Master Side : 6
get 9 (src: 0x0)                        Get Data From Master Side : 8
get 11 (src: 0x0)                       Get Data From Master Side : 10
...                                     ...

Serial communication demo

This demo sets up a communication channel between the A7 and M4 cores, allowing the user to type characters from the A7 core, and make them appear on M4 core. This demo requires booting into Linux and loading a special driver, and configure the serial tty connection between the cores. It is available in two configurations: the "bare metal" (bm) configuration, which implements the demo functionality without FreeRTOS kernel code, and the freertos version, which does use freertos kernel code.

Example run

Run the demo via U-Boot:

  • To run the bare metal version:
CL-SOM-iMX7 # mmc rescan && load mmc 0 7F8000 rpmsg_str_echo_bm_example.bin && dcache flush; bootaux 7F8000
  • To run the freertos kernel version:
CL-SOM-iMX7 # mmc rescan && load mmc 0 7F8000 rpmsg_str_echo_freertos_example.bin && dcache flush; bootaux 7F8000

...and then boot into Linux:

CL-SOM-iMX7 # boot

While Linux boots, the following will appear on the M4 core terminal:

RPMSG String Echo Bare Metal Demo...
RPMSG Init as Remote

After booting into Linux, load the imx_rpmsg_tty driver:

root@cl-debian:~# modprobe imx_rpmsg_tty
imx_rpmsg_tty rpmsg0: new channel: 0x400 -> 0x0!
Install rpmsg tty driver!

On M4 serial terminal the following output is observed:

Name service handshake is done, M4 has setup a rpmsg channel [0 ---> 1024]

A /dev/ttyRPMSG device file will appear in Linux. Configure it for serial communication using stty:

root@cl-debian:/# stty -F /dev/ttyRPMSG

Send a message from Linux to M4 core:

root@cl-debian:/# echo hello > /dev/ttyRPMSG

On M4 serial terminal the following output is observed:

Get Message From Master Side : "hello" [len : 5]
Get New Line From Master Side

ADC driver demo

The demo demonstrates the usage of the ADC driver.

Example run

Run the demo via U-Boot:

CL-SOM-iMX7 # mmc rescan && load mmc 0 7F8000 adc_imx7d_example.bin && dcache flush; bootaux 7F8000

M4 serial output:

-------------- ADC imx7d driver example --------------

This example demonstrates usage of ADC driver on i.MX processor.
It Continuous convert Analog Input, and print the result to terminal 
Current analog value: 1.33v
Current analog value: 1.32v
Current analog value: 1.31v
Current analog value: 1.29v
Current analog value: 1.31v
Current analog value: 1.31v
Current analog value: 1.32v
Current analog value: 1.31v
Current analog value: 1.32v
Current analog value: 1.30v
Current analog value: 1.32v
Current analog value: 1.32v
Current analog value: 1.30v
Current analog value: 1.31v
Current analog value: 1.31v
Current analog value: 1.31v
Current analog value: 1.30v

Flexcan loopback demo

This demo demonstrates the usage of the Flexcan driver, when the CAN bus is set to loopback mode.

Example run

Run the demo via U-Boot:

CL-SOM-iMX7 # mmc rescan && load mmc 0 7F8000 flexcan_loopback_example.bin && dcache flush; bootaux 7F8000

M4 serial output:

********* FLEXCAN LOOPBACK TEST *********
   Message format: Standard (11 bit id)
   Message buffer 9 used for Rx.
   Message buffer 13 used for Tx.
   Interrupt Mode: Enabled
   Operating Mode: TX and RX --> LoopBack
*****************************************


DLC=1, mb_idx=0x123
RX MB data: 0x0 

DLC=1, mb_idx=0x123
RX MB data: 0x1 

DLC=1, mb_idx=0x123
RX MB data: 0x2 

DLC=1, mb_idx=0x123
RX MB data: 0x3 

DLC=1, mb_idx=0x123
RX MB data: 0x4 

DLC=1, mb_idx=0x123
RX MB data: 0x5 

DLC=1, mb_idx=0x123
RX MB data: 0x6 

DLC=1, mb_idx=0x123
RX MB data: 0x7 

DLC=1, mb_idx=0x123
RX MB data: 0x8 

DLC=1, mb_idx=0x123
RX MB data: 0x9 

DLC=1, mb_idx=0x123
RX MB data: 0xa 

Flexcan network demo

This demo demonstrates the usage of the Flexcan driver. It is designed to be paired with another M4 core, running a modified version of this demo.

Preparation

  • Prepare 2 versions of the flexcan_network_example demo image, one configured for NODE1, and another configured for NODE2. Both variations can be found in the images folder.
  • Obtain another CL-SOM-iMX7 eval board and connect the two boards to the CAN Bus.

Example run

Run the demo via U-Boot on both devices:

CL-SOM-iMX7 # mmc rescan && load mmc 0 7F8000 flexcan_network_example_nodeX.bin && dcache flush; bootaux 7F8000

After boot succeeds, the serial output of M4 will display the following:

********* FLEXCAN NETWORK TEST *********
   Message format: Standard (11 bit id)
   Message buffer 9 used for Rx.
   Message buffer 8 used for Tx.
   Interrupt Mode: Enabled
   Operating Mode: TX and RX --> Normal
****************************************


NODE is 1

After both modules loaded and booted the demo image, CAN bus communication between the boards will commence.

DLC=1, mb_idx=0x123
RX MB data: 0x0
DLC=1, mb_idx=0x123
RX MB data: 0x1
DLC=1, mb_idx=0x123
RX MB data: 0x2
DLC=1, mb_idx=0x123
RX MB data: 0x3
DLC=1, mb_idx=0x123
RX MB data: 0x4
DLC=1, mb_idx=0x123
RX MB data: 0x5

GPIO driver demo

This demo demonstrates the usage of the GPIO driver. It is setup to toggle a GPIO on and off using key presses into the M4 serial connection. On CL-SOM-iMX7 the GPIO controls the CL-SOM-iMX7 LED.

Example run

Run the demo via U-Boot:

CL-SOM-iMX7 # mmc rescan && load mmc 0 7F8000 gpio_imx_example.bin && dcache flush; bootaux 7F8000

M4 serial output (key presses are not echoed back):

====================== GPIO Example ========================

============ Use key to simulate GPIO button ==============
Input any data from terminal 3 times to continues.

Button pressed 1 time. 
Button pressed 2 time. 
Button pressed 3 time. 

================= GPIO Functionality==================
The button state is now polled.
Press the button to switch LED on or off

At this point sending keypresses into the M4 terminal toggles the CL-SOM-iMX7 LED on and off.

GPT driver demo

This demo demonstrates the usage of the GPT driver.

Example run

Run the demo via U-Boot:

CL-SOM-iMX7 # mmc rescan && load mmc 0 7F8000 gpt_example.bin && dcache flush; bootaux 7F8000

M4 serial output:

GPT timer will now start
counter/freq ratio should be close to 0.0 or 1.0 ...
	GPT A freq 6000000, counter 6.
	GPT B freq 49090907, counter 18.
	GPT A freq 6000000, counter 2.
	GPT B freq 49090907, counter 52.
	GPT A freq 6000000, counter 1.
	GPT B freq 49090907, counter 52.
	GPT A freq 6000000, counter 0.
	GPT B freq 49090907, counter 53.
	GPT A freq 6000000, counter 6000000.
	GPT B freq 49090907, counter 53.
GPT example finished...

UART driver demo

This demo demonstrates the usage of the UART driver in both interrupt and polling modes of operation.

Example run

Run the demo via U-Boot:

  • To run the interrupt driven version:
CL-SOM-iMX7 # mmc rescan && load mmc 0 7F8000 uart_imx_interrupt_example.bin && dcache flush; bootaux 7F8000
  • To run the polling version:
CL-SOM-iMX7 # mmc rescan && load mmc 0 7F8000 uart_imx_polling_example.bin && dcache flush; bootaux 7F8000

M4 serial output for interrupt driven example:

++++++++++++++++ UART Send/Receive Interrupt Driven Example +++++++++++++++++

Type characters from keyboard, the board will receive and then echo them to terminal screen
This was typed by the user!

M4 serial output for polling driven example:

++++++++++++++++ UART Send/Receive Polling Example +++++++++++++++++

Type characters from keyboard, the board will receive and then echo them to terminal screen
This was typed by the user!

Watchdog driver demo

This demo demonstrates the usage of the Watchdog driver.

Example run

Run the demo via U-Boot:

CL-SOM-iMX7 # mmc rescan && load mmc 0 7F8000 wdog_imx_example.bin && dcache flush; bootaux 7F8000

M4 serial output:

WDOG with timeout 1.5 seconds will now start
WDOG was refreshed 4
WDOG was refreshed 3
WDOG was refreshed 2
WDOG was refreshed 1
WDOG was refreshed 0
Counter down to 0, WDOG is starved now...
WDOG with timeout 1.5 seconds will now start
WDOG was refreshed 4
WDOG was refreshed 3
WDOG was refreshed 2
WDOG was refreshed 1
WDOG was refreshed 0
Counter down to 0, WDOG is starved now...