openamp — Provide standard Asymmetric Multi-Processing (AMP) support
The openamp module provides a standard inter-processor communication infrastructure for MicroPython. This module handles all the details of OpenAMP, such as setting up the shared resource table, initializing the vring, etc. It provides an API for using the RPMsg bus infrastructure through the Endpoint class, and provides processor lifecycle management (LCM) support through the RemoteProc class, such as loading firmware and starting and stopping the remote core.
Usage example:
import openamp
def ept_recv_callback(src, data):
print("Message received on endpoint", data)
# Create a new RPMsg endpoint to communicate with the remote core
ept = openamp.Endpoint("vuart-channel", callback=ept_recv_callback)
# Create a RemoteProc object, load its firmware and start it
rproc = openamp.RemoteProc("virtual_uart.elf") # or an entry point address (e.g. 0x081E0000)
rproc.start()
while True:
if ept.is_ready():
ept.send("data")
Functions
- openamp.new_service_callback(ns_callback)
Set the new service callback function.
The ns_callback parameter is a function that will be called when the remote processor announces a new service. At this point, the host processor can choose to create the announced endpoint (if this specific service is supported), or ignore it (if it is not supported). If this function is not set, the host processor should first register the endpoint locally, and it will be automatically bound when the remote announces the service.
Endpoint Class
- class openamp.Endpoint(name, callback, src=ENDPOINT_ADDR_ANY, dest=ENDPOINT_ADDR_ANY)
Construct a new RPMsg endpoint. An endpoint is a bidirectional communication channel between two cores.
Parameters:
name is the name of the endpoint.
callback is a function that is called when the endpoint receives data, with arguments being the source address of the remote endpoint and the data (bytes) passed by reference.
src is the endpoint source address. If not provided, the library will allocate one for the endpoint.
dest is the endpoint destination address. If the endpoint is created from new_service_callback, this parameter must be provided and it must match the source address of the remote endpoint. If the endpoint is registered locally before being announced, the library will allocate the destination address when the endpoint is bound.
- Endpoint.deinit()
Destroy the endpoint and release all its resources.
- Endpoint.is_ready()
Return
Trueif the endpoint is ready to send (i.e. it has both a source address and a destination address).
- Endpoint.send(src=-1, dest=-1, timeout=-1)
Send a message to the remote processor through this endpoint.
Parameters:
src is the source endpoint address of the message. If not provided, the source address bound to the endpoint is used.
dest is the destination endpoint address of the message. If not provided, the destination address bound to the endpoint is used.
timeout specifies the time to wait for a free buffer (in milliseconds). By default, the function is blocking.
RemoteProc Class
- class openamp.RemoteProc(entry)
A RemoteProc object provides processor lifecycle management (LCM) support, such as loading firmware and starting and stopping the remote core.
The entry parameter can be the path to a firmware image, in which case the firmware will be loaded from the file into its target memory, or an entry point address, in which case the firmware must already be loaded at the given address.
- RemoteProc.start()
Start the remote processor.
- RemoteProc.stop()
Stop the remote processor. The exact behavior depends on the platform. For example, on the STM32H7, the Cortex-M4 core cannot be stopped and then restarted, so a full system reset is performed when this function is called.
- RemoteProc.shutdown()
Shutdown stops the remote processor and releases all its resources. The exact behavior depends on the platform, but it usually disables the power and clock of the remote core. This function is also used as a finalizer (i.e. it is called when the
RemoteProcobject is collected). Note that on the STM32H7, the Cortex-M4 core cannot be stopped and then restarted, so a full system reset is performed when this function is called.