How to exchange data buffers with the coprocessor

Revision as of 11:37, 12 July 2019 by Registered User (→‎Source code)

1. Article purpose[edit source]

This article gives an example of high data rate exchange from the Cortex-M4 to the Cortex-A7, via a DMA transfer. .

2. Introduction[edit source]

TTY over RPMSG (Cortex-A7 Linux) and Virtual UART (Cortex-M4 firmware) may be used to exchange up to 7MB/s of data between Cortex-M4 and Cortex-A7.

Info white.png Information
Note:

In situation where more than 7MB/s have to be exchanged, RPMSG is not the solution; in this case transfer by DMA is a must.

DMA will decrease a lot the CPU consumption due to the copy of data.

But the solution based on DMA requires:

  • Contiguous memory allocation
  • Cortex-M4 to be aware of physical address and size of memory buffers in order to setup DMA transfers
  • To mmap buffer to let Linux user land application have access to it

A specific Linux driver has to be developed to take care of such constraints.

3. Static architecture of big data solution[edit source]

Big data solution is composed of:

  • Linux user land application
  • Linux RPMSG sdb (shared data buffer) driver
  • Linux RPMSG tty driver

Please have a look to the chapter Data flow to see the architecture view figure.

4. System use case to demonstrate[edit source]

Let's implement a logic analyser running on the STM32MP1 discovery kit. As lot of GPIO port E bits are present on Arduino connector, so we will sample the data on PE8..15.

In order to implement an intensive data treatment on Cortex-M4, Cortex-M4 firmware will be responsible to:

  • Receive messages from Linux RPMSG sdb driver, containing physical address and size of DDR buffer
    • Save DDR buffer address and size in SRAM
  • Receive a command Start/Stop sampling including sampling frequency
    • Sample the data at a sampling frequency
  • Filter input data to keep only bit 8..12
  • Compress data on bit 13..15
    • Bit 13..15 represent a repetition factor:
      • 000: repetition=0 meaning the data is present once
      • 111: repetition=7 meaning the data is present eight times
  • Transfer the packed data in DDR buffer by packet of 1024 bytes thanks to DMA
  • Inform Cortex-A7 user interface when a DDR buffer of 1 megabyte is filled, and roll to next DDR buffer

A user interface will be available in a web page, running in the Cortex-A7 Linux application.

The user interface allows to control:

  • The sampling frequency
  • The start / stop of the sampling

The user interface displays statistics, including:

  • Number of packed data received by user interface
  • Number of unpacked data decompressed by user interface
  • Number of packed data written by user interface in file system

The user interface saves packed data in a binary file.

5. Behavior[edit source]

At startup, the application has to:

  • Load Cortex-M4 firmware
  • Open rpmsg_sdb driver
  • Use IOCTL function of rpmsg_sdb driver to allocate and mmap 3 buffers of 1MB in DDR memory.
  • Open rpmsg_tty driver

On press on START button, the application sends the sampling command to Cortex-M4 firmware (including the sampling frequency), and open a "date-time.dat" binary file.

On press on STOP button, or overrun data error, or file system full error, the application sends the stop command to Cortex-M4 firmware and close the "date-time.dat" binary file.

On event "buffer full" coming from Cortex-M4 firmware, the application unpack data, write packed data in "date-time.dat" file, and update statistics information.

Cortex-A7 Linux rpmsg_sdb driver is responsible to:

  • Allocate / free buffers in contiguous memory (DDR)
  • Send physical address and size of DDR buffer to Cotex-M4 firmware over RPMSG
  • Mmap DDR buffers in order to let user land application have access to them


Rpmsg_tty driver will be used to communicate (transport commands and events) between Cortex-M4 firmware and Cortex-A7 user land application.

6. Data flow[edit source]



7. Dynamic view[edit source]

File:Howtobigdatamsc.png

8. Snapshot view of user interface[edit source]


9. Results[edit source]

In this use case Cortex-M4 CPU is able to compress data at a rate up to 64 megabits per second (8 megabytes per second), and this is the maximum we can hit.

Depending on the type of data available on GPIOE, the transfer rate between Cortex-M4 and Cortex-A7 will vary from 1 megabyte per second (repetition factor of 7) to 8 megabytes per second (repetition factor of 0).


10. Source code[edit source]

The source code of this use case is available as a Yocto layer here:

https://github.com/STMicroelectronics/meta-st-stm32mpu-app-logicanalyser.git

The firmware is included in the Yocto layer as a .elf file.

The source code of the Cortex-M4 firmware is available here:

https://github.com/STMicroelectronics/logicanalyser

11. Usage[edit source]

Please follow README.md of Yocto layer to perform installation.

The logicanalyser application is launched by pressing User2 button of the STM32MP1 Discovery board.

Use a PC or a Tablet or a MobilePhone as a host, and scan for a Wifi hotspot named STDemoNetwork.

Select it and use stm32mp1 as password.

Launch the internet navigator on the host, and enter the following URL: 192.168.72.1:8888/index.html

Select the sampling frequency and click on Start to start the use case.