diff --git a/boards.txt b/boards.txt index c0f7f9f0ee..0204feb39a 100644 --- a/boards.txt +++ b/boards.txt @@ -5,6 +5,7 @@ menu.pnum=Board part number 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 @@ -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.disable=Disabled (no SerialVirtIO nor /dev/ttyRPMSG0 available) +STM32MP1.menu.virtio.disable.build.enable_virtio= +STM32MP1.menu.virtio.generic=SerialVirtIO (= generic 'Serial') <=> /dev/ttyRPMSG0 +STM32MP1.menu.virtio.generic.build.enable_virtio={build.virtio_flags} +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') STM32MP1.menu.xserial.generic.build.xSerial=-DHAL_UART_MODULE_ENABLED STM32MP1.menu.xserial.none=UART only (no generic 'Serial') diff --git a/cores/arduino/VirtIOSerial.cpp b/cores/arduino/VirtIOSerial.cpp new file mode 100644 index 0000000000..f35303c070 --- /dev/null +++ b/cores/arduino/VirtIOSerial.cpp @@ -0,0 +1,197 @@ +/** + * 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 "VirtIOSerial.h" +#if !defined(VIRTIOSERIAL_NUM) +#define VIRTIOSERIAL_NUM 1 +#endif + +VirtIOSerialObj_t *VirtIOSerial_Handle[VIRTIOSERIAL_NUM] = {NULL}; + +uint32_t VirtIOSerial::VirtIOSerial_index = 0; + +// Default instance +VirtIOSerial SerialVirtIO; + +void serialEventVirtIO() __attribute__((weak)); +VirtIOSerialObj_t *get_VirtIOSerial_obj(VIRT_UART_HandleTypeDef *huart); + +void VirtIOSerial::begin(void) +{ + virtio_buffer_init(&_VirtIOSerialObj.ring); + if (_VirtIOSerialObj.initialized) { + return; + } + if (OPENAMP_Init() != 0) { + Error_Handler(); + } + 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(&_VirtIOSerialObj.handle, VIRT_UART_RXCPLT_CB_ID, rxGenericCallback) != VIRT_UART_OK) { + Error_Handler(); + } + + VirtIOSerial_Handle[VirtIOSerial_index] = &_VirtIOSerialObj; + _VirtIOSerialObj.initialized = true; + _VirtIOSerialObj.first_message_discarded = false; +} + +void VirtIOSerial::begin(uint32_t /* baud_count */) +{ + // uart config is ignored in OpenAmp + begin(); +} + +void VirtIOSerial::begin(uint32_t /* baud_count */, uint8_t /* config */) +{ + // uart config is ignored in OpenAmp + begin(); +} + +void VirtIOSerial::end() +{ + OPENAMP_DeInit(); + virtio_buffer_init(&_VirtIOSerialObj.ring); + _VirtIOSerialObj.initialized = false; +} + +int VirtIOSerial::available(void) +{ + return virtio_buffer_read_available(&_VirtIOSerialObj.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 (virtio_buffer_read_available(&_VirtIOSerialObj.ring) > 0) { + uint8_t tmp; + virtio_buffer_peek(&_VirtIOSerialObj.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) +{ + 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; +} + +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(&_VirtIOSerialObj.handle, const_cast(buffer), size) == VIRT_UART_ERROR) { + // This error usually happens when rpmsg is not ready for + 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; +} + +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 (!_VirtIOSerialObj.first_message_discarded) { + huart->RxXferSize = 0; + _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(&_VirtIOSerialObj.ring)); + while (size > 0) { + size -= virtio_buffer_write(&_VirtIOSerialObj.ring, huart->pRxBuffPtr, 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 new file mode 100644 index 0000000000..02572f6692 --- /dev/null +++ b/cores/arduino/VirtIOSerial.h @@ -0,0 +1,82 @@ +/** + * 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" +#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); + 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); + + 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; + +#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/OpenAMP/libmetal/device.c b/cores/arduino/stm32/OpenAMP/libmetal/device.c new file mode 100644 index 0000000000..ad62849d0f --- /dev/null +++ b/cores/arduino/stm32/OpenAMP/libmetal/device.c @@ -0,0 +1,5 @@ +#ifdef VIRTIOCON + +#include "libmetal/lib/device.c" + +#endif /* VIRTIOCON */ diff --git a/cores/arduino/stm32/OpenAMP/libmetal/generic/condition.c b/cores/arduino/stm32/OpenAMP/libmetal/generic/condition.c new file mode 100644 index 0000000000..a8f7a7427d --- /dev/null +++ b/cores/arduino/stm32/OpenAMP/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/OpenAMP/libmetal/generic/cortexm/sys.c b/cores/arduino/stm32/OpenAMP/libmetal/generic/cortexm/sys.c new file mode 100644 index 0000000000..83f98dd29f --- /dev/null +++ b/cores/arduino/stm32/OpenAMP/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/OpenAMP/libmetal/generic/generic_device.c b/cores/arduino/stm32/OpenAMP/libmetal/generic/generic_device.c new file mode 100644 index 0000000000..85a97eef94 --- /dev/null +++ b/cores/arduino/stm32/OpenAMP/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/OpenAMP/libmetal/generic/generic_init.c b/cores/arduino/stm32/OpenAMP/libmetal/generic/generic_init.c new file mode 100644 index 0000000000..abdbe5cf12 --- /dev/null +++ b/cores/arduino/stm32/OpenAMP/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/OpenAMP/libmetal/generic/generic_io.c b/cores/arduino/stm32/OpenAMP/libmetal/generic/generic_io.c new file mode 100644 index 0000000000..d1fcb36feb --- /dev/null +++ b/cores/arduino/stm32/OpenAMP/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/OpenAMP/libmetal/generic/generic_shmem.c b/cores/arduino/stm32/OpenAMP/libmetal/generic/generic_shmem.c new file mode 100644 index 0000000000..75be24b343 --- /dev/null +++ b/cores/arduino/stm32/OpenAMP/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/OpenAMP/libmetal/generic/time.c b/cores/arduino/stm32/OpenAMP/libmetal/generic/time.c new file mode 100644 index 0000000000..917e7b88bc --- /dev/null +++ b/cores/arduino/stm32/OpenAMP/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/OpenAMP/libmetal/init.c b/cores/arduino/stm32/OpenAMP/libmetal/init.c new file mode 100644 index 0000000000..e7ddd67304 --- /dev/null +++ b/cores/arduino/stm32/OpenAMP/libmetal/init.c @@ -0,0 +1,5 @@ +#ifdef VIRTIOCON + +#include "libmetal/lib/init.c" + +#endif /* VIRTIOCON */ diff --git a/cores/arduino/stm32/OpenAMP/libmetal/io.c b/cores/arduino/stm32/OpenAMP/libmetal/io.c new file mode 100644 index 0000000000..902aca060e --- /dev/null +++ b/cores/arduino/stm32/OpenAMP/libmetal/io.c @@ -0,0 +1,5 @@ +#ifdef VIRTIOCON + +#include "libmetal/lib/io.c" + +#endif /* VIRTIOCON */ diff --git a/cores/arduino/stm32/OpenAMP/libmetal/log.c b/cores/arduino/stm32/OpenAMP/libmetal/log.c new file mode 100644 index 0000000000..03eff42dc6 --- /dev/null +++ b/cores/arduino/stm32/OpenAMP/libmetal/log.c @@ -0,0 +1,5 @@ +#ifdef VIRTIOCON + +#include "libmetal/lib/log.c" + +#endif /* VIRTIOCON */ diff --git a/cores/arduino/stm32/OpenAMP/libmetal/shmem.c b/cores/arduino/stm32/OpenAMP/libmetal/shmem.c new file mode 100644 index 0000000000..83b2e508a1 --- /dev/null +++ b/cores/arduino/stm32/OpenAMP/libmetal/shmem.c @@ -0,0 +1,5 @@ +#ifdef VIRTIOCON + +#include "libmetal/lib/shmem.c" + +#endif /* VIRTIOCON */ diff --git a/cores/arduino/stm32/OpenAMP/mbox_ipcc.c b/cores/arduino/stm32/OpenAMP/mbox_ipcc.c new file mode 100644 index 0000000000..c957bc6979 --- /dev/null +++ b/cores/arduino/stm32/OpenAMP/mbox_ipcc.c @@ -0,0 +1,166 @@ +/** + ****************************************************************************** + * @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: + * virtio_rpmsg_bus.c rpmsg_virtio.c + * ======== <-- new msg ---=============--------<------ ======= + * || || rvq (rx) || CHANNEL 1 || svq (tx_vq) || || + * || A7 || ------->-------=============--- buf free--> || M4 || + * || || || || + * ||master|| <-- buf free---=============--------<------ ||slave|| + * || || svq (tx) || CHANNEL 2 || rvq (rx_vq) || || + * ======== ------->-------=============----new msg --> ======= + */ + +/* Includes ------------------------------------------------------------------*/ +#include "virtio_config.h" +#include "openamp/open_amp.h" +#include "stm32_def.h" +#include "openamp_conf.h" + +/* 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 ---------------------------------------------------------*/ +IPCC_HandleTypeDef hipcc; +extern struct rpmsg_virtio_device rvdev; + + + + +/* 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) { + Error_Handler(); + return -1; + } + + if (HAL_IPCC_ActivateNotification(&hipcc, IPCC_CHANNEL_2, IPCC_CHANNEL_DIR_RX, + IPCC_channel2_callback) != HAL_OK) { + Error_Handler(); + return -1; + } + + return 0; +} + +/** + * @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; + } else if (id == VRING1_ID) { + /* Note: the OpenAMP framework never notifies this */ + channel = IPCC_CHANNEL_2; + return -1; + } else { + 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) { + // 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; +} + +/** + * @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) +{ + /* Inform A7 that we have received the 'buff free' msg */ + 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) +{ + (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); +} + +/** + * @brief This function handles IPCC RX1 occupied interrupt. + */ +void IPCC_RX1_IRQHandler(void) +{ + HAL_IPCC_RX_IRQHandler(&hipcc); +} + +#endif /* VIRTIOCON */ +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/cores/arduino/stm32/OpenAMP/mbox_ipcc.h b/cores/arduino/stm32/OpenAMP/mbox_ipcc.h new file mode 100644 index 0000000000..34fe831e99 --- /dev/null +++ b/cores/arduino/stm32/OpenAMP/mbox_ipcc.h @@ -0,0 +1,42 @@ +/** + ****************************************************************************** + * @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 + +/* Includes ------------------------------------------------------------------*/ +/* Exported types ------------------------------------------------------------*/ +/* Exported constants --------------------------------------------------------*/ +/* Exported functions ------------------------------------------------------- */ +int MAILBOX_Init(void); +int MAILBOX_Notify(void *priv, uint32_t id); +void MAILBOX_Notify_Rx_Buf_Free(void); + +#endif /* VIRTIOCON */ +#endif /* MBOX_IPCC_H_ */ diff --git a/cores/arduino/stm32/OpenAMP/open-amp/remoteproc/remoteproc_virtio.c b/cores/arduino/stm32/OpenAMP/open-amp/remoteproc/remoteproc_virtio.c new file mode 100644 index 0000000000..c829226b93 --- /dev/null +++ b/cores/arduino/stm32/OpenAMP/open-amp/remoteproc/remoteproc_virtio.c @@ -0,0 +1,6 @@ +#ifdef VIRTIOCON + +#include "virtio_config.h" +#include "open-amp/lib/remoteproc/remoteproc_virtio.c" + +#endif /* VIRTIOCON */ diff --git a/cores/arduino/stm32/OpenAMP/open-amp/rpmsg/rpmsg.c b/cores/arduino/stm32/OpenAMP/open-amp/rpmsg/rpmsg.c new file mode 100644 index 0000000000..11b66787ff --- /dev/null +++ b/cores/arduino/stm32/OpenAMP/open-amp/rpmsg/rpmsg.c @@ -0,0 +1,6 @@ +#ifdef VIRTIOCON + +#include "virtio_config.h" +#include "open-amp/lib/rpmsg/rpmsg.c" + +#endif /* VIRTIOCON */ diff --git a/cores/arduino/stm32/OpenAMP/open-amp/rpmsg/rpmsg_virtio.c b/cores/arduino/stm32/OpenAMP/open-amp/rpmsg/rpmsg_virtio.c new file mode 100644 index 0000000000..8a89668a05 --- /dev/null +++ b/cores/arduino/stm32/OpenAMP/open-amp/rpmsg/rpmsg_virtio.c @@ -0,0 +1,6 @@ +#ifdef VIRTIOCON + +#include "virtio_config.h" +#include "open-amp/lib/rpmsg/rpmsg_virtio.c" + +#endif /* VIRTIOCON */ diff --git a/cores/arduino/stm32/OpenAMP/openamp.c b/cores/arduino/stm32/OpenAMP/openamp.c new file mode 100644 index 0000000000..2b291122b3 --- /dev/null +++ b/cores/arduino/stm32/OpenAMP/openamp.c @@ -0,0 +1,170 @@ +/** + ****************************************************************************** + * @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 "virtio_config.h" +#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; +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() +{ + struct fw_rsc_vdev_vring *vring_rsc; + struct virtio_device *vdev; + int status = 0; + + MAILBOX_Init(); + + /* Libmetal Initilalization */ + status = OPENAMP_shmem_init(RPMSG_REMOTE); + if (status) { + return status; + } + + vdev = rproc_virtio_create_vdev(RPMSG_REMOTE, 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, NULL, 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_Wait_EndPointready(struct rpmsg_endpoint *rp_ept) +{ + while (!is_rpmsg_ept_ready(rp_ept)); +} + +#endif /* VIRTIOCON */ +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/cores/arduino/stm32/OpenAMP/openamp.h b/cores/arduino/stm32/OpenAMP/openamp.h new file mode 100644 index 0000000000..b42e895e3c --- /dev/null +++ b/cores/arduino/stm32/OpenAMP/openamp.h @@ -0,0 +1,60 @@ +/** + ****************************************************************************** + * @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(void); + +/* 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); + +/* 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/OpenAMP/openamp_conf.h b/cores/arduino/stm32/OpenAMP/openamp_conf.h new file mode 100644 index 0000000000..19d87de7a1 --- /dev/null +++ b/cores/arduino/stm32/OpenAMP/openamp_conf.h @@ -0,0 +1,239 @@ +/** + ****************************************************************************** + * @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 + +#include "virtio_config.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#if defined (__LOG_TRACE_IO_) || defined(__LOG_UART_IO_) +#include "openamp_log.h" +#endif + +/* ########################## Mailbox Interface Selection ############################## */ +/** + * @brief This is the list of Mailbox interface to be used in the OpenAMP MW + * Please note that not all interfaces are supported by a STM32 device + */ +#define MAILBOX_IPCC_IF_ENABLED +//#define MAILBOX_HSEM_IF_ENABLED + +/* Includes ------------------------------------------------------------------*/ +/** + * @brief Include 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 */ + +/** @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/OpenAMP/openamp_log.c b/cores/arduino/stm32/OpenAMP/openamp_log.c new file mode 100644 index 0000000000..e2368c2242 --- /dev/null +++ b/cores/arduino/stm32/OpenAMP/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/OpenAMP/openamp_log.h b/cores/arduino/stm32/OpenAMP/openamp_log.h new file mode 100644 index 0000000000..06475dcd47 --- /dev/null +++ b/cores/arduino/stm32/OpenAMP/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/OpenAMP/rsc_table.c b/cores/arduino/stm32/OpenAMP/rsc_table.c new file mode 100644 index 0000000000..1d5ec3da29 --- /dev/null +++ b/cores/arduino/stm32/OpenAMP/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 (STM32MP1xx) +#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 (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) + */ +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 (STM32MP1xx) +.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 (STM32MP1xx) +#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/OpenAMP/rsc_table.h b/cores/arduino/stm32/OpenAMP/rsc_table.h new file mode 100644 index 0000000000..60dd5e4edb --- /dev/null +++ b/cores/arduino/stm32/OpenAMP/rsc_table.h @@ -0,0 +1,49 @@ +/* + * 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 "virtio_config.h" +#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_ */ diff --git a/cores/arduino/stm32/OpenAMP/virt_uart.c b/cores/arduino/stm32/OpenAMP/virt_uart.c new file mode 100644 index 0000000000..3b86748c66 --- /dev/null +++ b/cores/arduino/stm32/OpenAMP/virt_uart.c @@ -0,0 +1,6 @@ +#ifdef VIRTIOCON + +#include "virtio_config.h" +#include "virtual_driver/virt_uart.c" + +#endif /* VIRTIOCON */ diff --git a/cores/arduino/stm32/OpenAMP/virtio/virtio.c b/cores/arduino/stm32/OpenAMP/virtio/virtio.c new file mode 100644 index 0000000000..2e7ec33eae --- /dev/null +++ b/cores/arduino/stm32/OpenAMP/virtio/virtio.c @@ -0,0 +1,6 @@ +#ifdef VIRTIOCON + +#include "virtio_config.h" +#include "open-amp/lib/virtio/virtio.c" + +#endif /* VIRTIOCON */ diff --git a/cores/arduino/stm32/OpenAMP/virtio/virtqueue.c b/cores/arduino/stm32/OpenAMP/virtio/virtqueue.c new file mode 100644 index 0000000000..150a7d06d3 --- /dev/null +++ b/cores/arduino/stm32/OpenAMP/virtio/virtqueue.c @@ -0,0 +1,6 @@ +#ifdef VIRTIOCON + +#include "virtio_config.h" +#include "open-amp/lib/virtio/virtqueue.c" + +#endif /* VIRTIOCON */ diff --git a/cores/arduino/stm32/OpenAMP/virtio_buffer.c b/cores/arduino/stm32/OpenAMP/virtio_buffer.c new file mode 100644 index 0000000000..b6643f2688 --- /dev/null +++ b/cores/arduino/stm32/OpenAMP/virtio_buffer.c @@ -0,0 +1,130 @@ +/** + * 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 "virtio_config.h" +#include "virtio_buffer.h" +#include +#include "wiring.h" + +void virtio_buffer_init(virtio_buffer_t *ring) +{ + ring->write_index = 0; + ring->read_index = 0; +} + +uint16_t virtio_buffer_read_available(virtio_buffer_t *ring) +{ + int32_t delta = ring->write_index - ring->read_index; + + if (delta < 0) { + return (VIRTIO_BUFFER_SIZE + delta); + } + 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) +{ + 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); + } + + // Update read index if not peeked + if (!peek) { + ring->read_index += size; + + // Manage ring buffer rollover + if (ring->read_index >= VIRTIO_BUFFER_SIZE) { + ring->read_index -= VIRTIO_BUFFER_SIZE; + } + } + return size; +} + +uint16_t virtio_buffer_read(virtio_buffer_t *ring, uint8_t *dst, uint16_t size) +{ + return read(ring, dst, size, false); +} + + +uint16_t virtio_buffer_peek(virtio_buffer_t *ring, uint8_t *dst, uint16_t size) +{ + return read(ring, dst, size, true); +} + + + +uint16_t virtio_buffer_write_available(virtio_buffer_t *ring) +{ + int32_t delta = ring->read_index - ring->write_index - 1; + + if (delta < 0) { + return (VIRTIO_BUFFER_SIZE + delta); + } + 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) +{ + 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; +} + +#endif /* VIRTIOCON */ diff --git a/cores/arduino/stm32/OpenAMP/virtio_buffer.h b/cores/arduino/stm32/OpenAMP/virtio_buffer.h new file mode 100644 index 0000000000..bc17e63348 --- /dev/null +++ b/cores/arduino/stm32/OpenAMP/virtio_buffer.h @@ -0,0 +1,54 @@ +/** + * 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_BUFFER_H +#define __VIRTIO_BUFFER_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define VIRTIO_BUFFER_SIZE (RPMSG_BUFFER_SIZE * 2) + +typedef struct { + uint8_t buffer[VIRTIO_BUFFER_SIZE]; + volatile uint16_t write_index; + volatile uint16_t read_index; +} virtio_buffer_t; + +void virtio_buffer_init(virtio_buffer_t *ring); + +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 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_VIRTIO_BUFFER_H diff --git a/cores/arduino/stm32/OpenAMP/virtio_config.h b/cores/arduino/stm32/OpenAMP/virtio_config.h new file mode 100644 index 0000000000..4271d559cc --- /dev/null +++ b/cores/arduino/stm32/OpenAMP/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 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 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. 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_ */