How to use coprocessor service for Android

Revision as of 16:26, 22 August 2019 by Registered User (Jean Christophe Trotin moved page How to use coprocessor service to How to use coprocessor service for Android without leaving a redirect: Request to add Android name in each How To concerned)

This article explains how to use the CoproService which is a SystemService embedded in the Android framework, allowing to use a serial connection to communicate with the Arm® Cortex®-M processor embedded in a compatible hardware board.

See STM32MPU Embedded Software for Android architecture overview to get more information on compatible hardware boards.

1. Prerequisites[edit source]

The environment must be installed using the Developer Package adapted to your selected microprocessor device. See the list of Android Developer Package.

The firmware built for the Arm® Cortex®-M processor has to use RemoteProc and RPMSG, and has to instantiate a /dev/ttyRPMSG unit during its initialization.

2. CoproService[edit source]

CoproService overview.png

CoproService is composed of two parts: Firmware management and TTY management.

2.1. Firmware management[edit source]

The Arm® Cortex®-M processor can be used to offload real time algorithms (such as MotorControl), support connectivity mediums (like LORA), etc.

Users will develop their Firmwares thanks to the CubeMX and SW4STM32 tools.

The Firmware will be embedded in the Android vendor partition in the /vendor/firmware/copro/ directory.

The CoproService will look at the contents of /vendor/firmware/copro/ to get the list of available firmwares. It will then load the requested firmware at the user's/application's request.

2.2. TTY management[edit source]

When the firmware is loaded and running, a /dev/ttyRPMSG0 driver is available to communicate with the Arm® Cortex®-M processor.

It is up to users to define and write their own protocol on top of ttyRPMSG0.

Application will then be able to:

  • open ttyRPMSG0
  • write to ttyRPMSG0
  • read from ttyRPMSG0
  • close ttyRPMSG0

3. API[edit source]

3.1. CoproManager API[edit source]

The CoproManager API gives access to the Firmware management.

  • CoproManager getInstance(): Get the instance of the available CoproManager to start using it.
  • FirmwareInfo[] getFirmwareList(): Return the list of available firmwares present in /vendor/firmware/copro/
  • FirmwareInfo getFirmwareByName(String name): Looks up a firmware by its name in the /vendor/firmware/copro/ folder and returns all useful information about it, overwise returns null.
  • boolean isFirmwareRunning(int id): Returns true if the Firmware of identifier id is running, otherwise returns false.
  • void startFirmware(int id): Starts the Firmware defined by its identifier id.
  • void stopFirmware(): Stop any running Firmware
  • CoproSerialPort getSerialPort(): Get access to CoproSerialPort to interact with the Firmware. See below for more info.

3.2. FirmwareInfo API[edit source]

The FirmwareInfo API gives information about Firmwares.

  • int getId(): get the ID given by the CoproService to this Firmware
  • String getName(): get the file name of this Firmware
  • boolean getState(): returns the state of the Firmware at the moment of the call: running (true) or stopped (false).

3.3. CoproSerialPort API[edit source]

The CoproSerialPort API gives access to the /dev/ttyRPMSG0 driver available when a Firmware is running. It allows the application to open and close the interface and also to send and receive data.

  • void open(int mode): opens a file descriptor to /dev/ttyRPMSG0 with the given mode : 0 for normal mode, 1 for raw mode
  • void close(): closes the file descriptor to /dev/ttyRPMSG0
  • String read(): reads available bytes if the file descriptor is open, overwise an empty string is returned.
  • void write(String command): write the given "command" to the file descriptor.

4. Developping a Copro application[edit source]

In order to build the application, make sure you are using the appropriate Android SDK including CoproService How to build and install an SDK.

In Android Studio create a new application.

Then, do not forget to select the right API level in the application Manifest, in order to be sure that CoproService is available.

To use the CoproService you need to get the instance to the CoproManager, then you will be able to use the CoproManager API defined above:

CoproManager mCoproManager = CoproManager.getInstance();

To be able to communicate with the running Firmware you need to get a CoproSerialPort from CoproManager, then you will be available to use the CoproSerialPort API defined above :

ICoproSerialPort mCoproSerialPort = mCoproManager.getSerialPort();

The serial communication is possible only if a Firmware is running. Make sure to close the serial communication when you stop a firmware and open it when you start one.


Renaming.png This page is a candidate for renaming (move).
The requested new name is: How to use coprocessor service for Android .
The supplied reason is: request to add Android name in each How To concerned .
-- N. Louboutin.
Wiki maintainers: remember to update the pages that link this page before renaming (moving) it.