FreeRTOS (10.4.3)

FreeRTOS, short for Free Real-Time Operating System, is an open-source, real-time operating system kernel designed for embedded systems. Developed by Real Time Engineers Ltd., FreeRTOS is known for its simplicity and flexibility, making it a popular choice for a wide range of microcontroller-based applications.

For further information, refer to official web site: FreeRTOS - Real-time operating system for microcontrollers

CM4 startup is controlled by the kernel through the use of remoteproc driver. CM4 software implements control of each power domain when the system is suspended or resume. It also includes polling wake-up key to enter or exit deep-sleep mode, power down or up main-domain, CA55, NPU, video codec powers, and data communication between CA55 and CM4 via virtIO as well.

Table of Contents

Features

  1. Output log at UART6 (set at 115,200 bps by x-boot).

  2. Support SP7350 power manager

    • Detect wake-up key

    • Power down and up control for main-domain, CA55, NPU, video codec

    • Support DDR retention

    • Support PMIC control

  3. Support communication with CA55 via virtual l/O serial port

  4. Support CmBacktrace to tracks and debug ARM Cortex-M4

  5. Support Arduino hardware interface, such as SPI, I2C, UART, timer, GPIO.

  6. Support CUnit test of SPI, I2C, UART, timer, GPIO driver

Default Tasks

By default, FreeRTOS of SP7350 platform is configured to run 6 tasks. In table below, we outline each task along with its location of source files and functionality.

Tasks

Files (under FreeRTOS project directory)

Descriptions

powerdown

application/power_manager/power_down.c

power-down control

powerup

application/power_manager/power_up.c

power-up control

wakeupkey

application/power_manager/wakeup_key.c

Detect wake-up key

virtIOrw

application/VirtIOSerial/vios_rw.cpp

virtual IO read/write

tmr Svc

system/freertos/timers.c

FreeRTOS system Timer task

Idle

system/freertos/tasks.c

FreeRTOS system Idle task

The source files of FreeRTOS are located within the "firmware/arduino_core_sunplus/" directory under the project's top directory.

Linux Remote Processor Framework

The Linux Remote Processor Framework is a framework that allows for managing (power on, load firmware, power off) and communicating with remote processors on Linux systems. This framework is typically used in embedded or multiprocessor systems where one processor (usually the main processor) is responsible for managing and controlling the other remote processors. In addition, this framework also adds rpmsg, virtio devices for remote processors that supports this kind of communication. This way, platform-specific remoteproc driver only needs to provide a few low-level handlers, and then all rpmsg drivers will then just work. For example:

  1. Load firmware of CM4 via Linux shell command:

echo firmware > /sys/class/remoteproc/remoteproc/firmware

where ‘firmware’ is the firmware file (elf format) of CM4 stored at “/lib/firmware/".

  1. Start CM4 via Linux shell command:

echo start > /sys/class/remoteproc/remoteproc0/state
  1. Stop CM4 via Linux shell command:

echo stop > /sys/class/remoteproc/remoteproc0/state

Linux Remoteproc Driver

The remoteproc driver bases on Remote Processor Framework to implement firmware loading and booting, resource allocation and management, communication support, and other functions.

Enabling remoteproc driver in Linux kernel needs to enable the kernel feature:

CONFIG_REMOTEPROC=y and

CONFIG_SUNPLUS_REMOTEPROC=y

in default configuration file.

Device-tree Nodes for Remoteproc Driver

In the RemoteProc framework, vdev0vring0, vdev0vring1, and vdev0buffer are typically used in conjunction with Virtio devices for efficient data transfers between the host processor and the remote processor.

vring0 and vring1 represent the two virtual rings of a Virtio device, typically one for sending data and the other for receiving data. These two rings pass data and control information through a set of descriptors. vbuffer represents the Virtio device's buffer, which is used to store data.

The remoteproc-related dts notes are as follows:

RPMSG and Virtual IO

The RPMsg framework (Remote Processor Messaging Framework) is an implementation of remote processor messaging. It allows communication between different processors, including communication between the main processor and remote processors, and it is a VirtIO-based message bus that allows Linux kernel drivers to communicate with remote processors in the system.

