From cdc13cd71f118337b2bd082ecf94805148c14932 Mon Sep 17 00:00:00 2001 From: Bumsik Kim Date: Thu, 24 Oct 2019 12:00:28 +0900 Subject: [PATCH 01/24] [VirtIO] Copy files from example project --- cores/arduino/stm32/virtio/mbox_ipcc.c | 216 +++++++++++++++++++ cores/arduino/stm32/virtio/mbox_ipcc.h | 50 +++++ cores/arduino/stm32/virtio/openamp.c | 176 ++++++++++++++++ cores/arduino/stm32/virtio/openamp.h | 63 ++++++ cores/arduino/stm32/virtio/openamp_conf.h | 243 ++++++++++++++++++++++ cores/arduino/stm32/virtio/openamp_log.c | 104 +++++++++ cores/arduino/stm32/virtio/openamp_log.h | 138 ++++++++++++ cores/arduino/stm32/virtio/rsc_table.c | 176 ++++++++++++++++ cores/arduino/stm32/virtio/rsc_table.h | 48 +++++ 9 files changed, 1214 insertions(+) create mode 100644 cores/arduino/stm32/virtio/mbox_ipcc.c create mode 100644 cores/arduino/stm32/virtio/mbox_ipcc.h create mode 100644 cores/arduino/stm32/virtio/openamp.c create mode 100644 cores/arduino/stm32/virtio/openamp.h create mode 100644 cores/arduino/stm32/virtio/openamp_conf.h create mode 100644 cores/arduino/stm32/virtio/openamp_log.c create mode 100644 cores/arduino/stm32/virtio/openamp_log.h create mode 100644 cores/arduino/stm32/virtio/rsc_table.c create mode 100644 cores/arduino/stm32/virtio/rsc_table.h diff --git a/cores/arduino/stm32/virtio/mbox_ipcc.c b/cores/arduino/stm32/virtio/mbox_ipcc.c new file mode 100644 index 0000000000..1eef08c520 --- /dev/null +++ b/cores/arduino/stm32/virtio/mbox_ipcc.c @@ -0,0 +1,216 @@ +/** + ****************************************************************************** + * @file mbox_ipcc.c + * @author MCD Application Team + * @brief This file provides code for the configuration + * of the mailbox_ipcc_if.c MiddleWare. + ****************************************************************************** + * @attention + * + *

© Copyright (c) 2019 STMicroelectronics. + * All rights reserved.

+ * + * This software component is licensed by ST under BSD 3-Clause license, + * the "License"; You may not use this file except in compliance with the + * License. You may obtain a copy of the License at: + * opensource.org/licenses/BSD-3-Clause + * + ****************************************************************************** + */ +#ifdef VIRTIOCON + +/* + * Channel direction and usage: + * + * ======== <-- new msg ---=============--------<------ ======= + * || || || CHANNEL 1 || || || + * || A7 || ------->-------=============--- buf free--> || M4 || + * || || || || + * ||master|| <-- buf free---=============--------<------ ||slave|| + * || || || CHANNEL 2 || || || + * ======== ------->-------=============----new msg --> ======= + */ + +/* Includes ------------------------------------------------------------------*/ +#include "openamp/open_amp.h" +#include "stm32_def.h" +#include "openamp_conf.h" + +/* Within 'USER CODE' section, code will be kept by default at each generation */ +/* USER CODE BEGIN 0 */ + +/* USER CODE END 0 */ + +/* Private define ------------------------------------------------------------*/ +#define MASTER_CPU_ID 0 +#define REMOTE_CPU_ID 1 +#define IPCC_CPU_A7 MASTER_CPU_ID +#define IPCC_CPU_M4 REMOTE_CPU_ID + +#define RX_NO_MSG 0 +#define RX_NEW_MSG 1 +#define RX_BUF_FREE 2 + +/* Private variables ---------------------------------------------------------*/ +extern IPCC_HandleTypeDef hipcc; +int msg_received_ch1 = RX_NO_MSG; +int msg_received_ch2 = RX_NO_MSG; +uint32_t vring0_id = 0; /* used for channel 1 */ +uint32_t vring1_id = 1; /* used for channel 2 */ + + + + +IPCC_HandleTypeDef hipcc; + + + + +/* Private function prototypes -----------------------------------------------*/ +void IPCC_channel1_callback(IPCC_HandleTypeDef *hipcc, uint32_t ChannelIndex, IPCC_CHANNELDirTypeDef ChannelDir); +void IPCC_channel2_callback(IPCC_HandleTypeDef *hipcc, uint32_t ChannelIndex, IPCC_CHANNELDirTypeDef ChannelDir); + + +/** + * @brief Initialize MAILBOX with IPCC peripheral + * @param None + * @retval : Operation result + */ +int MAILBOX_Init(void) +{ + __HAL_RCC_IPCC_CLK_ENABLE(); + HAL_NVIC_SetPriority(IPCC_RX1_IRQn, IPCC_IRQ_PRIO, IPCC_IRQ_SUBPRIO); + HAL_NVIC_EnableIRQ(IPCC_RX1_IRQn); + hipcc.Instance = IPCC; + if (HAL_IPCC_Init(&hipcc) != HAL_OK) { + Error_Handler(); + } + + if (HAL_IPCC_ActivateNotification(&hipcc, IPCC_CHANNEL_1, IPCC_CHANNEL_DIR_RX, + IPCC_channel1_callback) != HAL_OK) { + OPENAMP_log_err("%s: ch_1 RX fail\n", __func__); + return -1; + } + + if (HAL_IPCC_ActivateNotification(&hipcc, IPCC_CHANNEL_2, IPCC_CHANNEL_DIR_RX, + IPCC_channel2_callback) != HAL_OK) { + OPENAMP_log_err("%s: ch_2 RX fail\n", __func__); + return -1; + } + + return 0; +} + +/** + * @brief Initialize MAILBOX with IPCC 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_ch1 == RX_BUF_FREE) { + OPENAMP_log_dbg("Running virt0 (ch_1 buf free)\r\n"); + rproc_virtio_notified(vdev, VRING0_ID); + msg_received_ch1 = RX_NO_MSG; + return 0; + } + + if (msg_received_ch2 == RX_NEW_MSG) { + OPENAMP_log_dbg("Running virt1 (ch_2 new msg)\r\n"); + rproc_virtio_notified(vdev, VRING1_ID); + msg_received_ch2 = RX_NO_MSG; + + /* The OpenAMP framework does not notify for free buf: do it here */ + rproc_virtio_notified(NULL, VRING1_ID); + return 0; + } + + return -1; +} + + +/** + * @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) +{ + uint32_t channel; + (void)priv; + + /* Called after virtqueue processing: time to inform the remote */ + if (id == VRING0_ID) { + channel = IPCC_CHANNEL_1; + OPENAMP_log_dbg("Send msg on ch_1\r\n"); + } else if (id == VRING1_ID) { + /* Note: the OpenAMP framework never notifies this */ + channel = IPCC_CHANNEL_2; + OPENAMP_log_dbg("Send 'buff free' on ch_2\r\n"); + } else { + OPENAMP_log_err("invalid vring (%d)\r\n", (int)id); + return -1; + } + + /* Check that the channel is free (otherwise wait until it is) */ + if (HAL_IPCC_GetChannelStatus(&hipcc, channel, IPCC_CHANNEL_DIR_TX) == IPCC_CHANNEL_STATUS_OCCUPIED) { + OPENAMP_log_dbg("Waiting for channel to be freed\r\n"); + while (HAL_IPCC_GetChannelStatus(&hipcc, channel, IPCC_CHANNEL_DIR_TX) == IPCC_CHANNEL_STATUS_OCCUPIED) + ; + } + + /* Inform A7 (either new message, or buf free) */ + HAL_IPCC_NotifyCPU(&hipcc, channel, IPCC_CHANNEL_DIR_TX); + + return 0; +} + +/* Private function ---------------------------------------------------------*/ +/* Callback from IPCC Interrupt Handler: Master Processor informs that there are some free buffers */ +void IPCC_channel1_callback(IPCC_HandleTypeDef *hipcc, + uint32_t ChannelIndex, IPCC_CHANNELDirTypeDef ChannelDir) +{ + if (msg_received_ch1 != RX_NO_MSG) { + OPENAMP_log_dbg("IPCC_channel1_callback: previous IRQ not treated (status = %d)\r\n", msg_received_ch1); + } + + msg_received_ch1 = RX_BUF_FREE; + + /* Inform A7 that we have received the 'buff free' msg */ + OPENAMP_log_dbg("Ack 'buff free' message on ch1\r\n"); + HAL_IPCC_NotifyCPU(hipcc, ChannelIndex, IPCC_CHANNEL_DIR_RX); +} + +/* Callback from IPCC Interrupt Handler: new message received from Master Processor */ +void IPCC_channel2_callback(IPCC_HandleTypeDef *hipcc, + uint32_t ChannelIndex, IPCC_CHANNELDirTypeDef ChannelDir) +{ + if (msg_received_ch2 != RX_NO_MSG) { + OPENAMP_log_dbg("IPCC_channel2_callback: previous IRQ not treated (status = %d)\r\n", msg_received_ch2); + } + + msg_received_ch2 = RX_NEW_MSG; + + /* Inform A7 that we have received the new msg */ + OPENAMP_log_dbg("Ack new message on ch2\r\n"); + HAL_IPCC_NotifyCPU(hipcc, ChannelIndex, IPCC_CHANNEL_DIR_RX); +} + +/** + * @brief This function handles IPCC RX1 occupied interrupt. + */ +void IPCC_RX1_IRQHandler(void) +{ + /* USER CODE BEGIN IPCC_RX1_IRQn 0 */ + log_dbg("%s: IT RX1\r\n", __func__); + /* USER CODE END IPCC_RX1_IRQn 0 */ + HAL_IPCC_RX_IRQHandler(&hipcc); + /* USER CODE BEGIN IPCC_RX1_IRQn 1 */ + + /* USER CODE END IPCC_RX1_IRQn 1 */ +} + +#endif /* VIRTIOCON */ +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/cores/arduino/stm32/virtio/mbox_ipcc.h b/cores/arduino/stm32/virtio/mbox_ipcc.h new file mode 100644 index 0000000000..be338872b2 --- /dev/null +++ b/cores/arduino/stm32/virtio/mbox_ipcc.h @@ -0,0 +1,50 @@ +/** + ****************************************************************************** + * @file mbox_ipcc.h + * @author MCD Application Team + * @brief Header for mbox_ipcc.c module + ****************************************************************************** + * @attention + * + *

© Copyright (c) 2019 STMicroelectronics. + * All rights reserved.

+ * + * This software component is licensed by ST under BSD 3-Clause license, + * the "License"; You may not use this file except in compliance with the + * License. You may obtain a copy of the License at: + * opensource.org/licenses/BSD-3-Clause + * + ****************************************************************************** + */ + +#ifndef MBOX_IPCC_H_ +#define MBOX_IPCC_H_ + +#ifdef VIRTIOCON + +/* Interrupt priority */ +#ifndef IPCC_IRQ_PRIO +#define IPCC_IRQ_PRIO 1 +#endif +#ifndef IPCC_IRQ_SUBPRIO +#define IPCC_IRQ_SUBPRIO 0 +#endif + +/* USER CODE BEGIN firstSection */ +/* can be used to modify / undefine following code or add new definitions */ +/* USER CODE END firstSection */ + +/* Includes ------------------------------------------------------------------*/ +/* Exported types ------------------------------------------------------------*/ +/* Exported constants --------------------------------------------------------*/ +/* Exported functions ------------------------------------------------------- */ +int MAILBOX_Init(void); +int MAILBOX_Notify(void *priv, uint32_t id); +int MAILBOX_Poll(struct virtio_device *vdev); + +/* USER CODE BEGIN lastSection */ +/* can be used to modify / undefine previous code or add new definitions */ +/* USER CODE END lastSection */ + +#endif /* VIRTIOCON */ +#endif /* MBOX_IPCC_H_ */ diff --git a/cores/arduino/stm32/virtio/openamp.c b/cores/arduino/stm32/virtio/openamp.c new file mode 100644 index 0000000000..65291dcdb8 --- /dev/null +++ b/cores/arduino/stm32/virtio/openamp.c @@ -0,0 +1,176 @@ +/** + ****************************************************************************** + * @file openamp.c + * @author MCD Application Team + * @brief Code for openamp applications + ****************************************************************************** + * @attention + * + *

© Copyright (c) 2019 STMicroelectronics. + * All rights reserved.

+ * + * This software component is licensed by ST under BSD 3-Clause license, + * the "License"; You may not use this file except in compliance with the + * License. You may obtain a copy of the License at: + * opensource.org/licenses/BSD-3-Clause + * + ****************************************************************************** + */ +#ifdef VIRTIOCON + +#include "openamp/open_amp.h" +#include "openamp.h" +#include "rsc_table.h" +#include "metal/sys.h" +#include "metal/device.h" +/* Private define ------------------------------------------------------------*/ + +#define SHM_DEVICE_NAME "STM32_SHM" + +/* Globals */ + +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 +}; + +static int OPENAMP_shmem_init(int RPMsgRole) +{ + int status = 0; + struct metal_device *device; + struct metal_init_params metal_params = METAL_INIT_DEFAULTS; + void *rsc_tab_addr; + int rsc_size; + + 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); + + shm_io = metal_device_io_region(device, 0); + if (shm_io == NULL) { + return -1; + } + + /* 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; + } + + metal_io_init(&device->regions[1], rsc_table, + (metal_phys_addr_t *)rsc_table, rsc_size, -1U, 0, NULL); + + rsc_io = metal_device_io_region(device, 1); + if (rsc_io == NULL) { + return -1; + } + + return 0; +} + +int OPENAMP_Init(int RPMsgRole, rpmsg_ns_bind_cb ns_bind_cb) +{ + struct fw_rsc_vdev_vring *vring_rsc; + struct virtio_device *vdev; + int status = 0; + + MAILBOX_Init(); + + /* Libmetal Initilalization */ + status = OPENAMP_shmem_init(RPMsgRole); + if (status) { + return status; + } + + 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); + 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; + } + 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; + } + + 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); + + return 0; +} + +void OPENAMP_DeInit() +{ + rpmsg_deinit_vdev(&rvdev); + + metal_finish(); +} + +void OPENAMP_init_ept(struct rpmsg_endpoint *ept) +{ + rpmsg_init_ept(ept, "", RPMSG_ADDR_ANY, RPMSG_ADDR_ANY, NULL, NULL); +} + +int OPENAMP_create_endpoint(struct rpmsg_endpoint *ept, const char *name, + uint32_t dest, rpmsg_ept_cb cb, + rpmsg_ns_unbind_cb unbind_cb) +{ + return rpmsg_create_ept(ept, &rvdev.rdev, name, RPMSG_ADDR_ANY, dest, cb, + unbind_cb); +} + +void OPENAMP_check_for_message(void) +{ + MAILBOX_Poll(rvdev.vdev); +} + +void OPENAMP_Wait_EndPointready(struct rpmsg_endpoint *rp_ept) +{ + while (!is_rpmsg_ept_ready(rp_ept)) { + MAILBOX_Poll(rvdev.vdev); + } +} + +#endif /* VIRTIOCON */ +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/cores/arduino/stm32/virtio/openamp.h b/cores/arduino/stm32/virtio/openamp.h new file mode 100644 index 0000000000..8d8ee0f604 --- /dev/null +++ b/cores/arduino/stm32/virtio/openamp.h @@ -0,0 +1,63 @@ +/** + ****************************************************************************** + * @file openamp.h + * @brief Header for openamp applications + * @author MCD Application Team + ****************************************************************************** + * @attention + * + *

© Copyright (c) 2019 STMicroelectronics. + * All rights reserved.

+ * + * This software component is licensed by ST under BSD 3-Clause license, + * the "License"; You may not use this file except in compliance with the + * License. You may obtain a copy of the License at: + * opensource.org/licenses/BSD-3-Clause + * + ****************************************************************************** + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __openamp_H +#define __openamp_H + +#ifdef VIRTIOCON + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include "openamp_conf.h" + + +#define OPENAMP_send rpmsg_send +#define OPENAMP_destroy_ept rpmsg_destroy_ept + +/* Initialize the openamp framework*/ +int 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 /* VIRTIOCON */ +#endif /*__openamp_H */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/cores/arduino/stm32/virtio/openamp_conf.h b/cores/arduino/stm32/virtio/openamp_conf.h new file mode 100644 index 0000000000..c4b5b62f57 --- /dev/null +++ b/cores/arduino/stm32/virtio/openamp_conf.h @@ -0,0 +1,243 @@ +/** + ****************************************************************************** + * @file openamp_conf.h + * @author MCD Application Team + * @brief Configuration file for OpenAMP MW + ****************************************************************************** + * @attention + * + *

© Copyright (c) 2019 STMicroelectronics. + * All rights reserved.

+ * + * This software component is licensed by ST under BSD 3-Clause license, + * the "License"; You may not use this file except in compliance with the + * License. You may obtain a copy of the License at: + * opensource.org/licenses/BSD-3-Clause + * + ****************************************************************************** + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __OPENAMP_CONF__H__ +#define __OPENAMP_CONF__H__ + +#ifdef VIRTIOCON + +#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 Maibox 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 */ + + + +/* 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) +/* + * 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 STM32MP157Cxx +#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 /* VIRTIOCON */ +#endif /* __OPENAMP_CONF__H__ */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/cores/arduino/stm32/virtio/openamp_log.c b/cores/arduino/stm32/virtio/openamp_log.c new file mode 100644 index 0000000000..e2368c2242 --- /dev/null +++ b/cores/arduino/stm32/virtio/openamp_log.c @@ -0,0 +1,104 @@ +/** + ****************************************************************************** + * @file log.c + * @author MCD Application Team + * @brief Ressource table + * + * This file provides services for logging + * + ****************************************************************************** + * + * @attention + * + *

© Copyright (c) 2019 STMicroelectronics. + * All rights reserved.

