Skip to content

Commit 727f0dd

Browse files
committed
[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. OpenAMP/open-amp#182 As workaround, run_arduino.sh script will send "DUMMY" data right after the Arduino firmware loaded. The Arduino should discard the first message.
1 parent 2c479b9 commit 727f0dd

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

cores/arduino/VirtIOSerial.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ void serialEventVirtIO() __attribute__((weak));
3333

3434
static VIRT_UART_HandleTypeDef huart;
3535
static bool initialized = false;
36+
static bool first_message_discarded = false;
3637
static ringbuffer_t ring;
3738

3839
void rxCallback(VIRT_UART_HandleTypeDef *huart);
@@ -53,6 +54,7 @@ void VirtIOSerial::begin(void)
5354
Error_Handler();
5455
}
5556
initialized = true;
57+
first_message_discarded = false;
5658
}
5759

5860
void VirtIOSerial::begin(uint32_t /* baud_count */)
@@ -150,6 +152,15 @@ void VirtIOSerial::flush(void)
150152
void rxCallback(VIRT_UART_HandleTypeDef *huart)
151153
{
152154
log_info("Msg received on VIRTUAL UART0 channel: %s \n\r", (char *) huart->pRxBuffPtr);
155+
// Linux host must send a dummy data first to finish initialization of rpmsg
156+
// on the coprocessor side. This message should be discarded.
157+
// run_arduino_gen.sh script will send dummy data: "DUMMY".
158+
// See: https://github.com/OpenAMP/open-amp/issues/182
159+
// See: run_arduino_gen.sh
160+
if (!first_message_discarded) {
161+
huart->RxXferSize = 0;
162+
first_message_discarded = true;
163+
}
153164

154165
/* copy received msg in a variable to sent it back to master processor in main infinite loop*/
155166
size_t size = min(huart->RxXferSize, ringbuffer_write_available(&ring));

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy