add initial Setup
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
bdb5db2009
1955 files changed
+1004711
No files matched your search
@@ -0,0 +1,213 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* File Name : mbox_hsem.c
|
||||
* Description : This file provides code for the configuration
|
||||
* of the mailbox based on hardware semaphore.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2026 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "openamp/open_amp.h"
|
||||
#include "stm32h7xx_hal.h"
|
||||
#include "openamp_conf.h"
|
||||
#include "mbox_hsem.h"
|
||||
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Define */
|
||||
|
||||
/* USER CODE END Define */
|
||||
|
||||
#define RX_NO_MSG 0
|
||||
#define RX_NEW_MSG 1
|
||||
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PV */
|
||||
|
||||
/* USER CODE END PV */
|
||||
|
||||
static uint32_t msg_received = RX_NO_MSG;
|
||||
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PFP */
|
||||
|
||||
/* USER CODE END PFP */
|
||||
|
||||
void HAL_HSEM_FreeCallback(uint32_t SemMask)
|
||||
{
|
||||
|
||||
/* USER CODE BEGIN HSEM_FREE_CALLBACK */
|
||||
|
||||
/* USER CODE END HSEM_FREE_CALLBACK */
|
||||
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(SemMask);
|
||||
msg_received = RX_NEW_MSG;
|
||||
|
||||
#ifdef CORE_CM7
|
||||
|
||||
/* USER CODE BEGIN PRE_HSEM_FREE_CALLBACK_CM7 */
|
||||
|
||||
/* USER CODE END PRE_HSEM_FREE_CALLBACK_CM7 */
|
||||
|
||||
HAL_HSEM_ActivateNotification(__HAL_HSEM_SEMID_TO_MASK(HSEM_ID_1));
|
||||
|
||||
/* USER CODE BEGIN POST_HSEM_FREE_CALLBACK_CM7 */
|
||||
|
||||
/* USER CODE END POST_HSEM_FREE_CALLBACK_CM7 */
|
||||
|
||||
#endif
|
||||
#ifdef CORE_CM4
|
||||
|
||||
/* USER CODE BEGIN PRE_HSEM_FREE_CALLBACK_CM4 */
|
||||
|
||||
/* USER CODE END PRE_HSEM_FREE_CALLBACK_CM4 */
|
||||
|
||||
HAL_HSEM_ActivateNotification(__HAL_HSEM_SEMID_TO_MASK(HSEM_ID_0));
|
||||
|
||||
/* USER CODE BEGIN POST_HSEM_FREE_CALLBACK_CM4 */
|
||||
|
||||
/* USER CODE END POST_HSEM_FREE_CALLBACK_CM4 */
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initialize MAILBOX with HSEM peripheral
|
||||
* @param None
|
||||
* @retval : Operation result
|
||||
*/
|
||||
int MAILBOX_Init(void)
|
||||
{
|
||||
/* USER CODE BEGIN MAILBOX_INIT */
|
||||
|
||||
/* USER CODE END MAILBOX_INIT */
|
||||
__HAL_RCC_HSEM_CLK_ENABLE();
|
||||
|
||||
#ifdef CORE_CM7
|
||||
|
||||
/* USER CODE BEGIN PRE_MAILBOX_INIT_CM7 */
|
||||
|
||||
/* USER CODE END PRE_MAILBOX_INIT_CM7 */
|
||||
|
||||
HAL_HSEM_ActivateNotification(__HAL_HSEM_SEMID_TO_MASK(HSEM_ID_1));
|
||||
|
||||
/* USER CODE BEGIN POST_MAILBOX_INIT_CM7 */
|
||||
|
||||
/* USER CODE END POST_MAILBOX_INIT_CM7 */
|
||||
#endif
|
||||
#ifdef CORE_CM4
|
||||
|
||||
/* USER CODE BEGIN MAILBOX_INIT_CM4 */
|
||||
|
||||
/* USER CODE END MAILBOX_INIT_CM4 */
|
||||
|
||||
HAL_HSEM_ActivateNotification(__HAL_HSEM_SEMID_TO_MASK(HSEM_ID_0));
|
||||
|
||||
/* USER CODE BEGIN POST_MAILBOX_INIT_CM4 */
|
||||
|
||||
/* USER CODE END POST_MAILBOX_INIT_CM4 */
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initialize MAILBOX with HSEM peripheral
|
||||
* @param virtio device
|
||||
* @retval : Operation result
|
||||
*/
|
||||
int MAILBOX_Poll(struct virtio_device *vdev)
|
||||
{
|
||||
/* If we got an interrupt, ask for the corresponding virtqueue processing */
|
||||
|
||||
if (msg_received == RX_NEW_MSG)
|
||||
{
|
||||
|
||||
/* USER CODE BEGIN NEW_MSG */
|
||||
|
||||
/* USER CODE END NEW_MSG */
|
||||
#ifdef CORE_CM7
|
||||
|
||||
/* USER CODE BEGIN PRE_NEW_MSG_CM7 */
|
||||
|
||||
/* USER CODE END PRE_NEW_MSG_CM7 */
|
||||
|
||||
rproc_virtio_notified(vdev, VRING0_ID);
|
||||
|
||||
/* USER CODE BEGIN POST_NEW_MSG_CM7 */
|
||||
|
||||
/* USER CODE END POST_NEW_MSG_CM7 */
|
||||
#endif
|
||||
#ifdef CORE_CM4
|
||||
|
||||
/* USER CODE BEGIN PRE_NEW_MSG_CM4 */
|
||||
|
||||
/* USER CODE END PRE_NEW_MSG_CM4 */
|
||||
|
||||
rproc_virtio_notified(vdev, VRING1_ID);
|
||||
|
||||
/* USER CODE BEGIN POST_NEW_MSG_CM4 */
|
||||
|
||||
/* USER CODE END POST_NEW_MSG_CM4 */
|
||||
#endif
|
||||
msg_received = RX_NO_MSG;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN NO_MSG */
|
||||
|
||||
/* USER CODE END NO_MSG */
|
||||
return -EAGAIN;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Callback function called by OpenAMP MW to notify message processing
|
||||
* @param VRING id
|
||||
* @retval Operation result
|
||||
*/
|
||||
int MAILBOX_Notify(void *priv, uint32_t id)
|
||||
{
|
||||
(void)priv;
|
||||
(void)id;
|
||||
|
||||
/* USER CODE BEGIN MAILBOX_NOTIFY*/
|
||||
|
||||
/* USER CODE END MAILBOX_NOTIFY */
|
||||
#ifdef CORE_CM7
|
||||
|
||||
/* USER CODE BEGIN PRE_MAILBOX_NOTIFY_CM7 */
|
||||
|
||||
/* USER CODE END PRE_MAILBOX_NOTIFY_CM7 */
|
||||
HAL_HSEM_FastTake(HSEM_ID_0);
|
||||
HAL_HSEM_Release(HSEM_ID_0,0);
|
||||
|
||||
/* USER CODE BEGIN POST_MAILBOX_NOTIFY_CM7 */
|
||||
|
||||
/* USER CODE END POST_MAILBOX_NOTIFY_CM7 */
|
||||
#endif
|
||||
#ifdef CORE_CM4
|
||||
|
||||
/* USER CODE BEGIN PRE_MAILBOX_NOTIFY_CM4 */
|
||||
|
||||
/* USER CODE END PRE_MAILBOX_NOTIFY_CM4 */
|
||||
|
||||
HAL_HSEM_FastTake(HSEM_ID_1);
|
||||
HAL_HSEM_Release(HSEM_ID_1,0);
|
||||
|
||||
/* USER CODE BEGIN POST_MAILBOX_NOTIFY_CM4 */
|
||||
|
||||
/* USER CODE END POST_MAILBOX_NOTIFY_CM4 */
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file mabox_hsem.h
|
||||
* @author MCD Application Team
|
||||
* @brief header for mbox_hsem.c module
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2026 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef MBOX_HSEM_H_
|
||||
#define MBOX_HSEM_H_
|
||||
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN ET */
|
||||
|
||||
/* USER CODE END ET */
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* USER CODE BEGIN EC */
|
||||
|
||||
/* USER CODE END EC */
|
||||
|
||||
/* Private defines -----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Private defines */
|
||||
|
||||
/* USER CODE END Private defines */
|
||||
|
||||
#define HSEM_ID_0 0 /* CM7 to CM4 Notification */
|
||||
#define HSEM_ID_1 1 /* CM4 to CM7 Notification */
|
||||
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN EM */
|
||||
|
||||
/* USER CODE END EM */
|
||||
|
||||
/* Exported functions prototypes ---------------------------------------------*/
|
||||
/* USER CODE BEGIN EFP */
|
||||
|
||||
/* USER CODE END EFP */
|
||||
|
||||
int MAILBOX_Notify(void *priv, uint32_t id);
|
||||
int MAILBOX_Init(void);
|
||||
int MAILBOX_Poll(struct virtio_device *vdev);
|
||||
|
||||
#endif /* MBOX_HSEM_H_ */
|
||||
@@ -0,0 +1,282 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file openamp.c
|
||||
* @author MCD Application Team
|
||||
* @brief Code for openamp applications
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2026 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
#include "openamp.h"
|
||||
#include "rsc_table.h"
|
||||
#include "metal/sys.h"
|
||||
#include "metal/device.h"
|
||||
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Define */
|
||||
|
||||
/* USER CODE END Define */
|
||||
|
||||
#define SHM_DEVICE_NAME "STM32_SHM"
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PM */
|
||||
|
||||
/* USER CODE END PM */
|
||||
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PV */
|
||||
|
||||
/* USER CODE END PV */
|
||||
|
||||
static struct metal_io_region *shm_io;
|
||||
static struct metal_io_region *rsc_io;
|
||||
static struct shared_resource_table *rsc_table;
|
||||
static struct rpmsg_virtio_shm_pool shpool;
|
||||
static struct rpmsg_virtio_device rvdev;
|
||||
|
||||
static metal_phys_addr_t shm_physmap;
|
||||
|
||||
struct metal_device shm_device = {
|
||||
.name = SHM_DEVICE_NAME,
|
||||
.num_regions = 2,
|
||||
.regions = {
|
||||
{.virt = NULL}, /* shared memory */
|
||||
{.virt = NULL}, /* rsc_table memory */
|
||||
},
|
||||
.node = { NULL },
|
||||
.irq_num = 0,
|
||||
.irq_info = NULL
|
||||
};
|
||||
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PFP */
|
||||
|
||||
/* USER CODE END PFP */
|
||||
|
||||
static int OPENAMP_shmem_init(int RPMsgRole)
|
||||
{
|
||||
int status = 0;
|
||||
struct metal_device *device = NULL;
|
||||
struct metal_init_params metal_params = METAL_INIT_DEFAULTS;
|
||||
void* rsc_tab_addr = NULL;
|
||||
int rsc_size = 0;
|
||||
|
||||
/* USER CODE BEGIN PRE_LIB_METAL_INIT */
|
||||
|
||||
/* USER CODE END PRE_LIB_METAL_INIT */
|
||||
metal_init(&metal_params);
|
||||
|
||||
status = metal_register_generic_device(&shm_device);
|
||||
if (status != 0) {
|
||||
return status;
|
||||
}
|
||||
|
||||
status = metal_device_open("generic", SHM_DEVICE_NAME, &device);
|
||||
if (status != 0) {
|
||||
return status;
|
||||
}
|
||||
|
||||
shm_physmap = SHM_START_ADDRESS;
|
||||
metal_io_init(&device->regions[0], (void *)SHM_START_ADDRESS, &shm_physmap,
|
||||
SHM_SIZE, -1, 0, NULL);
|
||||
|
||||
/* USER CODE BEGIN PRE_SHM_IO_INIT */
|
||||
|
||||
/* USER CODE END PRE_SHM_IO_INIT */
|
||||
shm_io = metal_device_io_region(device, 0);
|
||||
if (shm_io == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN POST_SHM_IO_INIT */
|
||||
|
||||
/* USER CODE END POST_SHM_IO_INIT */
|
||||
|
||||
/* Initialize resources table variables */
|
||||
resource_table_init(RPMsgRole, &rsc_tab_addr, &rsc_size);
|
||||
rsc_table = (struct shared_resource_table *)rsc_tab_addr;
|
||||
if (!rsc_table)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN POST_RSC_TABLE_INIT */
|
||||
|
||||
/* USER CODE END POST_RSC_TABLE_INIT */
|
||||
|
||||
metal_io_init(&device->regions[1], rsc_table,
|
||||
(metal_phys_addr_t *)rsc_table, rsc_size, -1U, 0, NULL);
|
||||
|
||||
/* USER CODE BEGIN POST_METAL_IO_INIT */
|
||||
|
||||
/* USER CODE END POST_METAL_IO_INIT */
|
||||
rsc_io = metal_device_io_region(device, 1);
|
||||
if (rsc_io == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN POST_RSC_IO_INIT */
|
||||
|
||||
/* USER CODE END POST_RSC_IO_INIT */
|
||||
return 0;
|
||||
}
|
||||
|
||||
int MX_OPENAMP_Init(int RPMsgRole, rpmsg_ns_bind_cb ns_bind_cb)
|
||||
{
|
||||
struct fw_rsc_vdev_vring *vring_rsc = NULL;
|
||||
struct virtio_device *vdev = NULL;
|
||||
int status = 0;
|
||||
|
||||
/* USER CODE BEGIN MAILBOX_Init */
|
||||
|
||||
/* USER CODE END MAIL_BOX_Init */
|
||||
|
||||
MAILBOX_Init();
|
||||
|
||||
/* Libmetal Initilalization */
|
||||
status = OPENAMP_shmem_init(RPMsgRole);
|
||||
if(status)
|
||||
{
|
||||
return status;
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN PRE_VIRTIO_INIT */
|
||||
|
||||
/* USER CODE END PRE_VIRTIO_INIT */
|
||||
vdev = rproc_virtio_create_vdev(RPMsgRole, VDEV_ID, &rsc_table->vdev,
|
||||
rsc_io, NULL, MAILBOX_Notify, NULL);
|
||||
if (vdev == NULL)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
rproc_virtio_wait_remote_ready(vdev);
|
||||
|
||||
/* USER CODE BEGIN POST_VIRTIO_INIT */
|
||||
|
||||
/* USER CODE END POST_VIRTIO_INIT */
|
||||
vring_rsc = &rsc_table->vring0;
|
||||
status = rproc_virtio_init_vring(vdev, 0, vring_rsc->notifyid,
|
||||
(void *)vring_rsc->da, shm_io,
|
||||
vring_rsc->num, vring_rsc->align);
|
||||
if (status != 0)
|
||||
{
|
||||
return status;
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN POST_VRING0_INIT */
|
||||
|
||||
/* USER CODE END POST_VRING0_INIT */
|
||||
vring_rsc = &rsc_table->vring1;
|
||||
status = rproc_virtio_init_vring(vdev, 1, vring_rsc->notifyid,
|
||||
(void *)vring_rsc->da, shm_io,
|
||||
vring_rsc->num, vring_rsc->align);
|
||||
if (status != 0)
|
||||
{
|
||||
return status;
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN POST_VRING1_INIT */
|
||||
|
||||
/* USER CODE END POST_VRING1_INIT */
|
||||
|
||||
rpmsg_virtio_init_shm_pool(&shpool, (void *)VRING_BUFF_ADDRESS,
|
||||
(size_t)SHM_SIZE);
|
||||
rpmsg_init_vdev(&rvdev, vdev, ns_bind_cb, shm_io, &shpool);
|
||||
|
||||
/* USER CODE BEGIN POST_RPMSG_INIT */
|
||||
|
||||
/* USER CODE END POST_RPMSG_INIT */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void OPENAMP_DeInit()
|
||||
{
|
||||
|
||||
/* USER CODE BEGIN PRE_OPENAMP_DEINIT */
|
||||
|
||||
/* USER CODE END PRE_OPENAMP_DEINIT */
|
||||
|
||||
rpmsg_deinit_vdev(&rvdev);
|
||||
|
||||
metal_finish();
|
||||
|
||||
/* USER CODE BEGIN POST_OPENAMP_DEINIT */
|
||||
|
||||
/* USER CODE END POST_OPENAMP_DEINIT */
|
||||
}
|
||||
|
||||
void OPENAMP_init_ept(struct rpmsg_endpoint *ept)
|
||||
{
|
||||
/* USER CODE BEGIN PRE_EP_INIT */
|
||||
|
||||
/* USER CODE END PRE_EP_INIT */
|
||||
|
||||
rpmsg_init_ept(ept, "", RPMSG_ADDR_ANY, RPMSG_ADDR_ANY, NULL, NULL);
|
||||
|
||||
/* USER CODE BEGIN POST_EP_INIT */
|
||||
|
||||
/* USER CODE END POST_EP_INIT */
|
||||
}
|
||||
|
||||
int OPENAMP_create_endpoint(struct rpmsg_endpoint *ept, const char *name,
|
||||
uint32_t dest, rpmsg_ept_cb cb,
|
||||
rpmsg_ns_unbind_cb unbind_cb)
|
||||
{
|
||||
int ret = 0;
|
||||
/* USER CODE BEGIN PRE_EP_CREATE */
|
||||
|
||||
/* USER CODE END PRE_EP_CREATE */
|
||||
|
||||
ret = rpmsg_create_ept(ept, &rvdev.rdev, name, RPMSG_ADDR_ANY, dest, cb,
|
||||
unbind_cb);
|
||||
|
||||
/* USER CODE BEGIN POST_EP_CREATE */
|
||||
|
||||
/* USER CODE END POST_EP_CREATE */
|
||||
return ret;
|
||||
}
|
||||
|
||||
void OPENAMP_check_for_message(void)
|
||||
{
|
||||
/* USER CODE BEGIN MSG_CHECK */
|
||||
|
||||
/* USER CODE END MSG_CHECK */
|
||||
MAILBOX_Poll(rvdev.vdev);
|
||||
}
|
||||
|
||||
void OPENAMP_Wait_EndPointready(struct rpmsg_endpoint *rp_ept)
|
||||
{
|
||||
/* USER CODE BEGIN EP_READY */
|
||||
|
||||
/* USER CODE END EP_READY */
|
||||
|
||||
while(!is_rpmsg_ept_ready(rp_ept))
|
||||
{
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
/* USER CODE END 0 */
|
||||
MAILBOX_Poll(rvdev.vdev);
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file openamp.h
|
||||
* @brief Header for openamp applications
|
||||
* @author MCD Application Team
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2026 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __openamp_H
|
||||
#define __openamp_H
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "openamp/open_amp.h"
|
||||
#include "openamp_conf.h"
|
||||
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN ET */
|
||||
|
||||
/* USER CODE END ET */
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* USER CODE BEGIN EC */
|
||||
|
||||
/* USER CODE END EC */
|
||||
|
||||
/* Private defines -----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Private defines */
|
||||
|
||||
/* USER CODE END Private defines */
|
||||
|
||||
#define OPENAMP_send rpmsg_send
|
||||
#define OPENAMP_destroy_ept rpmsg_destroy_ept
|
||||
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN EM */
|
||||
|
||||
/* USER CODE END EM */
|
||||
|
||||
/* Exported functions prototypes ---------------------------------------------*/
|
||||
/* USER CODE BEGIN EFP */
|
||||
|
||||
/* USER CODE END EFP */
|
||||
|
||||
/* Initialize the openamp framework*/
|
||||
int MX_OPENAMP_Init(int RPMsgRole, rpmsg_ns_bind_cb ns_bind_cb);
|
||||
|
||||
/* Deinitialize the openamp framework*/
|
||||
void OPENAMP_DeInit(void);
|
||||
|
||||
/* Initialize the endpoint struct*/
|
||||
void OPENAMP_init_ept(struct rpmsg_endpoint *ept);
|
||||
|
||||
/* Create and register the endpoint */
|
||||
int OPENAMP_create_endpoint(struct rpmsg_endpoint *ept, const char *name,
|
||||
uint32_t dest, rpmsg_ept_cb cb,
|
||||
rpmsg_ns_unbind_cb unbind_cb);
|
||||
|
||||
/* Check for new rpmsg reception */
|
||||
void OPENAMP_check_for_message(void);
|
||||
|
||||
/* Wait loop on endpoint ready ( message dest address is know)*/
|
||||
void OPENAMP_Wait_EndPointready(struct rpmsg_endpoint *rp_ept);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /*__openamp_H */
|
||||
|
||||
@@ -0,0 +1,247 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file openamp_conf.h
|
||||
* @author MCD Application Team
|
||||
* @brief Configuration file for OpenAMP MW
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2026 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __OPENAMP_CONF__H__
|
||||
#define __OPENAMP_CONF__H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#if defined (__LOG_TRACE_IO_) || defined(__LOG_UART_IO_)
|
||||
#include "openamp_log.h"
|
||||
#endif
|
||||
|
||||
/* ########################## Mailbox Interface Selection ############################## */
|
||||
/**
|
||||
* @brief This is the list of Mailbox interface to be used in the OpenAMP MW
|
||||
* Please note that not all interfaces are supported by a STM32 device
|
||||
*/
|
||||
//#define MAILBOX_IPCC_IF_ENABLED
|
||||
#define MAILBOX_HSEM_IF_ENABLED
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief Include Mailbox interface header file
|
||||
*/
|
||||
|
||||
#ifdef MAILBOX_IPCC_IF_ENABLED
|
||||
#include "mbox_ipcc.h"
|
||||
#endif /* MAILBOX_IPCC_IF_ENABLED */
|
||||
|
||||
#ifdef MAILBOX_HSEM_IF_ENABLED
|
||||
#include "mbox_hsem.h"
|
||||
#endif /* MAILBOX_HSEM_IF_ENABLED */
|
||||
|
||||
/* ########################## Virtual Diver Module Selection ############################## */
|
||||
/**
|
||||
* @brief This is the list of modules to be used in the OpenAMP Virtual driver module
|
||||
* Please note that virtual driver are not supported on all stm32 families
|
||||
*/
|
||||
//#define VIRTUAL_UART_MODULE_ENABLED
|
||||
//#define VIRTUAL_I2C_MODULE_ENABLED
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief Include Virtual Driver module's header file
|
||||
*/
|
||||
|
||||
#ifdef VIRTUAL_UART_MODULE_ENABLED
|
||||
#include "virt_uart.h"
|
||||
#endif /* VIRTUAL_UART_MODULE_ENABLED */
|
||||
|
||||
#ifdef VIRTUAL_I2C_MODULE_ENABLED
|
||||
#include "virt_i2c.h"
|
||||
#endif /* VIRTUAL_I2C_MODULE_ENABLED */
|
||||
|
||||
/* ########################## Linux Master Selection ############################## */
|
||||
/**
|
||||
* @brief Due to Linux compatibility, it's important to distinguish if the MASTER is Linux or not.
|
||||
* In that case, the LINUX_RPROC_MASTER define is required
|
||||
*/
|
||||
//#define LINUX_RPROC_MASTER
|
||||
|
||||
/* USER CODE BEGIN INCLUDE */
|
||||
|
||||
/* USER CODE END INCLUDE */
|
||||
|
||||
/** @addtogroup OPENAMP_MW
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup OPENAMP_CONF OPENAMP_CONF
|
||||
* @brief Configuration file for Openamp mw
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup OPENAMP_CONF_Exported_Variables OPENAMP_CONF_Exported_Variables
|
||||
* @brief Public variables.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup OPENAMP_CONF_Exported_Defines OPENAMP_CONF_Exported_Defines
|
||||
* @brief Defines for configuration of the Openamp mw
|
||||
* @{
|
||||
*/
|
||||
|
||||
#if defined (__ICCARM__)
|
||||
/*
|
||||
* For IAR, the .icf file should contain the following lines:
|
||||
* define symbol __OPENAMP_region_start__ = BASE_ADDRESS; (0x38000400 for example)
|
||||
* define symbol __OPENAMP_region_size__ = MEM_SIZE; (0xB000 as example)
|
||||
*
|
||||
* export symbol __OPENAMP_region_start__;
|
||||
* export symbol __OPENAMP_region_size__;
|
||||
*/
|
||||
extern const uint32_t __OPENAMP_region_start__;
|
||||
extern const uint8_t __OPENAMP_region_size__;
|
||||
#define SHM_START_ADDRESS ((metal_phys_addr_t)&__OPENAMP_region_start__)
|
||||
#define SHM_SIZE ((size_t)&__OPENAMP_region_size__)
|
||||
|
||||
#elif defined(__CC_ARM) || defined (__clang__)
|
||||
/*
|
||||
* For MDK-ARM, the scatter file .sct should contain the following line:
|
||||
* LR_IROM1 .... {
|
||||
* ...
|
||||
* __OpenAMP_SHMEM__ 0x38000400 EMPTY 0x0000B000 {} ; Shared Memory area used by OpenAMP
|
||||
* }
|
||||
*
|
||||
*/
|
||||
extern unsigned int Image$$__OpenAMP_SHMEM__$$Base;
|
||||
extern unsigned int Image$$__OpenAMP_SHMEM__$$ZI$$Length;
|
||||
#define SHM_START_ADDRESS (unsigned int)&Image$$__OpenAMP_SHMEM__$$Base
|
||||
#define SHM_SIZE ((size_t)&Image$$__OpenAMP_SHMEM__$$ZI$$Length)
|
||||
|
||||
#else
|
||||
/*
|
||||
* for GCC add the following content to the .ld file:
|
||||
* MEMORY
|
||||
* {
|
||||
* ...
|
||||
* OPEN_AMP_SHMEM (xrw) : ORIGIN = 0x38000400, LENGTH = 63K
|
||||
* }
|
||||
* __OPENAMP_region_start__ = ORIGIN(OPEN_AMP_SHMEM);
|
||||
* __OPENAMP_region_end__ = ORIGIN(OPEN_AMP_SHMEM) + LENGTH(OPEN_AMP_SHMEM);
|
||||
*
|
||||
* using the LENGTH(OPEN_AMP_SHMEM) to set the SHM_SIZE lead to a crash thus we
|
||||
* use the start and end address.
|
||||
*/
|
||||
|
||||
extern int __OPENAMP_region_start__[]; /* defined by linker script */
|
||||
extern int __OPENAMP_region_end__[]; /* defined by linker script */
|
||||
|
||||
#define SHM_START_ADDRESS ((metal_phys_addr_t)__OPENAMP_region_start__)
|
||||
#define SHM_SIZE (size_t)((void *)__OPENAMP_region_end__ - (void *) __OPENAMP_region_start__)
|
||||
|
||||
#endif
|
||||
|
||||
#if defined LINUX_RPROC_MASTER
|
||||
#define VRING_RX_ADDRESS -1 /* allocated by Master processor: CA7 */
|
||||
#define VRING_TX_ADDRESS -1 /* allocated by Master processor: CA7 */
|
||||
#define VRING_BUFF_ADDRESS -1 /* allocated by Master processor: CA7 */
|
||||
#define VRING_ALIGNMENT 16 /* fixed to match with linux constraint */
|
||||
#define VRING_NUM_BUFFS 16 /* number of rpmsg buffer */
|
||||
#else
|
||||
#define VRING_RX_ADDRESS SHM_START_ADDRESS
|
||||
#define VRING_TX_ADDRESS (SHM_START_ADDRESS + 0x400)
|
||||
#define VRING_BUFF_ADDRESS (SHM_START_ADDRESS + 0x800)
|
||||
#define VRING_ALIGNMENT 4
|
||||
#define VRING_NUM_BUFFS 4 /* number of rpmsg buffers */
|
||||
#endif
|
||||
|
||||
/* Fixed parameter */
|
||||
|
||||
#define NUM_RESOURCE_ENTRIES 2
|
||||
|
||||
#define VRING_COUNT 2
|
||||
|
||||
#define VDEV_ID 0xFF
|
||||
|
||||
#define VRING0_ID 0 /* VRING0 ID (master to remote) fixed to 0 for linux compatibility*/
|
||||
|
||||
#define VRING1_ID 1 /* VRING1 ID (remote to master) fixed to 1 for linux compatibility */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup OPENAMP_CONF_Exported_Macros OPENAMP_CONF_Exported_Macros
|
||||
* @brief Aliases.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* DEBUG macros */
|
||||
|
||||
#if defined (__LOG_TRACE_IO_) || defined(__LOG_UART_IO_)
|
||||
#define OPENAMP_log_dbg log_dbg
|
||||
#define OPENAMP_log_info log_info
|
||||
#define OPENAMP_log_warn log_warn
|
||||
#define OPENAMP_log_err log_err
|
||||
#else
|
||||
#define OPENAMP_log_dbg(...)
|
||||
#define OPENAMP_log_info(...)
|
||||
#define OPENAMP_log_warn(...)
|
||||
#define OPENAMP_log_err(...)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup OPENAMP_CONF_Exported_Types OPENAMP_CONF_Exported_Types
|
||||
* @brief Types.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup OPENAMP_CONF_Exported_FunctionsPrototype OPENAMP_CONF_Exported_FunctionsPrototype
|
||||
* @brief Declaration of public functions for OpenAMP mw.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Exported functions -------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __OPENAMP_CONF__H__ */
|
||||
|
||||
@@ -0,0 +1,175 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file rsc_table.c
|
||||
* @author MCD Application Team
|
||||
* @brief Resource table
|
||||
*
|
||||
* This file provides a default resource table requested by remote proc to
|
||||
* load the elf file. It also allows to add debug trace using a shared buffer.
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2026 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
/** @addtogroup RSC_TABLE
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup resource_table
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup resource_table_Private_Includes
|
||||
* @{
|
||||
*/
|
||||
|
||||
#if defined(__ICCARM__) || defined (__CC_ARM)
|
||||
#include <stddef.h> /* needed for offsetof definition*/
|
||||
#endif
|
||||
#include "rsc_table.h"
|
||||
#include "openamp/open_amp.h"
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup resource_table_Private_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup resource_table_Private_Defines
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Place resource table in special ELF section */
|
||||
#if defined(__GNUC__)
|
||||
#define __section_t(S) __attribute__((__section__(#S)))
|
||||
#define __resource __section_t(.resource_table)
|
||||
#endif
|
||||
|
||||
#if defined (LINUX_RPROC_MASTER)
|
||||
#ifdef VIRTIO_MASTER_ONLY
|
||||
#define CONST
|
||||
#else
|
||||
#define CONST const
|
||||
#endif
|
||||
#else
|
||||
#define CONST
|
||||
#endif
|
||||
|
||||
#define RPMSG_IPU_C0_FEATURES 1
|
||||
#define VRING_COUNT 2
|
||||
|
||||
/* VirtIO rpmsg device id */
|
||||
#define VIRTIO_ID_RPMSG_ 7
|
||||
|
||||
#if defined (__LOG_TRACE_IO_)
|
||||
extern char system_log_buf[];
|
||||
#endif
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#if !defined (__CC_ARM) && !defined (LINUX_RPROC_MASTER)
|
||||
|
||||
/* Since GCC is not initializing the resource_table at startup, it is declared as volatile to avoid compiler optimization
|
||||
* for the CM4 (see resource_table_init() below)
|
||||
*/
|
||||
volatile struct shared_resource_table __resource __attribute__((used)) resource_table;
|
||||
#else
|
||||
CONST struct shared_resource_table __resource __attribute__((used)) resource_table = {
|
||||
#endif
|
||||
#elif defined(__ICCARM__)
|
||||
__root CONST struct shared_resource_table resource_table @ ".resource_table" = {
|
||||
#endif
|
||||
|
||||
#if defined(__ICCARM__) || defined (__CC_ARM) || defined (LINUX_RPROC_MASTER)
|
||||
.version = 1,
|
||||
#if defined (__LOG_TRACE_IO_)
|
||||
.num = 2,
|
||||
#else
|
||||
.num = 1,
|
||||
#endif
|
||||
.reserved = {0, 0},
|
||||
.offset = {
|
||||
offsetof(struct shared_resource_table, vdev),
|
||||
offsetof(struct shared_resource_table, cm_trace),
|
||||
},
|
||||
|
||||
/* Virtio device entry */
|
||||
.vdev= {
|
||||
RSC_VDEV, VIRTIO_ID_RPMSG_, 0, RPMSG_IPU_C0_FEATURES, 0, 0, 0,
|
||||
VRING_COUNT, {0, 0},
|
||||
},
|
||||
|
||||
/* Vring rsc entry - part of vdev rsc entry */
|
||||
.vring0 = {VRING_TX_ADDRESS, VRING_ALIGNMENT, VRING_NUM_BUFFS, VRING0_ID, 0},
|
||||
.vring1 = {VRING_RX_ADDRESS, VRING_ALIGNMENT, VRING_NUM_BUFFS, VRING1_ID, 0},
|
||||
|
||||
#if defined (__LOG_TRACE_IO_)
|
||||
.cm_trace = {
|
||||
RSC_TRACE,
|
||||
(uint32_t)system_log_buf, SYSTEM_TRACE_BUF_SZ, 0, "cm4_log",
|
||||
},
|
||||
#endif
|
||||
} ;
|
||||
#endif
|
||||
|
||||
void resource_table_init(int RPMsgRole, void **table_ptr, int *length)
|
||||
{
|
||||
|
||||
#if !defined (LINUX_RPROC_MASTER)
|
||||
#if defined (__GNUC__) && ! defined (__CC_ARM)
|
||||
#ifdef VIRTIO_MASTER_ONLY
|
||||
|
||||
/*
|
||||
* Currently the GCC linker doesn't initialize the resource_table global variable at startup
|
||||
* it is done here by the master application.
|
||||
*/
|
||||
memset(&resource_table, '\0', sizeof(struct shared_resource_table));
|
||||
resource_table.num = 1;
|
||||
resource_table.version = 1;
|
||||
resource_table.offset[0] = offsetof(struct shared_resource_table, vdev);
|
||||
|
||||
resource_table.vring0.da = VRING_TX_ADDRESS;
|
||||
resource_table.vring0.align = VRING_ALIGNMENT;
|
||||
resource_table.vring0.num = VRING_NUM_BUFFS;
|
||||
resource_table.vring0.notifyid = VRING0_ID;
|
||||
|
||||
resource_table.vring1.da = VRING_RX_ADDRESS;
|
||||
resource_table.vring1.align = VRING_ALIGNMENT;
|
||||
resource_table.vring1.num = VRING_NUM_BUFFS;
|
||||
resource_table.vring1.notifyid = VRING1_ID;
|
||||
|
||||
resource_table.vdev.type = RSC_VDEV;
|
||||
resource_table.vdev.id = VIRTIO_ID_RPMSG_;
|
||||
resource_table.vdev.num_of_vrings=VRING_COUNT;
|
||||
resource_table.vdev.dfeatures = RPMSG_IPU_C0_FEATURES;
|
||||
#else
|
||||
|
||||
/* For the slave application let's wait until the resource_table is correctly initialized */
|
||||
while(resource_table.vring1.da != VRING_RX_ADDRESS)
|
||||
{
|
||||
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
(void)RPMsgRole;
|
||||
*length = sizeof(resource_table);
|
||||
*table_ptr = (void *)&resource_table;
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2026 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
/* This file populates resource table for BM remote
|
||||
* for use by the Linux Master */
|
||||
/* USER CODE END Header */
|
||||
|
||||
#ifndef RSC_TABLE_H_
|
||||
#define RSC_TABLE_H_
|
||||
|
||||
#include "openamp/open_amp.h"
|
||||
#include "openamp_conf.h"
|
||||
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN ET */
|
||||
|
||||
/* Resource table for the given remote */
|
||||
struct shared_resource_table {
|
||||
unsigned int version;
|
||||
unsigned int num;
|
||||
unsigned int reserved[2];
|
||||
unsigned int offset[NUM_RESOURCE_ENTRIES];
|
||||
/* text carveout entry */
|
||||
|
||||
/* rpmsg vdev entry */
|
||||
struct fw_rsc_vdev vdev;
|
||||
struct fw_rsc_vdev_vring vring0;
|
||||
struct fw_rsc_vdev_vring vring1;
|
||||
struct fw_rsc_trace cm_trace;
|
||||
};
|
||||
|
||||
/* USER CODE END ET */
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* USER CODE BEGIN EC */
|
||||
|
||||
/* USER CODE END EC */
|
||||
|
||||
/* Private defines -----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Private defines */
|
||||
|
||||
/* USER CODE END Private defines */
|
||||
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN EM */
|
||||
|
||||
/* USER CODE END EM */
|
||||
|
||||
/* Exported functions prototypes ---------------------------------------------*/
|
||||
/* USER CODE BEGIN EFP */
|
||||
|
||||
/* USER CODE END EFP */
|
||||
|
||||
void resource_table_init(int RPMsgRole, void **table_ptr, int *length);
|
||||
|
||||
#endif /* RSC_TABLE_H_ */
|
||||
Reference in new issue
Block a user