+ * + * This software component is licensed by ST under BSD 3-Clause license, + * the "License"; You may not use this file except in compliance with the + * License. You may obtain a copy of the License at: + * opensource.org/licenses/BSD-3-Clause + * + * + ****************************************************************************** + */ +#ifdef VIRTIOCON +/** @addtogroup LOG + * @{ + */ + +/** @addtogroup STM32MP1xx_log + * @{ + */ + +/** @addtogroup STM32MP1xx_Log_Private_Includes + * @{ + */ +#include "openamp_log.h" +/** + * @} + */ + +/** @addtogroup STM32MP1xx_Log_Private_TypesDefinitions + * @{ + */ + +/** + * @} + */ + +/** @addtogroup STM32MP1xx_Log_Private_Defines + * @{ + */ + +/** + * @} + */ + +#if defined (__LOG_TRACE_IO_) +char system_log_buf[SYSTEM_TRACE_BUF_SZ]; + +__weak void log_buff(int ch) +{ + /* Place your implementation of fputc here */ + /* e.g. write a character to the USART1 and Loop until the end of transmission */ + static int offset = 0; + + if (offset + 1 >= SYSTEM_TRACE_BUF_SZ) { + offset = 0; + } + + system_log_buf[offset] = ch; + system_log_buf[offset++ + 1] = '\0'; +} + +#endif + +#if defined ( __CC_ARM) || (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) +#define PUTCHAR_PROTOTYPE int stdout_putchar(int ch) +#elif __GNUC__ +/* With GCC/RAISONANCE, small log_info (option LD Linker->Libraries->Small log_info + set to 'Yes') calls __io_putchar() */ +#define PUTCHAR_PROTOTYPE int __attribute__(( weak )) __io_putchar(int ch) +#else +#define PUTCHAR_PROTOTYPE int __attribute__(( weak )) fputc(int ch, FILE *f) +#endif /* __GNUC__ */ + +#if defined (__LOG_UART_IO_) || defined (__LOG_TRACE_IO_) +PUTCHAR_PROTOTYPE { + /* Place your implementation of fputc here */ + /* e.g. write a character to the USART1 and Loop until the end of transmission */ +#if defined (__LOG_UART_IO_) + extern UART_HandleTypeDef huart; + HAL_UART_Transmit(&huart, (uint8_t *)&ch, 1, HAL_MAX_DELAY); +#endif +#if defined (__LOG_TRACE_IO_) + log_buff(ch); +#endif + return ch; +} +#else +/* No printf output */ +#endif + +#endif /* VIRTIOCON */ +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ \ No newline at end of file diff --git a/cores/arduino/stm32/virtio/openamp_log.h b/cores/arduino/stm32/virtio/openamp_log.h new file mode 100644 index 0000000000..06475dcd47 --- /dev/null +++ b/cores/arduino/stm32/virtio/openamp_log.h @@ -0,0 +1,138 @@ +/** + ****************************************************************************** + * @file log.h + * @author MCD Application Team + * @brief logging services + ****************************************************************************** + * + * @attention + * + *

© Copyright (c) 2019 STMicroelectronics. + * All rights reserved.

+ * + * This software component is licensed by ST under BSD 3-Clause license, + * the "License"; You may not use this file except in compliance with the + * License. You may obtain a copy of the License at: + * opensource.org/licenses/BSD-3-Clause + * + * + ****************************************************************************** + */ + +/** @addtogroup LOG + * @{ + */ + +/** @addtogroup stm32mp1xx_Log + * @{ + */ + +/** + * @brief Define to prevent recursive inclusion + */ +#ifndef __LOG_STM32MP1XX_H +#define __LOG_STM32MP1XX_H + +#ifdef VIRTIOCON + +#ifdef __cplusplus +extern "C" { +#endif + +/** @addtogroup STM32MP1xx_Log_Includes + * @{ + */ +#include "stm32_def.h" +/** + * @} + */ + +/** @addtogroup STM32MP1xx_Log_Exported_Constants + * @{ + */ +#if defined (__LOG_TRACE_IO_) +#define SYSTEM_TRACE_BUF_SZ 2048 +#endif + +#define LOGQUIET 0 +#define LOGERR 1 +#define LOGWARN 2 +#define LOGINFO 3 +#define LOGDBG 4 + +#ifndef LOGLEVEL +#define LOGLEVEL LOGINFO +#endif + + +/** + * @} + */ + +/** @addtogroup STM32MP1xx_Log_Exported_types + * @{ + */ +#if defined (__LOG_TRACE_IO_) +extern char system_log_buf[SYSTEM_TRACE_BUF_SZ]; /*!< buffer for debug traces */ +#endif /* __LOG_TRACE_IO_ */ +/** + * @} + */ + +/** @addtogroup STM32MP1xx_Log_Exported_Macros + * @{ + */ +#if defined (__LOG_TRACE_IO_) || defined(__LOG_UART_IO_) +#if LOGLEVEL >= LOGDBG +#define log_dbg(fmt, ...) printf("[%05ld.%03ld][DBG ]" fmt, HAL_GetTick()/1000, HAL_GetTick() % 1000, ##__VA_ARGS__) +#else +#define log_dbg(fmt, ...) +#endif +#if LOGLEVEL >= LOGINFO +#define log_info(fmt, ...) printf("[%05ld.%03ld][INFO ]" fmt, HAL_GetTick()/1000, HAL_GetTick() % 1000, ##__VA_ARGS__) +#else +#define log_info(fmt, ...) +#endif +#if LOGLEVEL >= LOGWARN +#define log_warn(fmt, ...) printf("[%05ld.%03ld][WARN ]" fmt, HAL_GetTick()/1000, HAL_GetTick() % 1000, ##__VA_ARGS__) +#else +#define log_warn(fmt, ...) +#endif +#if LOGLEVEL >= LOGERR +#define log_err(fmt, ...) printf("[%05ld.%03ld][ERR ]" fmt, HAL_GetTick()/1000, HAL_GetTick() % 1000, ##__VA_ARGS__) +#else +#define log_err(fmt, ...) +#endif +#else +#define log_dbg(fmt, ...) +#define log_info(fmt, ...) +#define log_warn(fmt, ...) +#define log_err(fmt, ...) +#endif /* __LOG_TRACE_IO_ */ +/** + * @} + */ + +/** @addtogroup STM32MP1xx_Log_Exported_Functions + * @{ + */ + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* VIRTIOCON */ +#endif /*__LOG_STM32MP1XX_H */ + +/** + * @} + */ + +/** + * @} + */ +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/cores/arduino/stm32/virtio/rsc_table.c b/cores/arduino/stm32/virtio/rsc_table.c new file mode 100644 index 0000000000..ac8d7a2af0 --- /dev/null +++ b/cores/arduino/stm32/virtio/rsc_table.c @@ -0,0 +1,176 @@ +/** + ****************************************************************************** + * @file rsc_table.c + * @author MCD Application Team + * @brief Ressource 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) 2019 STMicroelectronics. + * All rights reserved.