Enabling RPMSG and VirtIO in kernel needs to enable the kernel feature:

CONFIG_RPMSG=y and

CONFIG_RPMSG_VIRTIO=y

in default configuration file.

  • RPMSG: After CM4 is running, a device node /dev/ttyRPMSGx is generated on the kernel side, and the kernel side communicates with CM4 via /dev/ttyRPMSGx.

  • VirtIO: Virtio is a standard for high-performance virtual appliances in virtualized environments, CM4 write/read VirtioSerial to transfer data to /dev/ttyRPMSGX

Build Image

Use “make firmware" in the root directory to compile the FreeRTOS code, The output file after compilation is put in bin/firmware. You need to copy it to linux/rootfs/initramfs/disk/lib/firmware in project directory.

This project includes several code environments, including FreeRTOS+Arduino (default), Arduino, and CUnit, and the different code environments are determined by the configuration of the Makefile.

  • FreeRTOS+Arduino: The default compiled image is based on the FreeRTOS environment, It implements power management function for suspend and resume processes.

  • Arduino: Set FREERTOS ?=0 in Makefile will compile the code environment with only Arduino, not FreeRTOS. The entry function of the program is in ‘application/arduino_main.cpp’.

  • CUnit: Set CUNIT ?=1 in Makefile. Compiled code contains only CUnit test code, including SPI, I2C, UART, timer, and GPIO test units.

Supported Drivers for SP7350 Platform

The source files of FreeRTOS are located within the "firmware/arduino_core_sunplus/" directory under the project's top directory. For the SP7350 platform, a wide array of device drivers is supported. These drivers are within the "system/drivers/sp7350_hal_driver/" directory. Below is a reference table detailing the drivers along with their corresponding feature descriptions:

Drivers

Files

Features

ADC (SAR12B)

sp7350_hal_adc.c

read analog voltage

Audio (I2S)

sp7350_hal_i2s.c

I2S read/write interface

GPIO driver

sp7350_hal_gpio.c

write/read gpio level

AHB DMA

sp7350_hal_dma.c

AHB DMA driver

I2C driver

sp7350_hal_i2c.c

I2C read/write interface

Mailbox

sp7350_hal_ipcc.c

trigger between CM4 and CA55

PWM

/sp7350_hal_pwm.c

output pwm

RTC

sp7350_hal_rtc.c

get rtc time and generate rtc irq

SPI

sp7350_hal_spi.c

SPI read/write interface

Timer

sp7350_hal_tim.c

get/set timer. generate timer irq

UART

sp7350_hal_uart.c

UART read/write interface

Watchdog

sp7350_hal_wdg.c

watchdog interface

Source Files

The source files of FreeRTOS are organized within the "firmware/arduino_core_sunplus/" directory at the project's top directory. Below is a breakdown of the main subdirectories:

Folders

Descriptions

cores/arduino

Contains the code for Arduino only

libraries/

Contains the third party source code and ‘syscall.c’

application/power_manager/

Contains power manager codes

application/VirtIOSerial/

Contains VirtIO Serial read/write codes

bin/

Output folder

system/drivers

Contains CMIS files for CM4 and SP7350 drivers

system/freertos

Contains FreeRTOS kernel files

system/Middlewares

Contains Open-amp driver (VirtIO/Remoteproc)

system/sp7350

Contains many constant definitions

variants/sp7350_evb/

Contains ldscript and config file

Example Files

CUnit is a C unit testing framework for unit testing C programs. It provides a set of libraries and macros for writing and executing test cases and reporting test results. CUnit tests include examples using the SP7350 peripheral interface driver. Includes examples for other drivers such as SPI, I2C, UART, GPIO and PWM. The path is:

/application/Cunit_test

Set CUNIT ?=1 in Makefile to build image. The code will run from Cuint_main.cpp

FreeRTOS Log and Explanation

Line 1: The banner of CM4 firmware.

Line 2-4: Initialize remoteproc.

Line 5-6: Initialize rpmsg.

Line 7-12: Create FreeRTOS tasks.