Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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

Table of Contents
stylenone

...

  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.

...

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:

...

Code Block
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.

...

in default configuration file.

Device-tree

...

Nodes for

...

Remoteproc Driver

Code Block
	remoteproc0: remoteproc@f800817c {
		compatible = "sunplus,sp-rproc";
		firmware = "firmware";
		reg = <0 0xf800817c 0 4>, /* mbox G258.31, cpu0 to cpu2 direct reg07 */
		      <0 0xf8800250 0 4>,
		      <0 0xf80081fc 0 4>; /* mbox G259.31, cpu2 to cpu0 direct reg07 */
		interrupt-parent = <&gic>;
		interrupts = <GIC_SPI 125 IRQ_TYPE_LEVEL_HIGH>; /* CPU2_TO_0_DIRECT_INT7 */
		resets = <&rstc RST_CM4>;
		memory-region = <&rproc_0_reserved>, <&rproc0runaddr>,<&vdev0buffer>, <&vdev0vring0>, <&vdev0vring1>;
	};

...

Code Block
	vdev0buffer: vdev0buffer@5be00000 {
		compatible = "shared-dma-pool";
		reg = <0x0 0x5be00000 0x0 0x100000>;
		no-map;
	};
	vdev0vring0: vdev0vring0@5bf00000 {
		compatible = "shared-dma-pool";
		reg = <0x0 0x5bf00000 0x0 0x10000>;
		no-map;
	};
	vdev0vring1: vdev0vring1@5bf10000 {
		compatible = "shared-dma-pool";
		reg = <0x0 0x5bf10000 0x0 0x10000>;
		no-map;
	};

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.

...

  • 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.

...

  • 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:

...

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.

Code Block
CM4  build @ Mar  7 2024 02:01:06
Successfully intialize remoteproc.
Initialize remoteproc successfully.
creating remoteproc virtio: 0x5be00000
initializing rpmsg vdev in mode 1
initializing rpmsg vdev done
CreateTask-viorw-result:1
CreateTask-wakeupkey-result:1
CreateTask-powerdown-result:1
CreateTask-powerup-result:1
CreateTask-IDLE-result:1
CreateTask-Tmr Svc-result:1
power down wait Semaphore !