+ * + * This software component is licensed by ST under BSD 3-Clause license, + * the "License"; You may not use this file except in compliance with the + * License. You may obtain a copy of the License at: + * opensource.org/licenses/BSD-3-Clause + * + ****************************************************************************** + */ +#ifdef VIRTIOCON +/** @addtogroup RSC_TABLE + * @{ + */ + +/** @addtogroup resource_table + * @{ + */ + +/** @addtogroup resource_table_Private_Includes + * @{ + */ + +#if defined(__ICCARM__) || defined (__CC_ARM) +#include /* 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 (STM32MP157Cxx) +#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 (STM32MP157Cxx) + +/* 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 (STM32MP157Cxx) +.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 (STM32MP157Cxx) +#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; +} + +#endif /* VIRTIOCON */ diff --git a/cores/arduino/stm32/virtio/rsc_table.h b/cores/arduino/stm32/virtio/rsc_table.h new file mode 100644 index 0000000000..ccb9260b9f --- /dev/null +++ b/cores/arduino/stm32/virtio/rsc_table.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2019 STMicroelectronics. + * All rights reserved. + * + * This software component is licensed by ST under BSD 3-Clause license, + * the "License"; You may not use this file except in compliance with the + * License. You may obtain a copy of the License at: + * opensource.org/licenses/BSD-3-Clause + * + */ + +/* This file populates resource table for BM remote + * for use by the Linux Master */ + +#ifndef RSC_TABLE_H_ +#define RSC_TABLE_H_ + +#ifdef VIRTIOCON + +#include "openamp/open_amp.h" +#include "openamp_conf.h" + +/* Place resource table in special ELF section */ +//#define __section_t(S) __attribute__((__section__(#S))) +//#define __resource __section_t(.resource_table) + + + + +/* 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; +}; + +void resource_table_init(int RPMsgRole, void **table_ptr, int *length); + +#endif /* VIRTIOCON */ +#endif /* RSC_TABLE_H_ */ From ace855897c7aaad5eef6de4c17425ac015eaeed4 Mon Sep 17 00:00:00 2001 From: Bumsik Kim Date: Thu, 24 Oct 2019 12:02:44 +0900 Subject: [PATCH 02/24] [VirtIO] Link OpenAMP middleware files to the core --- cores/arduino/stm32/virtio/libmetal/device.c | 5 +++++ .../stm32/virtio/libmetal/generic/condition.c | 5 +++++ .../stm32/virtio/libmetal/generic/cortexm/sys.c | 5 +++++ .../stm32/virtio/libmetal/generic/generic_device.c | 5 +++++ .../stm32/virtio/libmetal/generic/generic_init.c | 5 +++++ .../stm32/virtio/libmetal/generic/generic_io.c | 5 +++++ .../stm32/virtio/libmetal/generic/generic_shmem.c | 5 +++++ cores/arduino/stm32/virtio/libmetal/generic/time.c | 5 +++++ cores/arduino/stm32/virtio/libmetal/init.c | 5 +++++ cores/arduino/stm32/virtio/libmetal/io.c | 5 +++++ cores/arduino/stm32/virtio/libmetal/log.c | 5 +++++ cores/arduino/stm32/virtio/libmetal/shmem.c | 5 +++++ .../virtio/open-amp/remoteproc/remoteproc_virtio.c | 5 +++++ cores/arduino/stm32/virtio/open-amp/rpmsg/rpmsg.c | 5 +++++ .../stm32/virtio/open-amp/rpmsg/rpmsg_virtio.c | 5 +++++ cores/arduino/stm32/virtio/virt_uart.c | 13 +++++++++++++ cores/arduino/stm32/virtio/virtio/virtio.c | 5 +++++ cores/arduino/stm32/virtio/virtio/virtqueue.c | 5 +++++ 18 files changed, 98 insertions(+) create mode 100644 cores/arduino/stm32/virtio/libmetal/device.c create mode 100644 cores/arduino/stm32/virtio/libmetal/generic/condition.c create mode 100644 cores/arduino/stm32/virtio/libmetal/generic/cortexm/sys.c create mode 100644 cores/arduino/stm32/virtio/libmetal/generic/generic_device.c create mode 100644 cores/arduino/stm32/virtio/libmetal/generic/generic_init.c create mode 100644 cores/arduino/stm32/virtio/libmetal/generic/generic_io.c create mode 100644 cores/arduino/stm32/virtio/libmetal/generic/generic_shmem.c create mode 100644 cores/arduino/stm32/virtio/libmetal/generic/time.c create mode 100644 cores/arduino/stm32/virtio/libmetal/init.c create mode 100644 cores/arduino/stm32/virtio/libmetal/io.c create mode 100644 cores/arduino/stm32/virtio/libmetal/log.c create mode 100644 cores/arduino/stm32/virtio/libmetal/shmem.c create mode 100644 cores/arduino/stm32/virtio/open-amp/remoteproc/remoteproc_virtio.c create mode 100644 cores/arduino/stm32/virtio/open-amp/rpmsg/rpmsg.c create mode 100644 cores/arduino/stm32/virtio/open-amp/rpmsg/rpmsg_virtio.c create mode 100644 cores/arduino/stm32/virtio/virt_uart.c create mode 100644 cores/arduino/stm32/virtio/virtio/virtio.c create mode 100644 cores/arduino/stm32/virtio/virtio/virtqueue.c diff --git a/cores/arduino/stm32/virtio/libmetal/device.c b/cores/arduino/stm32/virtio/libmetal/device.c new file mode 100644 index 0000000000..ad62849d0f --- /dev/null +++ b/cores/arduino/stm32/virtio/libmetal/device.c @@ -0,0 +1,5 @@ +#ifdef VIRTIOCON + +#include "libmetal/lib/device.c" + +#endif /* VIRTIOCON */ diff --git a/cores/arduino/stm32/virtio/libmetal/generic/condition.c b/cores/arduino/stm32/virtio/libmetal/generic/condition.c new file mode 100644 index 0000000000..a8f7a7427d --- /dev/null +++ b/cores/arduino/stm32/virtio/libmetal/generic/condition.c @@ -0,0 +1,5 @@ +#ifdef VIRTIOCON + +#include "libmetal/lib/system/generic/condition.c" + +#endif /* VIRTIOCON */ diff --git a/cores/arduino/stm32/virtio/libmetal/generic/cortexm/sys.c b/cores/arduino/stm32/virtio/libmetal/generic/cortexm/sys.c new file mode 100644 index 0000000000..83f98dd29f --- /dev/null +++ b/cores/arduino/stm32/virtio/libmetal/generic/cortexm/sys.c @@ -0,0 +1,5 @@ +#ifdef VIRTIOCON + +#include "libmetal/lib/system/generic/cortexm/sys.c" + +#endif /* VIRTIOCON */ diff --git a/cores/arduino/stm32/virtio/libmetal/generic/generic_device.c b/cores/arduino/stm32/virtio/libmetal/generic/generic_device.c new file mode 100644 index 0000000000..85a97eef94 --- /dev/null +++ b/cores/arduino/stm32/virtio/libmetal/generic/generic_device.c @@ -0,0 +1,5 @@ +#ifdef VIRTIOCON + +#include "libmetal/lib/system/generic/generic_device.c" + +#endif /* VIRTIOCON */ diff --git a/cores/arduino/stm32/virtio/libmetal/generic/generic_init.c b/cores/arduino/stm32/virtio/libmetal/generic/generic_init.c new file mode 100644 index 0000000000..abdbe5cf12 --- /dev/null +++ b/cores/arduino/stm32/virtio/libmetal/generic/generic_init.c @@ -0,0 +1,5 @@ +#ifdef VIRTIOCON + +#include "libmetal/lib/system/generic/generic_init.c" + +#endif /* VIRTIOCON */ diff --git a/cores/arduino/stm32/virtio/libmetal/generic/generic_io.c b/cores/arduino/stm32/virtio/libmetal/generic/generic_io.c new file mode 100644 index 0000000000..d1fcb36feb --- /dev/null +++ b/cores/arduino/stm32/virtio/libmetal/generic/generic_io.c @@ -0,0 +1,5 @@ +#ifdef VIRTIOCON + +#include "libmetal/lib/system/generic/generic_io.c" + +#endif /* VIRTIOCON */ diff --git a/cores/arduino/stm32/virtio/libmetal/generic/generic_shmem.c b/cores/arduino/stm32/virtio/libmetal/generic/generic_shmem.c new file mode 100644 index 0000000000..75be24b343 --- /dev/null +++ b/cores/arduino/stm32/virtio/libmetal/generic/generic_shmem.c @@ -0,0 +1,5 @@ +#ifdef VIRTIOCON + +#include "libmetal/lib/system/generic/generic_shmem.c" + +#endif /* VIRTIOCON */ diff --git a/cores/arduino/stm32/virtio/libmetal/generic/time.c b/cores/arduino/stm32/virtio/libmetal/generic/time.c new file mode 100644 index 0000000000..917e7b88bc --- /dev/null +++ b/cores/arduino/stm32/virtio/libmetal/generic/time.c @@ -0,0 +1,5 @@ +#ifdef VIRTIOCON + +#include "libmetal/lib/system/generic/time.c" + +#endif /* VIRTIOCON */ diff --git a/cores/arduino/stm32/virtio/libmetal/init.c b/cores/arduino/stm32/virtio/libmetal/init.c new file mode 100644 index 0000000000..e7ddd67304 --- /dev/null +++ b/cores/arduino/stm32/virtio/libmetal/init.c @@ -0,0 +1,5 @@ +#ifdef VIRTIOCON + +#include "libmetal/lib/init.c" + +#endif /* VIRTIOCON */ diff --git a/cores/arduino/stm32/virtio/libmetal/io.c b/cores/arduino/stm32/virtio/libmetal/io.c new file mode 100644 index 0000000000..902aca060e --- /dev/null +++ b/cores/arduino/stm32/virtio/libmetal/io.c @@ -0,0 +1,5 @@ +#ifdef VIRTIOCON + +#include "libmetal/lib/io.c" + +#endif /* VIRTIOCON */ diff --git a/cores/arduino/stm32/virtio/libmetal/log.c b/cores/arduino/stm32/virtio/libmetal/log.c new file mode 100644 index 0000000000..03eff42dc6 --- /dev/null +++ b/cores/arduino/stm32/virtio/libmetal/log.c @@ -0,0 +1,5 @@ +#ifdef VIRTIOCON + +#include "libmetal/lib/log.c" + +#endif /* VIRTIOCON */ diff --git a/cores/arduino/stm32/virtio/libmetal/shmem.c b/cores/arduino/stm32/virtio/libmetal/shmem.c new file mode 100644 index 0000000000..83b2e508a1 --- /dev/null +++ b/cores/arduino/stm32/virtio/libmetal/shmem.c @@ -0,0 +1,5 @@ +#ifdef VIRTIOCON + +#include "libmetal/lib/shmem.c" + +#endif /* VIRTIOCON */ diff --git a/cores/arduino/stm32/virtio/open-amp/remoteproc/remoteproc_virtio.c b/cores/arduino/stm32/virtio/open-amp/remoteproc/remoteproc_virtio.c new file mode 100644 index 0000000000..af4d8a2341 --- /dev/null +++ b/cores/arduino/stm32/virtio/open-amp/remoteproc/remoteproc_virtio.c @@ -0,0 +1,5 @@ +#ifdef VIRTIOCON + +#include "open-amp/lib/remoteproc/remoteproc_virtio.c" + +#endif /* VIRTIOCON */ diff --git a/cores/arduino/stm32/virtio/open-amp/rpmsg/rpmsg.c b/cores/arduino/stm32/virtio/open-amp/rpmsg/rpmsg.c new file mode 100644 index 0000000000..bf650fffdc --- /dev/null +++ b/cores/arduino/stm32/virtio/open-amp/rpmsg/rpmsg.c @@ -0,0 +1,5 @@ +#ifdef VIRTIOCON + +#include "open-amp/lib/rpmsg/rpmsg.c" + +#endif /* VIRTIOCON */ diff --git a/cores/arduino/stm32/virtio/open-amp/rpmsg/rpmsg_virtio.c b/cores/arduino/stm32/virtio/open-amp/rpmsg/rpmsg_virtio.c new file mode 100644 index 0000000000..086354d102 --- /dev/null +++ b/cores/arduino/stm32/virtio/open-amp/rpmsg/rpmsg_virtio.c @@ -0,0 +1,5 @@ +#ifdef VIRTIOCON + +#include "open-amp/lib/rpmsg/rpmsg_virtio.c" + +#endif /* VIRTIOCON */ diff --git a/cores/arduino/stm32/virtio/virt_uart.c b/cores/arduino/stm32/virtio/virt_uart.c new file mode 100644 index 0000000000..d6b918ed79 --- /dev/null +++ b/cores/arduino/stm32/virtio/virt_uart.c @@ -0,0 +1,13 @@ +#ifdef VIRTIOCON + + +// #include "openamp/open_amp.h" + +/* Configurable parameters */ +#ifndef RPMSG_BUFFER_SIZE +#define RPMSG_BUFFER_SIZE (512) +#endif + +#include "virtual_driver/virt_uart.c" + +#endif /* VIRTIOCON */ diff --git a/cores/arduino/stm32/virtio/virtio/virtio.c b/cores/arduino/stm32/virtio/virtio/virtio.c new file mode 100644 index 0000000000..0efadcfea5 --- /dev/null +++ b/cores/arduino/stm32/virtio/virtio/virtio.c @@ -0,0 +1,5 @@ +#ifdef VIRTIOCON + +#include "open-amp/lib/virtio/virtio.c" + +#endif /* VIRTIOCON */ diff --git a/cores/arduino/stm32/virtio/virtio/virtqueue.c b/cores/arduino/stm32/virtio/virtio/virtqueue.c new file mode 100644 index 0000000000..62b71b43ac --- /dev/null +++ b/cores/arduino/stm32/virtio/virtio/virtqueue.c @@ -0,0 +1,5 @@ +#ifdef VIRTIOCON + +#include "open-amp/lib/virtio/virtqueue.c" + +#endif /* VIRTIOCON */ From 7df4edfe34c7d503399ff467ebfdd52a7c352e50 Mon Sep 17 00:00:00 2001 From: Bumsik Kim Date: Thu, 7 Nov 2019 11:31:59 +0900 Subject: [PATCH 03/24] [VirtIO] Add ringbuffer --- cores/arduino/stm32/virtio/ringbuffer.c | 126 ++++++++++++++++++++++++ cores/arduino/stm32/virtio/ringbuffer.h | 59 +++++++++++ 2 files changed, 185 insertions(+) create mode 100644 cores/arduino/stm32/virtio/ringbuffer.c create mode 100644 cores/arduino/stm32/virtio/ringbuffer.h diff --git a/cores/arduino/stm32/virtio/ringbuffer.c b/cores/arduino/stm32/virtio/ringbuffer.c new file mode 100644 index 0000000000..1fb1fe9aa5 --- /dev/null +++ b/cores/arduino/stm32/virtio/ringbuffer.c @@ -0,0 +1,126 @@ +/** + * MIT License: + * Copyright (c) 2019 Bumsik kim + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#ifdef VIRTIOCON + +#include "ringbuffer.h" +#include +#include "wiring.h" + +#define BUFFER_END (VIRTIO_RINGBUFFER_SIZE - 1) + +static uint16_t read_tmp(ringbuffer_t *ring, uint8_t *dst, uint16_t size); +static void read_commit(ringbuffer_t *ring); +static void read_rollback(ringbuffer_t *ring); + +void ringbuffer_init(ringbuffer_t *ring) +{ + ring->write = 0; + ring->read = 0; + ring->read_tmp = 0; +} + +uint16_t ringbuffer_read_available(ringbuffer_t *ring) +{ + // This will make the function safe when write openrations are done in interrupts + volatile uint16_t write = ring->write; + + if (write < ring->read) { + return (BUFFER_END - ring->read) + (write + 1); + } + return write - ring->read; +} + +static uint16_t read_tmp(ringbuffer_t *ring, uint8_t *dst, uint16_t size) +{ + // This will make the function safe when write openrations are done in interrupts + volatile uint16_t write = ring->write; + uint16_t end = (write >= ring->read_tmp) ? write : BUFFER_END + 1; + + size = min(end - ring->read_tmp, size); + memcpy(dst, ring->buffer + ring->read_tmp, size); + ring->read_tmp += size; + if (ring->read_tmp > BUFFER_END) { + ring->read_tmp = 0; + } + return size; +} + +static void read_commit(ringbuffer_t *ring) +{ + ring->read = ring->read_tmp; +} + +static void read_rollback(ringbuffer_t *ring) +{ + ring->read_tmp = ring->read; +} + +uint16_t ringbuffer_read(ringbuffer_t *ring, uint8_t *dst, uint16_t size) +{ + uint16_t recv_size = read_tmp(ring, dst, size); + read_commit(ring); + return recv_size; +} + +/** + * WARNING: The size of read cannot be larger than ringbuffer_read_available(). + */ +uint16_t ringbuffer_peek(ringbuffer_t *ring, uint8_t *dst, uint16_t size) +{ + size = min(size, ringbuffer_read_available(ring)); + uint16_t recv_size = 0; + while (recv_size < size) { + recv_size += read_tmp(ring, dst + recv_size, size - recv_size); + } + read_rollback(ring); + return recv_size; +} + +uint16_t ringbuffer_write_available(ringbuffer_t *ring) +{ + // This will make the function safe when read openrations are done in interrupts + volatile uint16_t read = ring->read; + + if (ring->write < read) { + return (read - 1) - ring->write; + } + return read + (BUFFER_END - ring->write); +} + +uint16_t ringbuffer_write(ringbuffer_t *ring, uint8_t *src, uint16_t size) +{ + // This will make the function safe when read openrations are done in a interrupt + volatile uint16_t read = ring->read; + uint16_t end = (ring->write < read) ? read - 1 + : (read == 0) ? BUFFER_END : BUFFER_END + 1; + + size = min(end - ring->write, size); + memcpy(ring->buffer + ring->write, src, size); + ring->write += size; + if (ring->write > BUFFER_END) { + ring->write = 0; + } + return size; +} + +#endif /* VIRTIOCON */ diff --git a/cores/arduino/stm32/virtio/ringbuffer.h b/cores/arduino/stm32/virtio/ringbuffer.h new file mode 100644 index 0000000000..662c5b596e --- /dev/null +++ b/cores/arduino/stm32/virtio/ringbuffer.h @@ -0,0 +1,59 @@ +/** + * MIT License: + * Copyright (c) 2019 Bumsik kim + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef __VIRTIO_RINGBUFFER_H +#define __VIRTIO_RINGBUFFER_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef RPMSG_BUFFER_SIZE +#error "Define RPMSG_BUFFER_SIZE, or include relevant headers." +#endif + +#define VIRTIO_RINGBUFFER_SIZE (RPMSG_BUFFER_SIZE * 2) + +typedef struct { + uint8_t buffer[VIRTIO_RINGBUFFER_SIZE]; + volatile uint16_t write; + volatile uint16_t read; + volatile uint16_t read_tmp; +} ringbuffer_t; + +void ringbuffer_init(ringbuffer_t *ring); + +uint16_t ringbuffer_read_available(ringbuffer_t *ring); +uint16_t ringbuffer_read(ringbuffer_t *ring, uint8_t *dst, uint16_t size); +uint16_t ringbuffer_peek(ringbuffer_t *ring, uint8_t *dst, uint16_t size); + +uint16_t ringbuffer_write_available(ringbuffer_t *ring); +uint16_t ringbuffer_write(ringbuffer_t *ring, uint8_t *src, uint16_t size); + +#ifdef __cplusplus +} +#endif + +#endif // __VIRTIO_RINGBUFFER_H From 654090a721f96025be9b2a18174be8c37d6d592b Mon Sep 17 00:00:00 2001 From: Bumsik Kim Date: Thu, 24 Oct 2019 12:18:24 +0900 Subject: [PATCH 04/24] [VirtIO] Add first VirtIO --- cores/arduino/VirtIOSerial.cpp | 164 +++++++++++++++++++++++++ cores/arduino/VirtIOSerial.h | 57 +++++++++ cores/arduino/WSerial.cpp | 5 + cores/arduino/WSerial.h | 17 +++ cores/arduino/stm32/virtio/mbox_ipcc.c | 75 +++-------- cores/arduino/stm32/virtio/mbox_ipcc.h | 2 +- cores/arduino/stm32/virtio/openamp.c | 17 +-- cores/arduino/stm32/virtio/openamp.h | 5 +- cores/arduino/stm32/virtio/virt_uart.c | 2 +- 9 files changed, 271 insertions(+), 73 deletions(-) create mode 100644 cores/arduino/VirtIOSerial.cpp create mode 100644 cores/arduino/VirtIOSerial.h diff --git a/cores/arduino/VirtIOSerial.cpp b/cores/arduino/VirtIOSerial.cpp new file mode 100644 index 0000000000..f5ea0cd531 --- /dev/null +++ b/cores/arduino/VirtIOSerial.cpp @@ -0,0 +1,164 @@ +/** + * MIT License: + * Copyright (c) 2019 Bumsik kim + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#if defined (VIRTIOCON) + +#include "openamp.h" +#include "openamp_log.h" +#include "wiring.h" +#include "ringbuffer.h" + +VirtIOSerial SerialVirtIO; +void serialEventVirtIO() __attribute__((weak)); + +static VIRT_UART_HandleTypeDef huart; +static bool initialized = false; +static ringbuffer_t ring; + +void rxCallback(VIRT_UART_HandleTypeDef *huart); + +void VirtIOSerial::begin(void) +{ + ringbuffer_init(&ring); + if (initialized) { + return; + } + OPENAMP_Init(NULL); + if (VIRT_UART_Init(&huart) != VIRT_UART_OK) { + // log_err("VIRT_UART_Init UART0 failed.\r\n"); + Error_Handler(); + } + /*Need to register callback for message reception by channels*/ + if (VIRT_UART_RegisterCallback(&huart, VIRT_UART_RXCPLT_CB_ID, rxCallback) != VIRT_UART_OK) { + Error_Handler(); + } + initialized = true; +} + +void VirtIOSerial::begin(uint32_t /* baud_count */) +{ + // uart config is ignored in USB-CDC + begin(); +} + +void VirtIOSerial::begin(uint32_t /* baud_count */, uint8_t /* config */) +{ + // uart config is ignored in USB-CDC + begin(); +} + +void VirtIOSerial::end() +{ + OPENAMP_DeInit(); + ringbuffer_init(&ring); + initialized = false; +} + +int VirtIOSerial::available(void) +{ + return ringbuffer_read_available(&ring); +} + +int VirtIOSerial::availableForWrite() +{ + // Just return max length of VIRT_UART_Transmit() can transmit. + // See VIRT_UART_Transmit(). + return RPMSG_BUFFER_SIZE - 16; +} + +int VirtIOSerial::peek(void) +{ + if (ringbuffer_read_available(&ring) > 0) { + uint8_t tmp; + ringbuffer_peek(&ring, &tmp, 1); + return tmp; + } else { + return -1; + } +} + +int VirtIOSerial::read(void) +{ + if (available() > 0) { + char ch; + readBytes(&ch, 1); + return ch; + } else { + return -1; + } +} + +size_t VirtIOSerial::readBytes(char *buffer, size_t length) +{ + const size_t size = length; + _startMillis = millis(); + while (length > 0 && (millis() - _startMillis < _timeout)) { + uint16_t prev_write_available = ringbuffer_write_available(&ring); + length -= ringbuffer_read(&ring, reinterpret_cast(buffer), length); + if (prev_write_available < RPMSG_BUFFER_SIZE + && ringbuffer_write_available(&ring) >= RPMSG_BUFFER_SIZE) { + MAILBOX_Notify_Rx_Buf_Free(); + } + } + return size - length; +} + +size_t VirtIOSerial::write(uint8_t ch) +{ + // Just write single-byte buffer. + return write(&ch, 1); +} + +// Warning: Currently VirtIOSerial implementation is synchronous, blocking +// until all bytes are sent. +size_t VirtIOSerial::write(const uint8_t *buffer, size_t size) +{ + if (VIRT_UART_Transmit(&huart, const_cast(buffer), size) == VIRT_UART_ERROR) { + return 0; + } + return size; +} + +void VirtIOSerial::flush(void) +{ + // write() is blocked until all bytes are sent. So flush() doesn't need to do + // anything. See rpmsg_send(). + return; +} + +/* USER CODE BEGIN 4 */ +void rxCallback(VIRT_UART_HandleTypeDef *huart) +{ + log_info("Msg received on VIRTUAL UART0 channel: %s \n\r", (char *) huart->pRxBuffPtr); + + /* copy received msg in a variable to sent it back to master processor in main infinite loop*/ + size_t size = min(huart->RxXferSize, ringbuffer_write_available(&ring)); + while (size > 0) { + size -= ringbuffer_write(&ring, huart->pRxBuffPtr, size); + } + if (ringbuffer_write_available(&ring) >= RPMSG_BUFFER_SIZE) { + MAILBOX_Notify_Rx_Buf_Free(); + } +} + +#endif /* VIRTIOCON */ diff --git a/cores/arduino/VirtIOSerial.h b/cores/arduino/VirtIOSerial.h new file mode 100644 index 0000000000..82c344f219 --- /dev/null +++ b/cores/arduino/VirtIOSerial.h @@ -0,0 +1,57 @@ +/** + * MIT License: + * Copyright (c) 2019 Bumsik kim + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef _VIRTIOSERIAL_H_ +#define _VIRTIOSERIAL_H_ + +#if defined (VIRTIOCON) +#include "Stream.h" + +//================================================================================ +// Serial over CDC +class VirtIOSerial : public Stream { + public: + void begin(void); + void begin(uint32_t); + void begin(uint32_t, uint8_t); + void end(void); + + virtual int available(void); + virtual int availableForWrite(void); + virtual int peek(void); + virtual int read(void); + virtual size_t readBytes(char *buffer, size_t length); // read chars from stream into buffer + virtual size_t write(uint8_t); + virtual size_t write(const uint8_t *buffer, size_t size); + virtual void flush(void); + using Print::write; // pull in write(str) from Print + operator bool(void) + { + return true; + } +}; + +extern VirtIOSerial SerialVirtIO; + +#endif /* VIRTIOCON */ +#endif /* _VIRTIOSERIAL_H_ */ diff --git a/cores/arduino/WSerial.cpp b/cores/arduino/WSerial.cpp index 7fba4df0d1..db176db53d 100644 --- a/cores/arduino/WSerial.cpp +++ b/cores/arduino/WSerial.cpp @@ -62,5 +62,10 @@ void serialEventRun(void) serialEventUSB(); } #endif +#if defined(HAVE_SERIALVIRTIO) + if (serialEventVirtIO && SerialVirtIO.available()) { + serialEventVirtIO(); + } +#endif } diff --git a/cores/arduino/WSerial.h b/cores/arduino/WSerial.h index 753a38c25b..1bceffd4cb 100644 --- a/cores/arduino/WSerial.h +++ b/cores/arduino/WSerial.h @@ -4,6 +4,7 @@ #include "variant.h" #include "HardwareSerial.h" #include "USBSerial.h" +#include "VirtIOSerial.h" #if defined (USBCON) && defined(USBD_USE_CDC) #ifndef DISABLE_GENERIC_SERIALUSB @@ -21,6 +22,22 @@ extern void serialEventUSB(void) __attribute__((weak)); #endif /* USBCON && USBD_USE_CDC */ +#if defined(VIRTIOCON) +#ifndef DISABLE_GENERIC_SERIALVIRTIO +#define ENABLE_SERIALVIRTIO +#if !defined(Serial) +#define Serial SerialVirtIO +#define serialEvent serialEventVirtIO +#endif +#endif + +#if defined(ENABLE_SERIALVIRTIO) +#define HAVE_SERIALVIRTIO +#endif + +extern void serialEventVirtIO(void) __attribute__((weak)); +#endif /* VIRTIOCON */ + #if defined(HAL_UART_MODULE_ENABLED) && !defined(HAL_UART_MODULE_ONLY) #if !defined(HWSERIAL_NONE) && defined(SERIAL_UART_INSTANCE) #if SERIAL_UART_INSTANCE == 0 diff --git a/cores/arduino/stm32/virtio/mbox_ipcc.c b/cores/arduino/stm32/virtio/mbox_ipcc.c index 1eef08c520..b27980de2f 100644 --- a/cores/arduino/stm32/virtio/mbox_ipcc.c +++ b/cores/arduino/stm32/virtio/mbox_ipcc.c @@ -52,16 +52,8 @@ #define RX_BUF_FREE 2 /* Private variables ---------------------------------------------------------*/ -extern IPCC_HandleTypeDef hipcc; -int msg_received_ch1 = RX_NO_MSG; -int msg_received_ch2 = RX_NO_MSG; -uint32_t vring0_id = 0; /* used for channel 1 */ -uint32_t vring1_id = 1; /* used for channel 2 */ - - - - IPCC_HandleTypeDef hipcc; +extern struct rpmsg_virtio_device rvdev; @@ -70,7 +62,6 @@ IPCC_HandleTypeDef hipcc; void IPCC_channel1_callback(IPCC_HandleTypeDef *hipcc, uint32_t ChannelIndex, IPCC_CHANNELDirTypeDef ChannelDir); void IPCC_channel2_callback(IPCC_HandleTypeDef *hipcc, uint32_t ChannelIndex, IPCC_CHANNELDirTypeDef ChannelDir); - /** * @brief Initialize MAILBOX with IPCC peripheral * @param None @@ -101,36 +92,6 @@ int MAILBOX_Init(void) return 0; } -/** - * @brief Initialize MAILBOX with IPCC 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_ch1 == RX_BUF_FREE) { - OPENAMP_log_dbg("Running virt0 (ch_1 buf free)\r\n"); - rproc_virtio_notified(vdev, VRING0_ID); - msg_received_ch1 = RX_NO_MSG; - return 0; - } - - if (msg_received_ch2 == RX_NEW_MSG) { - OPENAMP_log_dbg("Running virt1 (ch_2 new msg)\r\n"); - rproc_virtio_notified(vdev, VRING1_ID); - msg_received_ch2 = RX_NO_MSG; - - /* The OpenAMP framework does not notify for free buf: do it here */ - rproc_virtio_notified(NULL, VRING1_ID); - return 0; - } - - return -1; -} - - /** * @brief Callback function called by OpenAMP MW to notify message processing * @param VRING id @@ -149,6 +110,7 @@ int MAILBOX_Notify(void *priv, uint32_t id) /* Note: the OpenAMP framework never notifies this */ channel = IPCC_CHANNEL_2; OPENAMP_log_dbg("Send 'buff free' on ch_2\r\n"); + return -1; } else { OPENAMP_log_err("invalid vring (%d)\r\n", (int)id); return -1; @@ -167,35 +129,38 @@ int MAILBOX_Notify(void *priv, uint32_t id) return 0; } +/** + * @brief Notify Rx buffer is free to Master + */ +void MAILBOX_Notify_Rx_Buf_Free() +{ + HAL_IPCC_NotifyCPU(&hipcc, IPCC_CHANNEL_2, IPCC_CHANNEL_DIR_RX); +} + /* Private function ---------------------------------------------------------*/ /* Callback from IPCC Interrupt Handler: Master Processor informs that there are some free buffers */ void IPCC_channel1_callback(IPCC_HandleTypeDef *hipcc, uint32_t ChannelIndex, IPCC_CHANNELDirTypeDef ChannelDir) { - if (msg_received_ch1 != RX_NO_MSG) { - OPENAMP_log_dbg("IPCC_channel1_callback: previous IRQ not treated (status = %d)\r\n", msg_received_ch1); - } - - msg_received_ch1 = RX_BUF_FREE; - /* Inform A7 that we have received the 'buff free' msg */ OPENAMP_log_dbg("Ack 'buff free' message on ch1\r\n"); HAL_IPCC_NotifyCPU(hipcc, ChannelIndex, IPCC_CHANNEL_DIR_RX); + rproc_virtio_notified(rvdev.vdev, VRING0_ID); } /* Callback from IPCC Interrupt Handler: new message received from Master Processor */ void IPCC_channel2_callback(IPCC_HandleTypeDef *hipcc, uint32_t ChannelIndex, IPCC_CHANNELDirTypeDef ChannelDir) { - if (msg_received_ch2 != RX_NO_MSG) { - OPENAMP_log_dbg("IPCC_channel2_callback: previous IRQ not treated (status = %d)\r\n", msg_received_ch2); - } - - msg_received_ch2 = RX_NEW_MSG; - - /* Inform A7 that we have received the new msg */ - OPENAMP_log_dbg("Ack new message on ch2\r\n"); - HAL_IPCC_NotifyCPU(hipcc, ChannelIndex, IPCC_CHANNEL_DIR_RX); + (void) hipcc; + (void) ChannelIndex; + (void) ChannelDir; + /* Don't inform A7 here, do it when the buffer has more than RPMSG_BUFFER_SIZE. + * See MAILBOX_Notify_Rx_Buf_Free() and VirIOSerial.cpp. + */ + rproc_virtio_notified(rvdev.vdev, VRING1_ID); + /* The OpenAMP framework does not notify for free buf: do it here */ + rproc_virtio_notified(NULL, VRING1_ID); } /** diff --git a/cores/arduino/stm32/virtio/mbox_ipcc.h b/cores/arduino/stm32/virtio/mbox_ipcc.h index be338872b2..341c808d11 100644 --- a/cores/arduino/stm32/virtio/mbox_ipcc.h +++ b/cores/arduino/stm32/virtio/mbox_ipcc.h @@ -40,7 +40,7 @@ /* Exported functions ------------------------------------------------------- */ int MAILBOX_Init(void); int MAILBOX_Notify(void *priv, uint32_t id); -int MAILBOX_Poll(struct virtio_device *vdev); +void MAILBOX_Notify_Rx_Buf_Free(void); /* USER CODE BEGIN lastSection */ /* can be used to modify / undefine previous code or add new definitions */ diff --git a/cores/arduino/stm32/virtio/openamp.c b/cores/arduino/stm32/virtio/openamp.c index 65291dcdb8..9ca211389a 100644 --- a/cores/arduino/stm32/virtio/openamp.c +++ b/cores/arduino/stm32/virtio/openamp.c @@ -33,7 +33,7 @@ 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; +struct rpmsg_virtio_device rvdev; static metal_phys_addr_t shm_physmap; @@ -97,7 +97,7 @@ static int OPENAMP_shmem_init(int RPMsgRole) return 0; } -int OPENAMP_Init(int RPMsgRole, rpmsg_ns_bind_cb ns_bind_cb) +int OPENAMP_Init(rpmsg_ns_bind_cb ns_bind_cb) { struct fw_rsc_vdev_vring *vring_rsc; struct virtio_device *vdev; @@ -106,12 +106,12 @@ int OPENAMP_Init(int RPMsgRole, rpmsg_ns_bind_cb ns_bind_cb) MAILBOX_Init(); /* Libmetal Initilalization */ - status = OPENAMP_shmem_init(RPMsgRole); + status = OPENAMP_shmem_init(RPMSG_REMOTE); if (status) { return status; } - vdev = rproc_virtio_create_vdev(RPMsgRole, VDEV_ID, &rsc_table->vdev, + vdev = rproc_virtio_create_vdev(RPMSG_REMOTE, VDEV_ID, &rsc_table->vdev, rsc_io, NULL, MAILBOX_Notify, NULL); if (vdev == NULL) { return -1; @@ -160,16 +160,9 @@ int OPENAMP_create_endpoint(struct rpmsg_endpoint *ept, const char *name, unbind_cb); } -void OPENAMP_check_for_message(void) -{ - MAILBOX_Poll(rvdev.vdev); -} - void OPENAMP_Wait_EndPointready(struct rpmsg_endpoint *rp_ept) { - while (!is_rpmsg_ept_ready(rp_ept)) { - MAILBOX_Poll(rvdev.vdev); - } + while (!is_rpmsg_ept_ready(rp_ept)); } #endif /* VIRTIOCON */ diff --git a/cores/arduino/stm32/virtio/openamp.h b/cores/arduino/stm32/virtio/openamp.h index 8d8ee0f604..8304e17443 100644 --- a/cores/arduino/stm32/virtio/openamp.h +++ b/cores/arduino/stm32/virtio/openamp.h @@ -35,7 +35,7 @@ extern "C" { #define OPENAMP_destroy_ept rpmsg_destroy_ept /* Initialize the openamp framework*/ -int OPENAMP_Init(int RPMsgRole, rpmsg_ns_bind_cb ns_bind_cb); +int OPENAMP_Init(rpmsg_ns_bind_cb ns_bind_cb); /* Deinitialize the openamp framework*/ void OPENAMP_DeInit(void); @@ -48,9 +48,6 @@ 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); diff --git a/cores/arduino/stm32/virtio/virt_uart.c b/cores/arduino/stm32/virtio/virt_uart.c index d6b918ed79..eeaa2ffeef 100644 --- a/cores/arduino/stm32/virtio/virt_uart.c +++ b/cores/arduino/stm32/virtio/virt_uart.c @@ -5,7 +5,7 @@ /* Configurable parameters */ #ifndef RPMSG_BUFFER_SIZE -#define RPMSG_BUFFER_SIZE (512) +#define RPMSG_BUFFER_SIZE (512) #endif #include "virtual_driver/virt_uart.c" From d1dbe6c4f690a9ad5f352bf0a4feb5b5ea065d7e Mon Sep 17 00:00:00 2001 From: Bumsik Kim Date: Thu, 7 Nov 2019 23:54:15 +0900 Subject: [PATCH 05/24] [VirtIO] Add virtio_config.h to avoid #define RPMSG_XX_XX location problem --- cores/arduino/stm32/virtio/mbox_ipcc.c | 1 + .../virtio/open-amp/remoteproc/remoteproc_virtio.c | 1 + cores/arduino/stm32/virtio/open-amp/rpmsg/rpmsg.c | 1 + .../arduino/stm32/virtio/open-amp/rpmsg/rpmsg_virtio.c | 1 + cores/arduino/stm32/virtio/openamp.c | 1 + cores/arduino/stm32/virtio/openamp_conf.h | 2 ++ cores/arduino/stm32/virtio/ringbuffer.c | 1 + cores/arduino/stm32/virtio/ringbuffer.h | 4 ---- cores/arduino/stm32/virtio/rsc_table.h | 1 + cores/arduino/stm32/virtio/virt_uart.c | 9 +-------- cores/arduino/stm32/virtio/virtio/virtio.c | 1 + cores/arduino/stm32/virtio/virtio/virtqueue.c | 1 + cores/arduino/stm32/virtio/virtio_config.h | 10 ++++++++++ 13 files changed, 22 insertions(+), 12 deletions(-) create mode 100644 cores/arduino/stm32/virtio/virtio_config.h diff --git a/cores/arduino/stm32/virtio/mbox_ipcc.c b/cores/arduino/stm32/virtio/mbox_ipcc.c index b27980de2f..69d020dd5d 100644 --- a/cores/arduino/stm32/virtio/mbox_ipcc.c +++ b/cores/arduino/stm32/virtio/mbox_ipcc.c @@ -32,6 +32,7 @@ */ /* Includes ------------------------------------------------------------------*/ +#include "virtio_config.h" #include "openamp/open_amp.h" #include "stm32_def.h" #include "openamp_conf.h" diff --git a/cores/arduino/stm32/virtio/open-amp/remoteproc/remoteproc_virtio.c b/cores/arduino/stm32/virtio/open-amp/remoteproc/remoteproc_virtio.c index af4d8a2341..c829226b93 100644 --- a/cores/arduino/stm32/virtio/open-amp/remoteproc/remoteproc_virtio.c +++ b/cores/arduino/stm32/virtio/open-amp/remoteproc/remoteproc_virtio.c @@ -1,5 +1,6 @@ #ifdef VIRTIOCON +#include "virtio_config.h" #include "open-amp/lib/remoteproc/remoteproc_virtio.c" #endif /* VIRTIOCON */ diff --git a/cores/arduino/stm32/virtio/open-amp/rpmsg/rpmsg.c b/cores/arduino/stm32/virtio/open-amp/rpmsg/rpmsg.c index bf650fffdc..11b66787ff 100644 --- a/cores/arduino/stm32/virtio/open-amp/rpmsg/rpmsg.c +++ b/cores/arduino/stm32/virtio/open-amp/rpmsg/rpmsg.c @@ -1,5 +1,6 @@ #ifdef VIRTIOCON +#include "virtio_config.h" #include "open-amp/lib/rpmsg/rpmsg.c" #endif /* VIRTIOCON */ diff --git a/cores/arduino/stm32/virtio/open-amp/rpmsg/rpmsg_virtio.c b/cores/arduino/stm32/virtio/open-amp/rpmsg/rpmsg_virtio.c index 086354d102..8a89668a05 100644 --- a/cores/arduino/stm32/virtio/open-amp/rpmsg/rpmsg_virtio.c +++ b/cores/arduino/stm32/virtio/open-amp/rpmsg/rpmsg_virtio.c @@ -1,5 +1,6 @@ #ifdef VIRTIOCON +#include "virtio_config.h" #include "open-amp/lib/rpmsg/rpmsg_virtio.c" #endif /* VIRTIOCON */ diff --git a/cores/arduino/stm32/virtio/openamp.c b/cores/arduino/stm32/virtio/openamp.c index 9ca211389a..bf114a5c67 100644 --- a/cores/arduino/stm32/virtio/openamp.c +++ b/cores/arduino/stm32/virtio/openamp.c @@ -18,6 +18,7 @@ */ #ifdef VIRTIOCON +#include "virtio_config.h" #include "openamp/open_amp.h" #include "openamp.h" #include "rsc_table.h" diff --git a/cores/arduino/stm32/virtio/openamp_conf.h b/cores/arduino/stm32/virtio/openamp_conf.h index c4b5b62f57..ef28b5f1c9 100644 --- a/cores/arduino/stm32/virtio/openamp_conf.h +++ b/cores/arduino/stm32/virtio/openamp_conf.h @@ -23,6 +23,8 @@ #ifdef VIRTIOCON +#include "virtio_config.h" + #ifdef __cplusplus extern "C" { #endif diff --git a/cores/arduino/stm32/virtio/ringbuffer.c b/cores/arduino/stm32/virtio/ringbuffer.c index 1fb1fe9aa5..eff4df7f52 100644 --- a/cores/arduino/stm32/virtio/ringbuffer.c +++ b/cores/arduino/stm32/virtio/ringbuffer.c @@ -22,6 +22,7 @@ */ #ifdef VIRTIOCON +#include "virtio_config.h" #include "ringbuffer.h" #include #include "wiring.h" diff --git a/cores/arduino/stm32/virtio/ringbuffer.h b/cores/arduino/stm32/virtio/ringbuffer.h index 662c5b596e..49cae2551e 100644 --- a/cores/arduino/stm32/virtio/ringbuffer.h +++ b/cores/arduino/stm32/virtio/ringbuffer.h @@ -30,10 +30,6 @@ extern "C" { #endif -#ifndef RPMSG_BUFFER_SIZE -#error "Define RPMSG_BUFFER_SIZE, or include relevant headers." -#endif - #define VIRTIO_RINGBUFFER_SIZE (RPMSG_BUFFER_SIZE * 2) typedef struct { diff --git a/cores/arduino/stm32/virtio/rsc_table.h b/cores/arduino/stm32/virtio/rsc_table.h index ccb9260b9f..60dd5e4edb 100644 --- a/cores/arduino/stm32/virtio/rsc_table.h +++ b/cores/arduino/stm32/virtio/rsc_table.h @@ -17,6 +17,7 @@ #ifdef VIRTIOCON +#include "virtio_config.h" #include "openamp/open_amp.h" #include "openamp_conf.h" diff --git a/cores/arduino/stm32/virtio/virt_uart.c b/cores/arduino/stm32/virtio/virt_uart.c index eeaa2ffeef..3b86748c66 100644 --- a/cores/arduino/stm32/virtio/virt_uart.c +++ b/cores/arduino/stm32/virtio/virt_uart.c @@ -1,13 +1,6 @@ #ifdef VIRTIOCON - -// #include "openamp/open_amp.h" - -/* Configurable parameters */ -#ifndef RPMSG_BUFFER_SIZE -#define RPMSG_BUFFER_SIZE (512) -#endif - +#include "virtio_config.h" #include "virtual_driver/virt_uart.c" #endif /* VIRTIOCON */ diff --git a/cores/arduino/stm32/virtio/virtio/virtio.c b/cores/arduino/stm32/virtio/virtio/virtio.c index 0efadcfea5..2e7ec33eae 100644 --- a/cores/arduino/stm32/virtio/virtio/virtio.c +++ b/cores/arduino/stm32/virtio/virtio/virtio.c @@ -1,5 +1,6 @@ #ifdef VIRTIOCON +#include "virtio_config.h" #include "open-amp/lib/virtio/virtio.c" #endif /* VIRTIOCON */ diff --git a/cores/arduino/stm32/virtio/virtio/virtqueue.c b/cores/arduino/stm32/virtio/virtio/virtqueue.c index 62b71b43ac..150a7d06d3 100644 --- a/cores/arduino/stm32/virtio/virtio/virtqueue.c +++ b/cores/arduino/stm32/virtio/virtio/virtqueue.c @@ -1,5 +1,6 @@ #ifdef VIRTIOCON +#include "virtio_config.h" #include "open-amp/lib/virtio/virtqueue.c" #endif /* VIRTIOCON */ diff --git a/cores/arduino/stm32/virtio/virtio_config.h b/cores/arduino/stm32/virtio/virtio_config.h new file mode 100644 index 0000000000..4271d559cc --- /dev/null +++ b/cores/arduino/stm32/virtio/virtio_config.h @@ -0,0 +1,10 @@ +#ifndef __VIRTIO_CONFIG_H +#define __VIRTIO_CONFIG_H + +#ifdef RPMSG_BUFFER_SIZE +#error "RPMSG_BUFFER_SIZE is already defined" +#else +#define RPMSG_BUFFER_SIZE (512) +#endif + +#endif // __VIRTIO_CONFIG_H From dda61c33a619e6380cdaa52d287a6b8ad9918cba Mon Sep 17 00:00:00 2001 From: Bumsik Kim Date: Fri, 8 Nov 2019 09:50:10 +0900 Subject: [PATCH 06/24] [VirtIO] Enhance IPCC & RPMsg model diagram description --- cores/arduino/stm32/virtio/mbox_ipcc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cores/arduino/stm32/virtio/mbox_ipcc.c b/cores/arduino/stm32/virtio/mbox_ipcc.c index 69d020dd5d..0e036bb76d 100644 --- a/cores/arduino/stm32/virtio/mbox_ipcc.c +++ b/cores/arduino/stm32/virtio/mbox_ipcc.c @@ -21,13 +21,13 @@ /* * Channel direction and usage: - * + * virtio_rpmsg_bus.c rpmsg_virtio.c * ======== <-- new msg ---=============--------<------ ======= - * || || || CHANNEL 1 || || || + * || || rvq (rx) || CHANNEL 1 || svq (tx_vq) || || * || A7 || ------->-------=============--- buf free--> || M4 || * || || || || * ||master|| <-- buf free---=============--------<------ ||slave|| - * || || || CHANNEL 2 || || || + * || || svq (tx) || CHANNEL 2 || rvq (rx_vq) || || * ======== ------->-------=============----new msg --> ======= */ From c6dbd3dc7830e47a467ec50873a18d86b9481c43 Mon Sep 17 00:00:00 2001 From: Bumsik Kim Date: Fri, 8 Nov 2019 15:51:26 +0900 Subject: [PATCH 07/24] [VirtIO] Disable support for dynamic creating endpoint OpenAMP_Init accepts rpmsg_ns_bind_cb, however, this Arduino Core will not allow dynamic endpoint (VirtSerial) creation, but only support dynamic binding endpoints that are already created by VirIOSerial.begin(). Therefore just remove such parameters seems more appropriate. Reference: https://github.com/OpenAMP/open-amp/blob/7b32a1b72cdc8866eea0803f683c35af01814a56/docs/rpmsg-design.md Signed-off-by: Bumsik Kim --- cores/arduino/VirtIOSerial.cpp | 2 +- cores/arduino/stm32/virtio/openamp.c | 4 ++-- cores/arduino/stm32/virtio/openamp.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cores/arduino/VirtIOSerial.cpp b/cores/arduino/VirtIOSerial.cpp index f5ea0cd531..63e4019a45 100644 --- a/cores/arduino/VirtIOSerial.cpp +++ b/cores/arduino/VirtIOSerial.cpp @@ -43,7 +43,7 @@ void VirtIOSerial::begin(void) if (initialized) { return; } - OPENAMP_Init(NULL); + OPENAMP_Init(); if (VIRT_UART_Init(&huart) != VIRT_UART_OK) { // log_err("VIRT_UART_Init UART0 failed.\r\n"); Error_Handler(); diff --git a/cores/arduino/stm32/virtio/openamp.c b/cores/arduino/stm32/virtio/openamp.c index bf114a5c67..2b291122b3 100644 --- a/cores/arduino/stm32/virtio/openamp.c +++ b/cores/arduino/stm32/virtio/openamp.c @@ -98,7 +98,7 @@ static int OPENAMP_shmem_init(int RPMsgRole) return 0; } -int OPENAMP_Init(rpmsg_ns_bind_cb ns_bind_cb) +int OPENAMP_Init() { struct fw_rsc_vdev_vring *vring_rsc; struct virtio_device *vdev; @@ -136,7 +136,7 @@ int OPENAMP_Init(rpmsg_ns_bind_cb ns_bind_cb) 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); + rpmsg_init_vdev(&rvdev, vdev, NULL, shm_io, &shpool); return 0; } diff --git a/cores/arduino/stm32/virtio/openamp.h b/cores/arduino/stm32/virtio/openamp.h index 8304e17443..b42e895e3c 100644 --- a/cores/arduino/stm32/virtio/openamp.h +++ b/cores/arduino/stm32/virtio/openamp.h @@ -35,7 +35,7 @@ extern "C" { #define OPENAMP_destroy_ept rpmsg_destroy_ept /* Initialize the openamp framework*/ -int OPENAMP_Init(rpmsg_ns_bind_cb ns_bind_cb); +int OPENAMP_Init(void); /* Deinitialize the openamp framework*/ void OPENAMP_DeInit(void); From 53bc04033e2ed8077a3e81a378ebd6cf718681bc Mon Sep 17 00:00:00 2001 From: Bumsik Kim Date: Thu, 24 Oct 2019 12:18:55 +0900 Subject: [PATCH 08/24] [VirtIO] Add VirtIO build config in boards.txt and platform.txt --- boards.txt | 10 +++++++++- platform.txt | 7 ++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/boards.txt b/boards.txt index c0f7f9f0ee..5063e90471 100644 --- a/boards.txt +++ b/boards.txt @@ -2,6 +2,7 @@ menu.pnum=Board part number +menu.virtio=Virtual serial support menu.xserial=U(S)ART support menu.usb=USB support (if available) menu.xusb=USB speed (if available) @@ -675,7 +676,7 @@ STM32MP1.build.mcu=cortex-m4 STM32MP1.build.flags.fp=-mfpu=fpv4-sp-d16 -mfloat-abi=hard STM32MP1.build.series=STM32MP1xx STM32MP1.build.cmsis_lib_gcc=arm_cortexM4l_math -STM32MP1.build.extra_flags=-DCORE_CM4 -DUSE_FULL_LL_DRIVER -D{build.product_line} {build.xSerial} +STM32MP1.build.extra_flags=-DCORE_CM4 -DUSE_FULL_LL_DRIVER -D{build.product_line} {build.enable_virtio} {build.xSerial} # STM32MP157A-DK1 board STM32MP1.menu.pnum.STM32MP157A_DK1=STM32MP157A-DK1 @@ -1601,6 +1602,13 @@ Eval.menu.xserial.none.build.xSerial=-DHAL_UART_MODULE_ENABLED -DHWSERIAL_NONE Eval.menu.xserial.disabled=Disabled (no Serial support) Eval.menu.xserial.disabled.build.xSerial= +STM32MP1.menu.virtio.generic=/dev/ttyRPMSG0 => 'Serial' supersede U(S)ART +STM32MP1.menu.virtio.generic.build.enable_virtio={build.virtio_flags} +STM32MP1.menu.virtio.none=/dev/ttyRPMSG0 => SerialVirtIO +STM32MP1.menu.virtio.none.build.enable_virtio={build.virtio_flags} -DDISABLE_GENERIC_SERIALVIRTIO +STM32MP1.menu.virtio.disable=Disabled (no /dev/ttyRPMSG0 available) +STM32MP1.menu.virtio.disable.build.enable_virtio= + STM32MP1.menu.xserial.generic=UART only (generic 'Serial') STM32MP1.menu.xserial.generic.build.xSerial=-DHAL_UART_MODULE_ENABLED STM32MP1.menu.xserial.none=UART only (no generic 'Serial') diff --git a/platform.txt b/platform.txt index a8fbebd2fd..f4c9bd4db0 100644 --- a/platform.txt +++ b/platform.txt @@ -9,7 +9,7 @@ version=1.0.0 # STM compile variables # ---------------------- -compiler.stm.extra_include="-I{build.source.path}" "-I{build.core.path}/avr" "-I{build.core.path}/stm32" "-I{build.core.path}/stm32/LL" "-I{build.core.path}/stm32/usb" "-I{build.core.path}/stm32/usb/hid" "-I{build.core.path}/stm32/usb/cdc" "-I{build.system.path}/Drivers/{build.series}_HAL_Driver/Inc" "-I{build.system.path}/Drivers/{build.series}_HAL_Driver/Src" "-I{build.system.path}/{build.series}" "-I{build.system.path}/Middlewares/ST/STM32_USB_Device_Library/Core/Inc" "-I{build.system.path}/Middlewares/ST/STM32_USB_Device_Library/Core/Src" +compiler.stm.extra_include="-I{build.source.path}" "-I{build.core.path}/avr" "-I{build.core.path}/stm32" "-I{build.core.path}/stm32/LL" "-I{build.core.path}/stm32/usb" "-I{build.core.path}/stm32/virtio" "-I{build.core.path}/stm32/usb/hid" "-I{build.core.path}/stm32/usb/cdc" "-I{build.system.path}/Drivers/{build.series}_HAL_Driver/Inc" "-I{build.system.path}/Drivers/{build.series}_HAL_Driver/Src" "-I{build.system.path}/{build.series}" "-I{build.system.path}/Middlewares/ST/STM32_USB_Device_Library/Core/Inc" "-I{build.system.path}/Middlewares/ST/STM32_USB_Device_Library/Core/Src" {build.virtio_extra_include} compiler.warning_flags=-w compiler.warning_flags.none=-w @@ -75,6 +75,10 @@ build.usb_flags=-DUSBCON {build.usb_speed} -DUSBD_VID={build.vid} '-DUSB_MANUFAC # numeric vendor ID if available or by board's specific value. build.usb_manufacturer="Unknown" +# VirtIO RPMsg Serial Flags +build.virtio_flags=-DVIRTIOCON -DHAL_IPCC_MODULE_ENABLED -DNO_ATOMIC_64_SUPPORT -DMETAL_INTERNAL -DMETAL_MAX_DEVICE_REGIONS=2 -DVIRTIO_SLAVE_ONLY -D__LOG_TRACE_IO_ +build.virtio_extra_include="-I{build.system.path}/Middlewares/OpenAMP" "-I{build.system.path}/Middlewares/OpenAMP/open-amp/lib/include" "-I{build.system.path}/Middlewares/OpenAMP/libmetal/lib/include" "-I{build.system.path}/Middlewares/OpenAMP/virtual_driver" + # Build information's build.info.flags=-D{build.series} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} -DBOARD_NAME="{build.board}" @@ -82,6 +86,7 @@ build.info.flags=-D{build.series} -DARDUINO={runtime.ide.version} -DARDUINO_{bui build.xSerial=-DHAL_UART_MODULE_ENABLED build.enable_usb= build.usb_speed= +build.enable_virtio= build.startup_file= build.flags.fp= build.flags.optimize=-Os From 24adcb07559a1e5e2cbd91e271d8f7c6916ea17f Mon Sep 17 00:00:00 2001 From: Bumsik Kim Date: Sat, 9 Nov 2019 02:09:42 +0900 Subject: [PATCH 09/24] [VirtIO] Fix STM32MP157Cxx specific #define --- cores/arduino/stm32/virtio/rsc_table.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cores/arduino/stm32/virtio/rsc_table.c b/cores/arduino/stm32/virtio/rsc_table.c index ac8d7a2af0..1d5ec3da29 100644 --- a/cores/arduino/stm32/virtio/rsc_table.c +++ b/cores/arduino/stm32/virtio/rsc_table.c @@ -61,7 +61,7 @@ #define __resource __section_t(.resource_table) #endif -#if defined (STM32MP157Cxx) +#if defined (STM32MP1xx) #ifdef VIRTIO_MASTER_ONLY #define CONST #else @@ -82,7 +82,7 @@ extern char system_log_buf[]; #endif #if defined(__GNUC__) -#if !defined (__CC_ARM) && !defined (STM32MP157Cxx) +#if !defined (__CC_ARM) && !defined (STM32MP1xx) /* 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) @@ -95,7 +95,7 @@ CONST struct shared_resource_table __resource __attribute__((used)) resource_tab __root CONST struct shared_resource_table resource_table @ ".resource_table" = { #endif -#if defined(__ICCARM__) || defined (__CC_ARM) || defined (STM32MP157Cxx) +#if defined(__ICCARM__) || defined (__CC_ARM) || defined (STM32MP1xx) .version = 1, #if defined (__LOG_TRACE_IO_) .num = 2, @@ -130,7 +130,7 @@ __root CONST struct shared_resource_table resource_table @ ".resource_table" = { void resource_table_init(int RPMsgRole, void **table_ptr, int *length) { -#if !defined (STM32MP157Cxx) +#if !defined (STM32MP1xx) #if defined (__GNUC__) && ! defined (__CC_ARM) #ifdef VIRTIO_MASTER_ONLY From 5ae00d160d5cfd5b94bd698cc990197a2b40146a Mon Sep 17 00:00:00 2001 From: Bumsik Kim Date: Sat, 9 Nov 2019 03:02:22 +0900 Subject: [PATCH 10/24] [STM32MP157_DK] Add SERIAL_PORT_LINUXBRIDGE as SerialVirtIO --- variants/STM32MP157_DK/variant.h | 1 + 1 file changed, 1 insertion(+) diff --git a/variants/STM32MP157_DK/variant.h b/variants/STM32MP157_DK/variant.h index 8acc778e07..d94a9c0936 100644 --- a/variants/STM32MP157_DK/variant.h +++ b/variants/STM32MP157_DK/variant.h @@ -178,6 +178,7 @@ extern "C" { // pins are NOT connected to anything by default. #define SERIAL_PORT_MONITOR Serial #define SERIAL_PORT_HARDWARE Serial +#define SERIAL_PORT_LINUXBRIDGE SerialVirtIO #endif #endif /* _VARIANT_ARDUINO_STM32_ */ From bc426929124af94ee2527619f24876aace5e9b31 Mon Sep 17 00:00:00 2001 From: Bumsik Kim Date: Sat, 9 Nov 2019 10:22:34 +0900 Subject: [PATCH 11/24] [VirtIO] Workaround for Arduino can't send data first There is a RPMsg's limitation by design that RPMsg remote (Arduino) cannot send any data until the master (Linux) send any data first. This is a design decision that service announcement receiver has to send a first message to bind their addresses. https://github.com/OpenAMP/open-amp/issues/182 As workaround, run_arduino.sh script will send "DUMMY" data right after the Arduino firmware loaded. The Arduino should discard the first message. --- cores/arduino/VirtIOSerial.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/cores/arduino/VirtIOSerial.cpp b/cores/arduino/VirtIOSerial.cpp index 63e4019a45..8f6af291dd 100644 --- a/cores/arduino/VirtIOSerial.cpp +++ b/cores/arduino/VirtIOSerial.cpp @@ -33,6 +33,7 @@ void serialEventVirtIO() __attribute__((weak)); static VIRT_UART_HandleTypeDef huart; static bool initialized = false; +static bool first_message_discarded = false; static ringbuffer_t ring; void rxCallback(VIRT_UART_HandleTypeDef *huart); @@ -53,6 +54,7 @@ void VirtIOSerial::begin(void) Error_Handler(); } initialized = true; + first_message_discarded = false; } void VirtIOSerial::begin(uint32_t /* baud_count */) @@ -150,6 +152,15 @@ void VirtIOSerial::flush(void) void rxCallback(VIRT_UART_HandleTypeDef *huart) { log_info("Msg received on VIRTUAL UART0 channel: %s \n\r", (char *) huart->pRxBuffPtr); + // Linux host must send a dummy data first to finish initialization of rpmsg + // on the coprocessor side. This message should be discarded. + // run_arduino_gen.sh script will send dummy data: "DUMMY". + // See: https://github.com/OpenAMP/open-amp/issues/182 + // See: run_arduino_gen.sh + if (!first_message_discarded) { + huart->RxXferSize = 0; + first_message_discarded = true; + } /* copy received msg in a variable to sent it back to master processor in main infinite loop*/ size_t size = min(huart->RxXferSize, ringbuffer_write_available(&ring)); From 7a40195f20750542cd3f2dfae67da477fc7ebc3c Mon Sep 17 00:00:00 2001 From: Alexandre Bourdiol Date: Tue, 28 Jan 2020 15:41:07 +0100 Subject: [PATCH 12/24] [VirtIO] README: add serial-related run_arduino.sh commands --- variants/STM32MP157_DK/README.md | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/variants/STM32MP157_DK/README.md b/variants/STM32MP157_DK/README.md index ac6c453883..4812b0dfd0 100644 --- a/variants/STM32MP157_DK/README.md +++ b/variants/STM32MP157_DK/README.md @@ -36,7 +36,9 @@ After Verify and Upload, you will see a message similar to the following in Ardu * Linux/macOS: - `/tmp/arduino_build_668148/run_arduino_Blink.sh` + Usage: sh run_arduino.sh [start|stop|restart] + sh run_arduino.sh [install|uninstall] + sh run_arduino.sh [monitor|send-msg|send-file|minicom] In this example, the user **must** upload `/run_arduino_.sh` file manually. Uploading instruction is described later in the [Uploading](#Uploading) section. @@ -63,6 +65,18 @@ After uploading the user can use `sh run_arduino_.sh start` in the sh run_arduino_.sh uninstall Uninstall the autostart service. + sh run_arduino_.sh monitor + Monitor data received from the coprocessor via the virtual serial. + + sh run_arduino_.sh send-msg + Send a message to the coprocessor via the virtual serial. + + sh run_arduino_.sh send-file + Send a file content to the coprocessor via the virtual serial. + + sh run_arduino_.sh minicom + Launch minicom interactive serial communication program. + sh run_arduino_.sh stop Stop the coprocessor. From a4f0b66fc8feec6e64b5656d9d0324733b78ff2d Mon Sep 17 00:00:00 2001 From: Bumsik Kim Date: Mon, 11 Nov 2019 10:10:35 +0900 Subject: [PATCH 13/24] !fixup: ringbuffer.h: name collides with RingBuffer.h in Windows --- cores/arduino/VirtIOSerial.cpp | 26 +++++++-------- .../virtio/{ringbuffer.c => virtio_buffer.c} | 32 +++++++++---------- .../virtio/{ringbuffer.h => virtio_buffer.h} | 24 +++++++------- 3 files changed, 41 insertions(+), 41 deletions(-) rename cores/arduino/stm32/virtio/{ringbuffer.c => virtio_buffer.c} (75%) rename cores/arduino/stm32/virtio/{ringbuffer.h => virtio_buffer.h} (68%) diff --git a/cores/arduino/VirtIOSerial.cpp b/cores/arduino/VirtIOSerial.cpp index 8f6af291dd..4881b86eef 100644 --- a/cores/arduino/VirtIOSerial.cpp +++ b/cores/arduino/VirtIOSerial.cpp @@ -26,7 +26,7 @@ #include "openamp.h" #include "openamp_log.h" #include "wiring.h" -#include "ringbuffer.h" +#include "virtio_buffer.h" VirtIOSerial SerialVirtIO; void serialEventVirtIO() __attribute__((weak)); @@ -34,13 +34,13 @@ void serialEventVirtIO() __attribute__((weak)); static VIRT_UART_HandleTypeDef huart; static bool initialized = false; static bool first_message_discarded = false; -static ringbuffer_t ring; +static virtio_buffer_t ring; void rxCallback(VIRT_UART_HandleTypeDef *huart); void VirtIOSerial::begin(void) { - ringbuffer_init(&ring); + virtio_buffer_init(&ring); if (initialized) { return; } @@ -72,13 +72,13 @@ void VirtIOSerial::begin(uint32_t /* baud_count */, uint8_t /* config */) void VirtIOSerial::end() { OPENAMP_DeInit(); - ringbuffer_init(&ring); + virtio_buffer_init(&ring); initialized = false; } int VirtIOSerial::available(void) { - return ringbuffer_read_available(&ring); + return virtio_buffer_read_available(&ring); } int VirtIOSerial::availableForWrite() @@ -90,9 +90,9 @@ int VirtIOSerial::availableForWrite() int VirtIOSerial::peek(void) { - if (ringbuffer_read_available(&ring) > 0) { + if (virtio_buffer_read_available(&ring) > 0) { uint8_t tmp; - ringbuffer_peek(&ring, &tmp, 1); + virtio_buffer_peek(&ring, &tmp, 1); return tmp; } else { return -1; @@ -115,10 +115,10 @@ size_t VirtIOSerial::readBytes(char *buffer, size_t length) const size_t size = length; _startMillis = millis(); while (length > 0 && (millis() - _startMillis < _timeout)) { - uint16_t prev_write_available = ringbuffer_write_available(&ring); - length -= ringbuffer_read(&ring, reinterpret_cast(buffer), length); + uint16_t prev_write_available = virtio_buffer_write_available(&ring); + length -= virtio_buffer_read(&ring, reinterpret_cast(buffer), length); if (prev_write_available < RPMSG_BUFFER_SIZE - && ringbuffer_write_available(&ring) >= RPMSG_BUFFER_SIZE) { + && virtio_buffer_write_available(&ring) >= RPMSG_BUFFER_SIZE) { MAILBOX_Notify_Rx_Buf_Free(); } } @@ -163,11 +163,11 @@ void rxCallback(VIRT_UART_HandleTypeDef *huart) } /* copy received msg in a variable to sent it back to master processor in main infinite loop*/ - size_t size = min(huart->RxXferSize, ringbuffer_write_available(&ring)); + size_t size = min(huart->RxXferSize, virtio_buffer_write_available(&ring)); while (size > 0) { - size -= ringbuffer_write(&ring, huart->pRxBuffPtr, size); + size -= virtio_buffer_write(&ring, huart->pRxBuffPtr, size); } - if (ringbuffer_write_available(&ring) >= RPMSG_BUFFER_SIZE) { + if (virtio_buffer_write_available(&ring) >= RPMSG_BUFFER_SIZE) { MAILBOX_Notify_Rx_Buf_Free(); } } diff --git a/cores/arduino/stm32/virtio/ringbuffer.c b/cores/arduino/stm32/virtio/virtio_buffer.c similarity index 75% rename from cores/arduino/stm32/virtio/ringbuffer.c rename to cores/arduino/stm32/virtio/virtio_buffer.c index eff4df7f52..a8f35b267b 100644 --- a/cores/arduino/stm32/virtio/ringbuffer.c +++ b/cores/arduino/stm32/virtio/virtio_buffer.c @@ -23,24 +23,24 @@ #ifdef VIRTIOCON #include "virtio_config.h" -#include "ringbuffer.h" +#include "virtio_buffer.h" #include #include "wiring.h" -#define BUFFER_END (VIRTIO_RINGBUFFER_SIZE - 1) +#define BUFFER_END (VIRTIO_BUFFER_SIZE - 1) -static uint16_t read_tmp(ringbuffer_t *ring, uint8_t *dst, uint16_t size); -static void read_commit(ringbuffer_t *ring); -static void read_rollback(ringbuffer_t *ring); +static uint16_t read_tmp(virtio_buffer_t *ring, uint8_t *dst, uint16_t size); +static void read_commit(virtio_buffer_t *ring); +static void read_rollback(virtio_buffer_t *ring); -void ringbuffer_init(ringbuffer_t *ring) +void virtio_buffer_init(virtio_buffer_t *ring) { ring->write = 0; ring->read = 0; ring->read_tmp = 0; } -uint16_t ringbuffer_read_available(ringbuffer_t *ring) +uint16_t virtio_buffer_read_available(virtio_buffer_t *ring) { // This will make the function safe when write openrations are done in interrupts volatile uint16_t write = ring->write; @@ -51,7 +51,7 @@ uint16_t ringbuffer_read_available(ringbuffer_t *ring) return write - ring->read; } -static uint16_t read_tmp(ringbuffer_t *ring, uint8_t *dst, uint16_t size) +static uint16_t read_tmp(virtio_buffer_t *ring, uint8_t *dst, uint16_t size) { // This will make the function safe when write openrations are done in interrupts volatile uint16_t write = ring->write; @@ -66,17 +66,17 @@ static uint16_t read_tmp(ringbuffer_t *ring, uint8_t *dst, uint16_t size) return size; } -static void read_commit(ringbuffer_t *ring) +static void read_commit(virtio_buffer_t *ring) { ring->read = ring->read_tmp; } -static void read_rollback(ringbuffer_t *ring) +static void read_rollback(virtio_buffer_t *ring) { ring->read_tmp = ring->read; } -uint16_t ringbuffer_read(ringbuffer_t *ring, uint8_t *dst, uint16_t size) +uint16_t virtio_buffer_read(virtio_buffer_t *ring, uint8_t *dst, uint16_t size) { uint16_t recv_size = read_tmp(ring, dst, size); read_commit(ring); @@ -84,11 +84,11 @@ uint16_t ringbuffer_read(ringbuffer_t *ring, uint8_t *dst, uint16_t size) } /** - * WARNING: The size of read cannot be larger than ringbuffer_read_available(). + * WARNING: The size of read cannot be larger than virtio_buffer_read_available(). */ -uint16_t ringbuffer_peek(ringbuffer_t *ring, uint8_t *dst, uint16_t size) +uint16_t virtio_buffer_peek(virtio_buffer_t *ring, uint8_t *dst, uint16_t size) { - size = min(size, ringbuffer_read_available(ring)); + size = min(size, virtio_buffer_read_available(ring)); uint16_t recv_size = 0; while (recv_size < size) { recv_size += read_tmp(ring, dst + recv_size, size - recv_size); @@ -97,7 +97,7 @@ uint16_t ringbuffer_peek(ringbuffer_t *ring, uint8_t *dst, uint16_t size) return recv_size; } -uint16_t ringbuffer_write_available(ringbuffer_t *ring) +uint16_t virtio_buffer_write_available(virtio_buffer_t *ring) { // This will make the function safe when read openrations are done in interrupts volatile uint16_t read = ring->read; @@ -108,7 +108,7 @@ uint16_t ringbuffer_write_available(ringbuffer_t *ring) return read + (BUFFER_END - ring->write); } -uint16_t ringbuffer_write(ringbuffer_t *ring, uint8_t *src, uint16_t size) +uint16_t virtio_buffer_write(virtio_buffer_t *ring, uint8_t *src, uint16_t size) { // This will make the function safe when read openrations are done in a interrupt volatile uint16_t read = ring->read; diff --git a/cores/arduino/stm32/virtio/ringbuffer.h b/cores/arduino/stm32/virtio/virtio_buffer.h similarity index 68% rename from cores/arduino/stm32/virtio/ringbuffer.h rename to cores/arduino/stm32/virtio/virtio_buffer.h index 49cae2551e..df5b3f96fb 100644 --- a/cores/arduino/stm32/virtio/ringbuffer.h +++ b/cores/arduino/stm32/virtio/virtio_buffer.h @@ -21,8 +21,8 @@ * THE SOFTWARE. */ -#ifndef __VIRTIO_RINGBUFFER_H -#define __VIRTIO_RINGBUFFER_H +#ifndef __VIRTIO_BUFFER_H +#define __VIRTIO_BUFFER_H #include @@ -30,26 +30,26 @@ extern "C" { #endif -#define VIRTIO_RINGBUFFER_SIZE (RPMSG_BUFFER_SIZE * 2) +#define VIRTIO_BUFFER_SIZE (RPMSG_BUFFER_SIZE * 2) typedef struct { - uint8_t buffer[VIRTIO_RINGBUFFER_SIZE]; + uint8_t buffer[VIRTIO_BUFFER_SIZE]; volatile uint16_t write; volatile uint16_t read; volatile uint16_t read_tmp; -} ringbuffer_t; +} virtio_buffer_t; -void ringbuffer_init(ringbuffer_t *ring); +void virtio_buffer_init(virtio_buffer_t *ring); -uint16_t ringbuffer_read_available(ringbuffer_t *ring); -uint16_t ringbuffer_read(ringbuffer_t *ring, uint8_t *dst, uint16_t size); -uint16_t ringbuffer_peek(ringbuffer_t *ring, uint8_t *dst, uint16_t size); +uint16_t virtio_buffer_read_available(virtio_buffer_t *ring); +uint16_t virtio_buffer_read(virtio_buffer_t *ring, uint8_t *dst, uint16_t size); +uint16_t virtio_buffer_peek(virtio_buffer_t *ring, uint8_t *dst, uint16_t size); -uint16_t ringbuffer_write_available(ringbuffer_t *ring); -uint16_t ringbuffer_write(ringbuffer_t *ring, uint8_t *src, uint16_t size); +uint16_t virtio_buffer_write_available(virtio_buffer_t *ring); +uint16_t virtio_buffer_write(virtio_buffer_t *ring, uint8_t *src, uint16_t size); #ifdef __cplusplus } #endif -#endif // __VIRTIO_RINGBUFFER_H +#endif // __VIRTIO_VIRTIO_BUFFER_H From de0c984464fe65bbd88c9b7489d3f7d599e96e72 Mon Sep 17 00:00:00 2001 From: Bumsik Kim Date: Sat, 16 Nov 2019 22:59:45 +0900 Subject: [PATCH 14/24] !fixup disable virtio by default --- boards.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/boards.txt b/boards.txt index 5063e90471..dc9b4f3244 100644 --- a/boards.txt +++ b/boards.txt @@ -2,10 +2,10 @@ menu.pnum=Board part number -menu.virtio=Virtual serial support menu.xserial=U(S)ART support menu.usb=USB support (if available) menu.xusb=USB speed (if available) +menu.virtio=Virtual serial support menu.opt=Optimize menu.rtlib=C Runtime Library @@ -1602,12 +1602,12 @@ Eval.menu.xserial.none.build.xSerial=-DHAL_UART_MODULE_ENABLED -DHWSERIAL_NONE Eval.menu.xserial.disabled=Disabled (no Serial support) Eval.menu.xserial.disabled.build.xSerial= -STM32MP1.menu.virtio.generic=/dev/ttyRPMSG0 => 'Serial' supersede U(S)ART -STM32MP1.menu.virtio.generic.build.enable_virtio={build.virtio_flags} -STM32MP1.menu.virtio.none=/dev/ttyRPMSG0 => SerialVirtIO -STM32MP1.menu.virtio.none.build.enable_virtio={build.virtio_flags} -DDISABLE_GENERIC_SERIALVIRTIO STM32MP1.menu.virtio.disable=Disabled (no /dev/ttyRPMSG0 available) STM32MP1.menu.virtio.disable.build.enable_virtio= +STM32MP1.menu.virtio.generic=/dev/ttyRPMSG0 => 'Serial' supersede U(S)ART +STM32MP1.menu.virtio.generic.build.enable_virtio={build.virtio_flags} +STM32MP1.menu.virtio.enabled=/dev/ttyRPMSG0 => SerialVirtIO +STM32MP1.menu.virtio.enabled.build.enable_virtio={build.virtio_flags} -DDISABLE_GENERIC_SERIALVIRTIO STM32MP1.menu.xserial.generic=UART only (generic 'Serial') STM32MP1.menu.xserial.generic.build.xSerial=-DHAL_UART_MODULE_ENABLED From c2b31eebc8064bb8486389bfff0c606b3eb608cd Mon Sep 17 00:00:00 2001 From: Bumsik Kim Date: Sun, 17 Nov 2019 10:41:45 +0900 Subject: [PATCH 15/24] !fixup remove debug printing in interrupts (not safe) --- cores/arduino/VirtIOSerial.cpp | 1 - cores/arduino/stm32/virtio/mbox_ipcc.c | 2 -- 2 files changed, 3 deletions(-) diff --git a/cores/arduino/VirtIOSerial.cpp b/cores/arduino/VirtIOSerial.cpp index 4881b86eef..49aeef63fc 100644 --- a/cores/arduino/VirtIOSerial.cpp +++ b/cores/arduino/VirtIOSerial.cpp @@ -151,7 +151,6 @@ void VirtIOSerial::flush(void) /* USER CODE BEGIN 4 */ void rxCallback(VIRT_UART_HandleTypeDef *huart) { - log_info("Msg received on VIRTUAL UART0 channel: %s \n\r", (char *) huart->pRxBuffPtr); // Linux host must send a dummy data first to finish initialization of rpmsg // on the coprocessor side. This message should be discarded. // run_arduino_gen.sh script will send dummy data: "DUMMY". diff --git a/cores/arduino/stm32/virtio/mbox_ipcc.c b/cores/arduino/stm32/virtio/mbox_ipcc.c index 0e036bb76d..cf27cda81d 100644 --- a/cores/arduino/stm32/virtio/mbox_ipcc.c +++ b/cores/arduino/stm32/virtio/mbox_ipcc.c @@ -144,7 +144,6 @@ void IPCC_channel1_callback(IPCC_HandleTypeDef *hipcc, uint32_t ChannelIndex, IPCC_CHANNELDirTypeDef ChannelDir) { /* Inform A7 that we have received the 'buff free' msg */ - OPENAMP_log_dbg("Ack 'buff free' message on ch1\r\n"); HAL_IPCC_NotifyCPU(hipcc, ChannelIndex, IPCC_CHANNEL_DIR_RX); rproc_virtio_notified(rvdev.vdev, VRING0_ID); } @@ -170,7 +169,6 @@ void IPCC_channel2_callback(IPCC_HandleTypeDef *hipcc, void IPCC_RX1_IRQHandler(void) { /* USER CODE BEGIN IPCC_RX1_IRQn 0 */ - log_dbg("%s: IT RX1\r\n", __func__); /* USER CODE END IPCC_RX1_IRQn 0 */ HAL_IPCC_RX_IRQHandler(&hipcc); /* USER CODE BEGIN IPCC_RX1_IRQn 1 */ From bf48f3bdcf4941202ecf956fdb9923bc85085145 Mon Sep 17 00:00:00 2001 From: Bumsik Kim Date: Sun, 17 Nov 2019 20:52:44 +0900 Subject: [PATCH 16/24] !fixup Cleanup debug messages and use Error_Handler() --- cores/arduino/VirtIOSerial.cpp | 8 +++++--- cores/arduino/stm32/virtio/mbox_ipcc.c | 10 +++------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/cores/arduino/VirtIOSerial.cpp b/cores/arduino/VirtIOSerial.cpp index 49aeef63fc..39fddacf62 100644 --- a/cores/arduino/VirtIOSerial.cpp +++ b/cores/arduino/VirtIOSerial.cpp @@ -44,9 +44,10 @@ void VirtIOSerial::begin(void) if (initialized) { return; } - OPENAMP_Init(); - if (VIRT_UART_Init(&huart) != VIRT_UART_OK) { - // log_err("VIRT_UART_Init UART0 failed.\r\n"); + if (OPENAMP_Init() != 0) { + Error_Handler(); + } + if (VIRT_UART_Init(&virt_huart) != VIRT_UART_OK) { Error_Handler(); } /*Need to register callback for message reception by channels*/ @@ -136,6 +137,7 @@ size_t VirtIOSerial::write(uint8_t ch) size_t VirtIOSerial::write(const uint8_t *buffer, size_t size) { if (VIRT_UART_Transmit(&huart, const_cast(buffer), size) == VIRT_UART_ERROR) { + // This error usually happens when rpmsg is not ready for return 0; } return size; diff --git a/cores/arduino/stm32/virtio/mbox_ipcc.c b/cores/arduino/stm32/virtio/mbox_ipcc.c index cf27cda81d..373f0aff2c 100644 --- a/cores/arduino/stm32/virtio/mbox_ipcc.c +++ b/cores/arduino/stm32/virtio/mbox_ipcc.c @@ -80,13 +80,13 @@ int MAILBOX_Init(void) if (HAL_IPCC_ActivateNotification(&hipcc, IPCC_CHANNEL_1, IPCC_CHANNEL_DIR_RX, IPCC_channel1_callback) != HAL_OK) { - OPENAMP_log_err("%s: ch_1 RX fail\n", __func__); + Error_Handler(); return -1; } if (HAL_IPCC_ActivateNotification(&hipcc, IPCC_CHANNEL_2, IPCC_CHANNEL_DIR_RX, IPCC_channel2_callback) != HAL_OK) { - OPENAMP_log_err("%s: ch_2 RX fail\n", __func__); + Error_Handler(); return -1; } @@ -106,27 +106,23 @@ int MAILBOX_Notify(void *priv, uint32_t id) /* Called after virtqueue processing: time to inform the remote */ if (id == VRING0_ID) { channel = IPCC_CHANNEL_1; - OPENAMP_log_dbg("Send msg on ch_1\r\n"); } else if (id == VRING1_ID) { /* Note: the OpenAMP framework never notifies this */ channel = IPCC_CHANNEL_2; - OPENAMP_log_dbg("Send 'buff free' on ch_2\r\n"); return -1; } else { - OPENAMP_log_err("invalid vring (%d)\r\n", (int)id); return -1; } /* Check that the channel is free (otherwise wait until it is) */ if (HAL_IPCC_GetChannelStatus(&hipcc, channel, IPCC_CHANNEL_DIR_TX) == IPCC_CHANNEL_STATUS_OCCUPIED) { - OPENAMP_log_dbg("Waiting for channel to be freed\r\n"); + // Wait for channel to be freed while (HAL_IPCC_GetChannelStatus(&hipcc, channel, IPCC_CHANNEL_DIR_TX) == IPCC_CHANNEL_STATUS_OCCUPIED) ; } /* Inform A7 (either new message, or buf free) */ HAL_IPCC_NotifyCPU(&hipcc, channel, IPCC_CHANNEL_DIR_TX); - return 0; } From fb10c3c39801d40ca3d53f6b4695867fd7e744e8 Mon Sep 17 00:00:00 2001 From: Alexandre Bourdiol Date: Mon, 27 Jan 2020 16:35:33 +0100 Subject: [PATCH 17/24] Fix compilation issue: virtual uart handle virt_huart rename huart --- cores/arduino/VirtIOSerial.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cores/arduino/VirtIOSerial.cpp b/cores/arduino/VirtIOSerial.cpp index 39fddacf62..1b30b162ad 100644 --- a/cores/arduino/VirtIOSerial.cpp +++ b/cores/arduino/VirtIOSerial.cpp @@ -47,7 +47,7 @@ void VirtIOSerial::begin(void) if (OPENAMP_Init() != 0) { Error_Handler(); } - if (VIRT_UART_Init(&virt_huart) != VIRT_UART_OK) { + if (VIRT_UART_Init(&huart) != VIRT_UART_OK) { Error_Handler(); } /*Need to register callback for message reception by channels*/ From 671d675738a0a86851f3d8fa555e6006b5129d55 Mon Sep 17 00:00:00 2001 From: Alexandre Bourdiol Date: Tue, 28 Jan 2020 16:38:00 +0100 Subject: [PATCH 18/24] VirtIOSerial and virtio: Fix typo --- cores/arduino/VirtIOSerial.cpp | 7 +++---- cores/arduino/VirtIOSerial.h | 2 +- cores/arduino/stm32/virtio/virtio_buffer.c | 8 ++++---- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/cores/arduino/VirtIOSerial.cpp b/cores/arduino/VirtIOSerial.cpp index 1b30b162ad..93920ab901 100644 --- a/cores/arduino/VirtIOSerial.cpp +++ b/cores/arduino/VirtIOSerial.cpp @@ -50,7 +50,7 @@ void VirtIOSerial::begin(void) if (VIRT_UART_Init(&huart) != VIRT_UART_OK) { Error_Handler(); } - /*Need to register callback for message reception by channels*/ + /* Need to register callback for message reception by channels */ if (VIRT_UART_RegisterCallback(&huart, VIRT_UART_RXCPLT_CB_ID, rxCallback) != VIRT_UART_OK) { Error_Handler(); } @@ -60,13 +60,13 @@ void VirtIOSerial::begin(void) void VirtIOSerial::begin(uint32_t /* baud_count */) { - // uart config is ignored in USB-CDC + // uart config is ignored in OpenAmp begin(); } void VirtIOSerial::begin(uint32_t /* baud_count */, uint8_t /* config */) { - // uart config is ignored in USB-CDC + // uart config is ignored in OpenAmp begin(); } @@ -150,7 +150,6 @@ void VirtIOSerial::flush(void) return; } -/* USER CODE BEGIN 4 */ void rxCallback(VIRT_UART_HandleTypeDef *huart) { // Linux host must send a dummy data first to finish initialization of rpmsg diff --git a/cores/arduino/VirtIOSerial.h b/cores/arduino/VirtIOSerial.h index 82c344f219..31534c62c2 100644 --- a/cores/arduino/VirtIOSerial.h +++ b/cores/arduino/VirtIOSerial.h @@ -28,7 +28,7 @@ #include "Stream.h" //================================================================================ -// Serial over CDC +// Serial over OpenAmp class VirtIOSerial : public Stream { public: void begin(void); diff --git a/cores/arduino/stm32/virtio/virtio_buffer.c b/cores/arduino/stm32/virtio/virtio_buffer.c index a8f35b267b..60aa70decc 100644 --- a/cores/arduino/stm32/virtio/virtio_buffer.c +++ b/cores/arduino/stm32/virtio/virtio_buffer.c @@ -42,7 +42,7 @@ void virtio_buffer_init(virtio_buffer_t *ring) uint16_t virtio_buffer_read_available(virtio_buffer_t *ring) { - // This will make the function safe when write openrations are done in interrupts + // This will make the function safe when write operations are done in interrupts volatile uint16_t write = ring->write; if (write < ring->read) { @@ -53,7 +53,7 @@ uint16_t virtio_buffer_read_available(virtio_buffer_t *ring) static uint16_t read_tmp(virtio_buffer_t *ring, uint8_t *dst, uint16_t size) { - // This will make the function safe when write openrations are done in interrupts + // This will make the function safe when write operations are done in interrupts volatile uint16_t write = ring->write; uint16_t end = (write >= ring->read_tmp) ? write : BUFFER_END + 1; @@ -99,7 +99,7 @@ uint16_t virtio_buffer_peek(virtio_buffer_t *ring, uint8_t *dst, uint16_t size) uint16_t virtio_buffer_write_available(virtio_buffer_t *ring) { - // This will make the function safe when read openrations are done in interrupts + // This will make the function safe when read operations are done in interrupts volatile uint16_t read = ring->read; if (ring->write < read) { @@ -110,7 +110,7 @@ uint16_t virtio_buffer_write_available(virtio_buffer_t *ring) uint16_t virtio_buffer_write(virtio_buffer_t *ring, uint8_t *src, uint16_t size) { - // This will make the function safe when read openrations are done in a interrupt + // This will make the function safe when read operations are done in a interrupt volatile uint16_t read = ring->read; uint16_t end = (ring->write < read) ? read - 1 : (read == 0) ? BUFFER_END : BUFFER_END + 1; From 6dbfc1b898ce2a0825174ae96e1954a8a3f2b5ab Mon Sep 17 00:00:00 2001 From: Alexandre Bourdiol Date: Wed, 29 Jan 2020 11:31:45 +0100 Subject: [PATCH 19/24] virtio_buffer: rework to get ride of read_tmp Note: I stick to Arduino official definition: https://www.arduino.cc/reference/en/language/functions/communication/serial/peek/ "That is, successive calls to peek() will return the same character, as will the next call to read()." --- cores/arduino/stm32/virtio/virtio_buffer.c | 38 +++++++--------------- cores/arduino/stm32/virtio/virtio_buffer.h | 1 - 2 files changed, 12 insertions(+), 27 deletions(-) diff --git a/cores/arduino/stm32/virtio/virtio_buffer.c b/cores/arduino/stm32/virtio/virtio_buffer.c index 60aa70decc..19a28c9884 100644 --- a/cores/arduino/stm32/virtio/virtio_buffer.c +++ b/cores/arduino/stm32/virtio/virtio_buffer.c @@ -29,15 +29,10 @@ #define BUFFER_END (VIRTIO_BUFFER_SIZE - 1) -static uint16_t read_tmp(virtio_buffer_t *ring, uint8_t *dst, uint16_t size); -static void read_commit(virtio_buffer_t *ring); -static void read_rollback(virtio_buffer_t *ring); - void virtio_buffer_init(virtio_buffer_t *ring) { ring->write = 0; ring->read = 0; - ring->read_tmp = 0; } uint16_t virtio_buffer_read_available(virtio_buffer_t *ring) @@ -51,35 +46,27 @@ uint16_t virtio_buffer_read_available(virtio_buffer_t *ring) return write - ring->read; } -static uint16_t read_tmp(virtio_buffer_t *ring, uint8_t *dst, uint16_t size) +static uint16_t read(virtio_buffer_t *ring, uint8_t *dst, uint16_t size, bool peek) { // This will make the function safe when write operations are done in interrupts volatile uint16_t write = ring->write; - uint16_t end = (write >= ring->read_tmp) ? write : BUFFER_END + 1; + uint16_t end = (write >= ring->read) ? write : BUFFER_END + 1; + + size = min(end - ring->read, size); + memcpy(dst, ring->buffer + ring->read, size); + if (!peek) { + ring->read += size; - size = min(end - ring->read_tmp, size); - memcpy(dst, ring->buffer + ring->read_tmp, size); - ring->read_tmp += size; - if (ring->read_tmp > BUFFER_END) { - ring->read_tmp = 0; + if (ring->read > BUFFER_END) { + ring->read = 0; + } } return size; } -static void read_commit(virtio_buffer_t *ring) -{ - ring->read = ring->read_tmp; -} - -static void read_rollback(virtio_buffer_t *ring) -{ - ring->read_tmp = ring->read; -} - uint16_t virtio_buffer_read(virtio_buffer_t *ring, uint8_t *dst, uint16_t size) { - uint16_t recv_size = read_tmp(ring, dst, size); - read_commit(ring); + uint16_t recv_size = read(ring, dst, size, false); return recv_size; } @@ -91,9 +78,8 @@ uint16_t virtio_buffer_peek(virtio_buffer_t *ring, uint8_t *dst, uint16_t size) size = min(size, virtio_buffer_read_available(ring)); uint16_t recv_size = 0; while (recv_size < size) { - recv_size += read_tmp(ring, dst + recv_size, size - recv_size); + recv_size += read(ring, dst + recv_size, size - recv_size, true); } - read_rollback(ring); return recv_size; } diff --git a/cores/arduino/stm32/virtio/virtio_buffer.h b/cores/arduino/stm32/virtio/virtio_buffer.h index df5b3f96fb..f0cafe5457 100644 --- a/cores/arduino/stm32/virtio/virtio_buffer.h +++ b/cores/arduino/stm32/virtio/virtio_buffer.h @@ -36,7 +36,6 @@ typedef struct { uint8_t buffer[VIRTIO_BUFFER_SIZE]; volatile uint16_t write; volatile uint16_t read; - volatile uint16_t read_tmp; } virtio_buffer_t; void virtio_buffer_init(virtio_buffer_t *ring); From 0e57b19299c2047d481a201d699b54df86903fc1 Mon Sep 17 00:00:00 2001 From: Alexandre Bourdiol Date: Wed, 29 Jan 2020 11:34:38 +0100 Subject: [PATCH 20/24] virtio_buffer: manage buffer rollover --- cores/arduino/VirtIOSerial.cpp | 18 ++-- cores/arduino/stm32/virtio/virtio_buffer.c | 103 ++++++++++++--------- cores/arduino/stm32/virtio/virtio_buffer.h | 4 +- 3 files changed, 70 insertions(+), 55 deletions(-) diff --git a/cores/arduino/VirtIOSerial.cpp b/cores/arduino/VirtIOSerial.cpp index 93920ab901..3dfe6b7d6a 100644 --- a/cores/arduino/VirtIOSerial.cpp +++ b/cores/arduino/VirtIOSerial.cpp @@ -113,17 +113,15 @@ int VirtIOSerial::read(void) size_t VirtIOSerial::readBytes(char *buffer, size_t length) { - const size_t size = length; - _startMillis = millis(); - while (length > 0 && (millis() - _startMillis < _timeout)) { - uint16_t prev_write_available = virtio_buffer_write_available(&ring); - length -= virtio_buffer_read(&ring, reinterpret_cast(buffer), length); - if (prev_write_available < RPMSG_BUFFER_SIZE - && virtio_buffer_write_available(&ring) >= RPMSG_BUFFER_SIZE) { - MAILBOX_Notify_Rx_Buf_Free(); - } + uint16_t prev_write_available = virtio_buffer_write_available(&_VirtIOSerialObj.ring); + const size_t size = virtio_buffer_read(&_VirtIOSerialObj.ring, reinterpret_cast(buffer), length); + + if (prev_write_available < RPMSG_BUFFER_SIZE + && virtio_buffer_write_available(&_VirtIOSerialObj.ring) >= RPMSG_BUFFER_SIZE) { + MAILBOX_Notify_Rx_Buf_Free(); } - return size - length; + + return size; } size_t VirtIOSerial::write(uint8_t ch) diff --git a/cores/arduino/stm32/virtio/virtio_buffer.c b/cores/arduino/stm32/virtio/virtio_buffer.c index 19a28c9884..b6643f2688 100644 --- a/cores/arduino/stm32/virtio/virtio_buffer.c +++ b/cores/arduino/stm32/virtio/virtio_buffer.c @@ -27,38 +27,50 @@ #include #include "wiring.h" -#define BUFFER_END (VIRTIO_BUFFER_SIZE - 1) - void virtio_buffer_init(virtio_buffer_t *ring) { - ring->write = 0; - ring->read = 0; + ring->write_index = 0; + ring->read_index = 0; } uint16_t virtio_buffer_read_available(virtio_buffer_t *ring) { - // This will make the function safe when write operations are done in interrupts - volatile uint16_t write = ring->write; + int32_t delta = ring->write_index - ring->read_index; - if (write < ring->read) { - return (BUFFER_END - ring->read) + (write + 1); + if (delta < 0) { + return (VIRTIO_BUFFER_SIZE + delta); } - return write - ring->read; + return delta; } +/* WARNING no protection against race codition (on ring->read_index) when used in interruption */ static uint16_t read(virtio_buffer_t *ring, uint8_t *dst, uint16_t size, bool peek) { - // This will make the function safe when write operations are done in interrupts - volatile uint16_t write = ring->write; - uint16_t end = (write >= ring->read) ? write : BUFFER_END + 1; + uint16_t read_index = ring->read_index; + int32_t delta = ring->write_index - read_index; + if (delta < 0) { + delta += VIRTIO_BUFFER_SIZE; + } + + size = min(size, delta); + + if ((size + read_index) > VIRTIO_BUFFER_SIZE) { + // Manage ring buffer rollover + // First, copy ring buffer from read index to end of buffer + memcpy(dst, ring->buffer + read_index, VIRTIO_BUFFER_SIZE - read_index); + // then, copy ring buffer from begining of buffer to end of read + memcpy(dst + VIRTIO_BUFFER_SIZE - read_index, ring->buffer, size - (VIRTIO_BUFFER_SIZE - read_index)); + } else { + memcpy(dst, ring->buffer + read_index, size); + } - size = min(end - ring->read, size); - memcpy(dst, ring->buffer + ring->read, size); + // Update read index if not peeked if (!peek) { - ring->read += size; + ring->read_index += size; - if (ring->read > BUFFER_END) { - ring->read = 0; + // Manage ring buffer rollover + if (ring->read_index >= VIRTIO_BUFFER_SIZE) { + ring->read_index -= VIRTIO_BUFFER_SIZE; } } return size; @@ -66,46 +78,51 @@ static uint16_t read(virtio_buffer_t *ring, uint8_t *dst, uint16_t size, bool pe uint16_t virtio_buffer_read(virtio_buffer_t *ring, uint8_t *dst, uint16_t size) { - uint16_t recv_size = read(ring, dst, size, false); - return recv_size; + return read(ring, dst, size, false); } -/** - * WARNING: The size of read cannot be larger than virtio_buffer_read_available(). - */ + uint16_t virtio_buffer_peek(virtio_buffer_t *ring, uint8_t *dst, uint16_t size) { - size = min(size, virtio_buffer_read_available(ring)); - uint16_t recv_size = 0; - while (recv_size < size) { - recv_size += read(ring, dst + recv_size, size - recv_size, true); - } - return recv_size; + return read(ring, dst, size, true); } + + uint16_t virtio_buffer_write_available(virtio_buffer_t *ring) { - // This will make the function safe when read operations are done in interrupts - volatile uint16_t read = ring->read; + int32_t delta = ring->read_index - ring->write_index - 1; - if (ring->write < read) { - return (read - 1) - ring->write; + if (delta < 0) { + return (VIRTIO_BUFFER_SIZE + delta); } - return read + (BUFFER_END - ring->write); + return delta; } +/* WARNING no protection against race codition (on ring->write_index) when used in interruption */ uint16_t virtio_buffer_write(virtio_buffer_t *ring, uint8_t *src, uint16_t size) { - // This will make the function safe when read operations are done in a interrupt - volatile uint16_t read = ring->read; - uint16_t end = (ring->write < read) ? read - 1 - : (read == 0) ? BUFFER_END : BUFFER_END + 1; - - size = min(end - ring->write, size); - memcpy(ring->buffer + ring->write, src, size); - ring->write += size; - if (ring->write > BUFFER_END) { - ring->write = 0; + uint16_t write_index = ring->write_index; + int32_t delta = ring->read_index - write_index - 1; + if (delta < 0) { + delta += VIRTIO_BUFFER_SIZE; + } + + size = min(size, delta); + + if ((size + write_index) > VIRTIO_BUFFER_SIZE) { + // Manage ring buffer rollover + // First, write ring buffer from write index to end of buffer + memcpy(ring->buffer + write_index, src, VIRTIO_BUFFER_SIZE - write_index); + // then, write ring buffer from beginning of buffer to end of read + memcpy(ring->buffer, src + VIRTIO_BUFFER_SIZE - write_index, size - (VIRTIO_BUFFER_SIZE - write_index)); + } else { + memcpy(ring->buffer + write_index, src, size); + } + + ring->write_index += size; + if (ring->write_index >= VIRTIO_BUFFER_SIZE) { + ring->write_index -= VIRTIO_BUFFER_SIZE; } return size; } diff --git a/cores/arduino/stm32/virtio/virtio_buffer.h b/cores/arduino/stm32/virtio/virtio_buffer.h index f0cafe5457..bc17e63348 100644 --- a/cores/arduino/stm32/virtio/virtio_buffer.h +++ b/cores/arduino/stm32/virtio/virtio_buffer.h @@ -34,8 +34,8 @@ extern "C" { typedef struct { uint8_t buffer[VIRTIO_BUFFER_SIZE]; - volatile uint16_t write; - volatile uint16_t read; + volatile uint16_t write_index; + volatile uint16_t read_index; } virtio_buffer_t; void virtio_buffer_init(virtio_buffer_t *ring); From fa37aaa8670531bf184e54d4fa51b0b49f54089f Mon Sep 17 00:00:00 2001 From: Alexandre Bourdiol Date: Wed, 29 Jan 2020 16:05:03 +0100 Subject: [PATCH 21/24] VirtIoSerial: support multi instances --- cores/arduino/VirtIOSerial.cpp | 82 ++++++++++++++++++++++------------ cores/arduino/VirtIOSerial.h | 25 +++++++++++ 2 files changed, 78 insertions(+), 29 deletions(-) diff --git a/cores/arduino/VirtIOSerial.cpp b/cores/arduino/VirtIOSerial.cpp index 3dfe6b7d6a..f35303c070 100644 --- a/cores/arduino/VirtIOSerial.cpp +++ b/cores/arduino/VirtIOSerial.cpp @@ -23,39 +23,45 @@ #if defined (VIRTIOCON) -#include "openamp.h" -#include "openamp_log.h" -#include "wiring.h" -#include "virtio_buffer.h" +#include "VirtIOSerial.h" +#if !defined(VIRTIOSERIAL_NUM) +#define VIRTIOSERIAL_NUM 1 +#endif -VirtIOSerial SerialVirtIO; -void serialEventVirtIO() __attribute__((weak)); +VirtIOSerialObj_t *VirtIOSerial_Handle[VIRTIOSERIAL_NUM] = {NULL}; -static VIRT_UART_HandleTypeDef huart; -static bool initialized = false; -static bool first_message_discarded = false; -static virtio_buffer_t ring; +uint32_t VirtIOSerial::VirtIOSerial_index = 0; + +// Default instance +VirtIOSerial SerialVirtIO; -void rxCallback(VIRT_UART_HandleTypeDef *huart); +void serialEventVirtIO() __attribute__((weak)); +VirtIOSerialObj_t *get_VirtIOSerial_obj(VIRT_UART_HandleTypeDef *huart); void VirtIOSerial::begin(void) { - virtio_buffer_init(&ring); - if (initialized) { + virtio_buffer_init(&_VirtIOSerialObj.ring); + if (_VirtIOSerialObj.initialized) { return; } if (OPENAMP_Init() != 0) { Error_Handler(); } - if (VIRT_UART_Init(&huart) != VIRT_UART_OK) { + if (VIRT_UART_Init(&_VirtIOSerialObj.handle) != VIRT_UART_OK) { Error_Handler(); } + + VirtIOSerial_index ++; + _VirtIOSerialObj.__this = (void *)this; + /* Need to register callback for message reception by channels */ - if (VIRT_UART_RegisterCallback(&huart, VIRT_UART_RXCPLT_CB_ID, rxCallback) != VIRT_UART_OK) { + if (VIRT_UART_RegisterCallback(&_VirtIOSerialObj.handle, VIRT_UART_RXCPLT_CB_ID, rxGenericCallback) != VIRT_UART_OK) { Error_Handler(); } - initialized = true; - first_message_discarded = false; + + VirtIOSerial_Handle[VirtIOSerial_index] = &_VirtIOSerialObj; + _VirtIOSerialObj.initialized = true; + _VirtIOSerialObj.first_message_discarded = false; } void VirtIOSerial::begin(uint32_t /* baud_count */) @@ -73,13 +79,13 @@ void VirtIOSerial::begin(uint32_t /* baud_count */, uint8_t /* config */) void VirtIOSerial::end() { OPENAMP_DeInit(); - virtio_buffer_init(&ring); - initialized = false; + virtio_buffer_init(&_VirtIOSerialObj.ring); + _VirtIOSerialObj.initialized = false; } int VirtIOSerial::available(void) { - return virtio_buffer_read_available(&ring); + return virtio_buffer_read_available(&_VirtIOSerialObj.ring); } int VirtIOSerial::availableForWrite() @@ -91,9 +97,9 @@ int VirtIOSerial::availableForWrite() int VirtIOSerial::peek(void) { - if (virtio_buffer_read_available(&ring) > 0) { + if (virtio_buffer_read_available(&_VirtIOSerialObj.ring) > 0) { uint8_t tmp; - virtio_buffer_peek(&ring, &tmp, 1); + virtio_buffer_peek(&_VirtIOSerialObj.ring, &tmp, 1); return tmp; } else { return -1; @@ -134,7 +140,7 @@ size_t VirtIOSerial::write(uint8_t ch) // until all bytes are sent. size_t VirtIOSerial::write(const uint8_t *buffer, size_t size) { - if (VIRT_UART_Transmit(&huart, const_cast(buffer), size) == VIRT_UART_ERROR) { + if (VIRT_UART_Transmit(&_VirtIOSerialObj.handle, const_cast(buffer), size) == VIRT_UART_ERROR) { // This error usually happens when rpmsg is not ready for return 0; } @@ -148,26 +154,44 @@ void VirtIOSerial::flush(void) return; } -void rxCallback(VIRT_UART_HandleTypeDef *huart) +void VirtIOSerial::rxGenericCallback(VIRT_UART_HandleTypeDef *huart) { + VirtIOSerialObj_t *obj = get_VirtIOSerial_obj(huart); + VirtIOSerial *VIOS = (VirtIOSerial *)(obj->__this); + + VIOS->rxCallback(huart); +} + +void VirtIOSerial::rxCallback(VIRT_UART_HandleTypeDef *huart) +{ + // Linux host must send a dummy data first to finish initialization of rpmsg // on the coprocessor side. This message should be discarded. // run_arduino_gen.sh script will send dummy data: "DUMMY". // See: https://github.com/OpenAMP/open-amp/issues/182 // See: run_arduino_gen.sh - if (!first_message_discarded) { + if (!_VirtIOSerialObj.first_message_discarded) { huart->RxXferSize = 0; - first_message_discarded = true; + _VirtIOSerialObj.first_message_discarded = true; } /* copy received msg in a variable to sent it back to master processor in main infinite loop*/ - size_t size = min(huart->RxXferSize, virtio_buffer_write_available(&ring)); + size_t size = min(huart->RxXferSize, virtio_buffer_write_available(&_VirtIOSerialObj.ring)); while (size > 0) { - size -= virtio_buffer_write(&ring, huart->pRxBuffPtr, size); + size -= virtio_buffer_write(&_VirtIOSerialObj.ring, huart->pRxBuffPtr, size); } - if (virtio_buffer_write_available(&ring) >= RPMSG_BUFFER_SIZE) { + if (virtio_buffer_write_available(&_VirtIOSerialObj.ring) >= RPMSG_BUFFER_SIZE) { MAILBOX_Notify_Rx_Buf_Free(); } } +/* Aim of the function is to get _VirtIOSerialObj pointer using huart pointer */ +/* Highly inspired from magical linux kernel's "container_of" */ +VirtIOSerialObj_t *get_VirtIOSerial_obj(VIRT_UART_HandleTypeDef *huart) +{ + VirtIOSerialObj_t *obj; + obj = (VirtIOSerialObj_t *)((char *)huart - offsetof(VirtIOSerialObj_t, handle)); + return (obj); +} + #endif /* VIRTIOCON */ diff --git a/cores/arduino/VirtIOSerial.h b/cores/arduino/VirtIOSerial.h index 31534c62c2..02572f6692 100644 --- a/cores/arduino/VirtIOSerial.h +++ b/cores/arduino/VirtIOSerial.h @@ -26,9 +26,26 @@ #if defined (VIRTIOCON) #include "Stream.h" +#include "openamp.h" +#include "openamp_log.h" +#include "wiring.h" +#include "virtio_buffer.h" //================================================================================ // Serial over OpenAmp + +// This structure is used to be able to get VirtIOSerial instance (C++ class) +// from handler (C structure) specially for interrupt management +typedef struct { + // Those 2 first fields must remain in this order at the beginning of the structure + void *__this; + VIRT_UART_HandleTypeDef handle; + bool initialized; + bool first_message_discarded; + virtio_buffer_t ring; +} VirtIOSerialObj_t; + + class VirtIOSerial : public Stream { public: void begin(void); @@ -44,11 +61,19 @@ class VirtIOSerial : public Stream { virtual size_t write(uint8_t); virtual size_t write(const uint8_t *buffer, size_t size); virtual void flush(void); + + static void rxGenericCallback(VIRT_UART_HandleTypeDef *huart); + void rxCallback(VIRT_UART_HandleTypeDef *huart); + using Print::write; // pull in write(str) from Print operator bool(void) { return true; } + + private: + static uint32_t VirtIOSerial_index; + VirtIOSerialObj_t _VirtIOSerialObj; }; extern VirtIOSerial SerialVirtIO; From 0c8dcb844dd47913fb1ec42cd585f4fefd0c31ff Mon Sep 17 00:00:00 2001 From: Alexandre Bourdiol Date: Wed, 29 Jan 2020 17:25:03 +0100 Subject: [PATCH 22/24] virtio: Remove useless CubeMX tags --- cores/arduino/stm32/virtio/mbox_ipcc.c | 10 ---------- cores/arduino/stm32/virtio/mbox_ipcc.h | 8 -------- cores/arduino/stm32/virtio/openamp_conf.h | 6 ------ 3 files changed, 24 deletions(-) diff --git a/cores/arduino/stm32/virtio/mbox_ipcc.c b/cores/arduino/stm32/virtio/mbox_ipcc.c index 373f0aff2c..c957bc6979 100644 --- a/cores/arduino/stm32/virtio/mbox_ipcc.c +++ b/cores/arduino/stm32/virtio/mbox_ipcc.c @@ -37,11 +37,6 @@ #include "stm32_def.h" #include "openamp_conf.h" -/* Within 'USER CODE' section, code will be kept by default at each generation */ -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - /* Private define ------------------------------------------------------------*/ #define MASTER_CPU_ID 0 #define REMOTE_CPU_ID 1 @@ -164,12 +159,7 @@ void IPCC_channel2_callback(IPCC_HandleTypeDef *hipcc, */ void IPCC_RX1_IRQHandler(void) { - /* USER CODE BEGIN IPCC_RX1_IRQn 0 */ - /* USER CODE END IPCC_RX1_IRQn 0 */ HAL_IPCC_RX_IRQHandler(&hipcc); - /* USER CODE BEGIN IPCC_RX1_IRQn 1 */ - - /* USER CODE END IPCC_RX1_IRQn 1 */ } #endif /* VIRTIOCON */ diff --git a/cores/arduino/stm32/virtio/mbox_ipcc.h b/cores/arduino/stm32/virtio/mbox_ipcc.h index 341c808d11..34fe831e99 100644 --- a/cores/arduino/stm32/virtio/mbox_ipcc.h +++ b/cores/arduino/stm32/virtio/mbox_ipcc.h @@ -30,10 +30,6 @@ #define IPCC_IRQ_SUBPRIO 0 #endif -/* USER CODE BEGIN firstSection */ -/* can be used to modify / undefine following code or add new definitions */ -/* USER CODE END firstSection */ - /* Includes ------------------------------------------------------------------*/ /* Exported types ------------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/ @@ -42,9 +38,5 @@ int MAILBOX_Init(void); int MAILBOX_Notify(void *priv, uint32_t id); void MAILBOX_Notify_Rx_Buf_Free(void); -/* USER CODE BEGIN lastSection */ -/* can be used to modify / undefine previous code or add new definitions */ -/* USER CODE END lastSection */ - #endif /* VIRTIOCON */ #endif /* MBOX_IPCC_H_ */ diff --git a/cores/arduino/stm32/virtio/openamp_conf.h b/cores/arduino/stm32/virtio/openamp_conf.h index ef28b5f1c9..19d87de7a1 100644 --- a/cores/arduino/stm32/virtio/openamp_conf.h +++ b/cores/arduino/stm32/virtio/openamp_conf.h @@ -77,12 +77,6 @@ extern "C" { #include "virt_i2c.h" #endif /* VIRTUAL_I2C_MODULE_ENABLED */ - - -/* USER CODE BEGIN INCLUDE */ - -/* USER CODE END INCLUDE */ - /** @addtogroup OPENAMP_MW * @{ */ From 7ac5b96cf9d66faf764733b4538c227421f99555 Mon Sep 17 00:00:00 2001 From: Alexandre Bourdiol Date: Fri, 31 Jan 2020 15:54:49 +0100 Subject: [PATCH 23/24] Rename virtio directory to OpenAmp virtio is the lower layer of the stack, so it is to restrictive to identify the whole stack. OpenAmp is already used in Middleware to identify the whole stack. --- cores/arduino/stm32/{virtio => OpenAMP}/libmetal/device.c | 0 .../stm32/{virtio => OpenAMP}/libmetal/generic/condition.c | 0 .../stm32/{virtio => OpenAMP}/libmetal/generic/cortexm/sys.c | 0 .../stm32/{virtio => OpenAMP}/libmetal/generic/generic_device.c | 0 .../stm32/{virtio => OpenAMP}/libmetal/generic/generic_init.c | 0 .../stm32/{virtio => OpenAMP}/libmetal/generic/generic_io.c | 0 .../stm32/{virtio => OpenAMP}/libmetal/generic/generic_shmem.c | 0 cores/arduino/stm32/{virtio => OpenAMP}/libmetal/generic/time.c | 0 cores/arduino/stm32/{virtio => OpenAMP}/libmetal/init.c | 0 cores/arduino/stm32/{virtio => OpenAMP}/libmetal/io.c | 0 cores/arduino/stm32/{virtio => OpenAMP}/libmetal/log.c | 0 cores/arduino/stm32/{virtio => OpenAMP}/libmetal/shmem.c | 0 cores/arduino/stm32/{virtio => OpenAMP}/mbox_ipcc.c | 0 cores/arduino/stm32/{virtio => OpenAMP}/mbox_ipcc.h | 0 .../{virtio => OpenAMP}/open-amp/remoteproc/remoteproc_virtio.c | 0 cores/arduino/stm32/{virtio => OpenAMP}/open-amp/rpmsg/rpmsg.c | 0 .../stm32/{virtio => OpenAMP}/open-amp/rpmsg/rpmsg_virtio.c | 0 cores/arduino/stm32/{virtio => OpenAMP}/openamp.c | 0 cores/arduino/stm32/{virtio => OpenAMP}/openamp.h | 0 cores/arduino/stm32/{virtio => OpenAMP}/openamp_conf.h | 0 cores/arduino/stm32/{virtio => OpenAMP}/openamp_log.c | 0 cores/arduino/stm32/{virtio => OpenAMP}/openamp_log.h | 0 cores/arduino/stm32/{virtio => OpenAMP}/rsc_table.c | 0 cores/arduino/stm32/{virtio => OpenAMP}/rsc_table.h | 0 cores/arduino/stm32/{virtio => OpenAMP}/virt_uart.c | 0 cores/arduino/stm32/{virtio => OpenAMP}/virtio/virtio.c | 0 cores/arduino/stm32/{virtio => OpenAMP}/virtio/virtqueue.c | 0 cores/arduino/stm32/{virtio => OpenAMP}/virtio_buffer.c | 0 cores/arduino/stm32/{virtio => OpenAMP}/virtio_buffer.h | 0 cores/arduino/stm32/{virtio => OpenAMP}/virtio_config.h | 0 30 files changed, 0 insertions(+), 0 deletions(-) rename cores/arduino/stm32/{virtio => OpenAMP}/libmetal/device.c (100%) rename cores/arduino/stm32/{virtio => OpenAMP}/libmetal/generic/condition.c (100%) rename cores/arduino/stm32/{virtio => OpenAMP}/libmetal/generic/cortexm/sys.c (100%) rename cores/arduino/stm32/{virtio => OpenAMP}/libmetal/generic/generic_device.c (100%) rename cores/arduino/stm32/{virtio => OpenAMP}/libmetal/generic/generic_init.c (100%) rename cores/arduino/stm32/{virtio => OpenAMP}/libmetal/generic/generic_io.c (100%) rename cores/arduino/stm32/{virtio => OpenAMP}/libmetal/generic/generic_shmem.c (100%) rename cores/arduino/stm32/{virtio => OpenAMP}/libmetal/generic/time.c (100%) rename cores/arduino/stm32/{virtio => OpenAMP}/libmetal/init.c (100%) rename cores/arduino/stm32/{virtio => OpenAMP}/libmetal/io.c (100%) rename cores/arduino/stm32/{virtio => OpenAMP}/libmetal/log.c (100%) rename cores/arduino/stm32/{virtio => OpenAMP}/libmetal/shmem.c (100%) rename cores/arduino/stm32/{virtio => OpenAMP}/mbox_ipcc.c (100%) rename cores/arduino/stm32/{virtio => OpenAMP}/mbox_ipcc.h (100%) rename cores/arduino/stm32/{virtio => OpenAMP}/open-amp/remoteproc/remoteproc_virtio.c (100%) rename cores/arduino/stm32/{virtio => OpenAMP}/open-amp/rpmsg/rpmsg.c (100%) rename cores/arduino/stm32/{virtio => OpenAMP}/open-amp/rpmsg/rpmsg_virtio.c (100%) rename cores/arduino/stm32/{virtio => OpenAMP}/openamp.c (100%) rename cores/arduino/stm32/{virtio => OpenAMP}/openamp.h (100%) rename cores/arduino/stm32/{virtio => OpenAMP}/openamp_conf.h (100%) rename cores/arduino/stm32/{virtio => OpenAMP}/openamp_log.c (100%) rename cores/arduino/stm32/{virtio => OpenAMP}/openamp_log.h (100%) rename cores/arduino/stm32/{virtio => OpenAMP}/rsc_table.c (100%) rename cores/arduino/stm32/{virtio => OpenAMP}/rsc_table.h (100%) rename cores/arduino/stm32/{virtio => OpenAMP}/virt_uart.c (100%) rename cores/arduino/stm32/{virtio => OpenAMP}/virtio/virtio.c (100%) rename cores/arduino/stm32/{virtio => OpenAMP}/virtio/virtqueue.c (100%) rename cores/arduino/stm32/{virtio => OpenAMP}/virtio_buffer.c (100%) rename cores/arduino/stm32/{virtio => OpenAMP}/virtio_buffer.h (100%) rename cores/arduino/stm32/{virtio => OpenAMP}/virtio_config.h (100%) diff --git a/cores/arduino/stm32/virtio/libmetal/device.c b/cores/arduino/stm32/OpenAMP/libmetal/device.c similarity index 100% rename from cores/arduino/stm32/virtio/libmetal/device.c rename to cores/arduino/stm32/OpenAMP/libmetal/device.c diff --git a/cores/arduino/stm32/virtio/libmetal/generic/condition.c b/cores/arduino/stm32/OpenAMP/libmetal/generic/condition.c similarity index 100% rename from cores/arduino/stm32/virtio/libmetal/generic/condition.c rename to cores/arduino/stm32/OpenAMP/libmetal/generic/condition.c diff --git a/cores/arduino/stm32/virtio/libmetal/generic/cortexm/sys.c b/cores/arduino/stm32/OpenAMP/libmetal/generic/cortexm/sys.c similarity index 100% rename from cores/arduino/stm32/virtio/libmetal/generic/cortexm/sys.c rename to cores/arduino/stm32/OpenAMP/libmetal/generic/cortexm/sys.c diff --git a/cores/arduino/stm32/virtio/libmetal/generic/generic_device.c b/cores/arduino/stm32/OpenAMP/libmetal/generic/generic_device.c similarity index 100% rename from cores/arduino/stm32/virtio/libmetal/generic/generic_device.c rename to cores/arduino/stm32/OpenAMP/libmetal/generic/generic_device.c diff --git a/cores/arduino/stm32/virtio/libmetal/generic/generic_init.c b/cores/arduino/stm32/OpenAMP/libmetal/generic/generic_init.c similarity index 100% rename from cores/arduino/stm32/virtio/libmetal/generic/generic_init.c rename to cores/arduino/stm32/OpenAMP/libmetal/generic/generic_init.c diff --git a/cores/arduino/stm32/virtio/libmetal/generic/generic_io.c b/cores/arduino/stm32/OpenAMP/libmetal/generic/generic_io.c similarity index 100% rename from cores/arduino/stm32/virtio/libmetal/generic/generic_io.c rename to cores/arduino/stm32/OpenAMP/libmetal/generic/generic_io.c diff --git a/cores/arduino/stm32/virtio/libmetal/generic/generic_shmem.c b/cores/arduino/stm32/OpenAMP/libmetal/generic/generic_shmem.c similarity index 100% rename from cores/arduino/stm32/virtio/libmetal/generic/generic_shmem.c rename to cores/arduino/stm32/OpenAMP/libmetal/generic/generic_shmem.c diff --git a/cores/arduino/stm32/virtio/libmetal/generic/time.c b/cores/arduino/stm32/OpenAMP/libmetal/generic/time.c similarity index 100% rename from cores/arduino/stm32/virtio/libmetal/generic/time.c rename to cores/arduino/stm32/OpenAMP/libmetal/generic/time.c diff --git a/cores/arduino/stm32/virtio/libmetal/init.c b/cores/arduino/stm32/OpenAMP/libmetal/init.c similarity index 100% rename from cores/arduino/stm32/virtio/libmetal/init.c rename to cores/arduino/stm32/OpenAMP/libmetal/init.c diff --git a/cores/arduino/stm32/virtio/libmetal/io.c b/cores/arduino/stm32/OpenAMP/libmetal/io.c similarity index 100% rename from cores/arduino/stm32/virtio/libmetal/io.c rename to cores/arduino/stm32/OpenAMP/libmetal/io.c diff --git a/cores/arduino/stm32/virtio/libmetal/log.c b/cores/arduino/stm32/OpenAMP/libmetal/log.c similarity index 100% rename from cores/arduino/stm32/virtio/libmetal/log.c rename to cores/arduino/stm32/OpenAMP/libmetal/log.c diff --git a/cores/arduino/stm32/virtio/libmetal/shmem.c b/cores/arduino/stm32/OpenAMP/libmetal/shmem.c similarity index 100% rename from cores/arduino/stm32/virtio/libmetal/shmem.c rename to cores/arduino/stm32/OpenAMP/libmetal/shmem.c diff --git a/cores/arduino/stm32/virtio/mbox_ipcc.c b/cores/arduino/stm32/OpenAMP/mbox_ipcc.c similarity index 100% rename from cores/arduino/stm32/virtio/mbox_ipcc.c rename to cores/arduino/stm32/OpenAMP/mbox_ipcc.c diff --git a/cores/arduino/stm32/virtio/mbox_ipcc.h b/cores/arduino/stm32/OpenAMP/mbox_ipcc.h similarity index 100% rename from cores/arduino/stm32/virtio/mbox_ipcc.h rename to cores/arduino/stm32/OpenAMP/mbox_ipcc.h diff --git a/cores/arduino/stm32/virtio/open-amp/remoteproc/remoteproc_virtio.c b/cores/arduino/stm32/OpenAMP/open-amp/remoteproc/remoteproc_virtio.c similarity index 100% rename from cores/arduino/stm32/virtio/open-amp/remoteproc/remoteproc_virtio.c rename to cores/arduino/stm32/OpenAMP/open-amp/remoteproc/remoteproc_virtio.c diff --git a/cores/arduino/stm32/virtio/open-amp/rpmsg/rpmsg.c b/cores/arduino/stm32/OpenAMP/open-amp/rpmsg/rpmsg.c similarity index 100% rename from cores/arduino/stm32/virtio/open-amp/rpmsg/rpmsg.c rename to cores/arduino/stm32/OpenAMP/open-amp/rpmsg/rpmsg.c diff --git a/cores/arduino/stm32/virtio/open-amp/rpmsg/rpmsg_virtio.c b/cores/arduino/stm32/OpenAMP/open-amp/rpmsg/rpmsg_virtio.c similarity index 100% rename from cores/arduino/stm32/virtio/open-amp/rpmsg/rpmsg_virtio.c rename to cores/arduino/stm32/OpenAMP/open-amp/rpmsg/rpmsg_virtio.c diff --git a/cores/arduino/stm32/virtio/openamp.c b/cores/arduino/stm32/OpenAMP/openamp.c similarity index 100% rename from cores/arduino/stm32/virtio/openamp.c rename to cores/arduino/stm32/OpenAMP/openamp.c diff --git a/cores/arduino/stm32/virtio/openamp.h b/cores/arduino/stm32/OpenAMP/openamp.h similarity index 100% rename from cores/arduino/stm32/virtio/openamp.h rename to cores/arduino/stm32/OpenAMP/openamp.h diff --git a/cores/arduino/stm32/virtio/openamp_conf.h b/cores/arduino/stm32/OpenAMP/openamp_conf.h similarity index 100% rename from cores/arduino/stm32/virtio/openamp_conf.h rename to cores/arduino/stm32/OpenAMP/openamp_conf.h diff --git a/cores/arduino/stm32/virtio/openamp_log.c b/cores/arduino/stm32/OpenAMP/openamp_log.c similarity index 100% rename from cores/arduino/stm32/virtio/openamp_log.c rename to cores/arduino/stm32/OpenAMP/openamp_log.c diff --git a/cores/arduino/stm32/virtio/openamp_log.h b/cores/arduino/stm32/OpenAMP/openamp_log.h similarity index 100% rename from cores/arduino/stm32/virtio/openamp_log.h rename to cores/arduino/stm32/OpenAMP/openamp_log.h diff --git a/cores/arduino/stm32/virtio/rsc_table.c b/cores/arduino/stm32/OpenAMP/rsc_table.c similarity index 100% rename from cores/arduino/stm32/virtio/rsc_table.c rename to cores/arduino/stm32/OpenAMP/rsc_table.c diff --git a/cores/arduino/stm32/virtio/rsc_table.h b/cores/arduino/stm32/OpenAMP/rsc_table.h similarity index 100% rename from cores/arduino/stm32/virtio/rsc_table.h rename to cores/arduino/stm32/OpenAMP/rsc_table.h diff --git a/cores/arduino/stm32/virtio/virt_uart.c b/cores/arduino/stm32/OpenAMP/virt_uart.c similarity index 100% rename from cores/arduino/stm32/virtio/virt_uart.c rename to cores/arduino/stm32/OpenAMP/virt_uart.c diff --git a/cores/arduino/stm32/virtio/virtio/virtio.c b/cores/arduino/stm32/OpenAMP/virtio/virtio.c similarity index 100% rename from cores/arduino/stm32/virtio/virtio/virtio.c rename to cores/arduino/stm32/OpenAMP/virtio/virtio.c diff --git a/cores/arduino/stm32/virtio/virtio/virtqueue.c b/cores/arduino/stm32/OpenAMP/virtio/virtqueue.c similarity index 100% rename from cores/arduino/stm32/virtio/virtio/virtqueue.c rename to cores/arduino/stm32/OpenAMP/virtio/virtqueue.c diff --git a/cores/arduino/stm32/virtio/virtio_buffer.c b/cores/arduino/stm32/OpenAMP/virtio_buffer.c similarity index 100% rename from cores/arduino/stm32/virtio/virtio_buffer.c rename to cores/arduino/stm32/OpenAMP/virtio_buffer.c diff --git a/cores/arduino/stm32/virtio/virtio_buffer.h b/cores/arduino/stm32/OpenAMP/virtio_buffer.h similarity index 100% rename from cores/arduino/stm32/virtio/virtio_buffer.h rename to cores/arduino/stm32/OpenAMP/virtio_buffer.h diff --git a/cores/arduino/stm32/virtio/virtio_config.h b/cores/arduino/stm32/OpenAMP/virtio_config.h similarity index 100% rename from cores/arduino/stm32/virtio/virtio_config.h rename to cores/arduino/stm32/OpenAMP/virtio_config.h From acc2416123ef1c3ca56d9ad3a533b55e9ec1186c Mon Sep 17 00:00:00 2001 From: Alexandre Bourdiol Date: Fri, 31 Jan 2020 15:57:35 +0100 Subject: [PATCH 24/24] Rephrase 'virtio' Arduino menu to be more explicit --- boards.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/boards.txt b/boards.txt index dc9b4f3244..0204feb39a 100644 --- a/boards.txt +++ b/boards.txt @@ -1602,11 +1602,11 @@ Eval.menu.xserial.none.build.xSerial=-DHAL_UART_MODULE_ENABLED -DHWSERIAL_NONE Eval.menu.xserial.disabled=Disabled (no Serial support) Eval.menu.xserial.disabled.build.xSerial= -STM32MP1.menu.virtio.disable=Disabled (no /dev/ttyRPMSG0 available) +STM32MP1.menu.virtio.disable=Disabled (no SerialVirtIO nor /dev/ttyRPMSG0 available) STM32MP1.menu.virtio.disable.build.enable_virtio= -STM32MP1.menu.virtio.generic=/dev/ttyRPMSG0 => 'Serial' supersede U(S)ART +STM32MP1.menu.virtio.generic=SerialVirtIO (= generic 'Serial') <=> /dev/ttyRPMSG0 STM32MP1.menu.virtio.generic.build.enable_virtio={build.virtio_flags} -STM32MP1.menu.virtio.enabled=/dev/ttyRPMSG0 => SerialVirtIO +STM32MP1.menu.virtio.enabled=SerialVirtIO <=> /dev/ttyRPMSG0 STM32MP1.menu.virtio.enabled.build.enable_virtio={build.virtio_flags} -DDISABLE_GENERIC_SERIALVIRTIO STM32MP1.menu.xserial.generic=UART only (generic 'Serial')