Skip to content

Commit 3f0c9a1

Browse files
committed
[VirtIO] Add virtual serial related commands
1 parent 5f224bc commit 3f0c9a1

File tree

3 files changed

+183
-3
lines changed

3 files changed

+183
-3
lines changed

linux/run_arduino_gen.sh

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
set -e
44

55
REMOTEPROC_DIR="/sys/class/remoteproc/remoteproc0"
6+
RPMSG_DIR="/dev/ttyRPMSG0"
67
ELF_NAME="arduino.ino.elf"
78
ELF_INSTALL_PATH="/lib/firmware/$ELF_NAME"
89
INSTALL_PATH="/usr/local/arduino/run_arduino.sh"
@@ -143,22 +144,48 @@ systemd_uninstall() {
143144
echo "File deleted: $INSTALL_PATH"
144145
}
145146

147+
try_send() {
148+
# Wait for /dev/ttyRPMSGx for 5 seconds, because the virtual device can be
149+
# created later depending on where Serial.begin() is located in the Arduino code.
150+
count=0
151+
while [ ! -c $RPMSG_DIR ]; do
152+
if [ $count -eq 2 ]; then
153+
echo "Waiting for virtual serial $RPMSG_DIR is created..."
154+
elif [ $count -ge 5 ]; then
155+
echo "No virtual serial $RPMSG_DIR is created."
156+
echo "If you didn't enable the virtual serial, ignore this message."
157+
return 0
158+
fi
159+
sleep 1;
160+
count=$(expr $count + 1)
161+
done
162+
# Linux host must send any dummy data first to finish initialization of rpmsg
163+
# on the coprocessor side. This message should be discarded.
164+
# See: https://github.com/OpenAMP/open-amp/issues/182
165+
echo "DUMMY" >$RPMSG_DIR
166+
echo "Virtual serial $RPMSG_DIR connection established."
167+
}
146168

147169
case "$1" in
148170
start)
149171
autodetect_board
150172
firmware_load
151173
firmware_stop
152174
firmware_start
175+
try_send
176+
echo "Arduino firmware started."
153177
;;
154178
stop)
155179
autodetect_board
156180
firmware_stop
181+
echo "Arduino firmware stopped."
157182
;;
158183
restart)
159184
autodetect_board
160185
firmware_stop
161186
firmware_start
187+
try_send
188+
echo "Arduino firmware restarted."
162189
;;
163190
install)
164191
autodetect_board
@@ -170,6 +197,23 @@ case "$1" in
170197
systemd_uninstall
171198
echo "Auto-start service $(basename $SYSTEMD_SERVICE_PATH) uninstalled."
172199
;;
200+
monitor)
201+
autodetect_board
202+
stty igncr onlcr -echo -F $RPMSG_DIR
203+
cat $RPMSG_DIR
204+
;;
205+
send-msg)
206+
autodetect_board
207+
echo "${@:2}" >$RPMSG_DIR
208+
;;
209+
send-file)
210+
autodetect_board
211+
dd if="$2" of=$RPMSG_DIR
212+
;;
213+
minicom)
214+
autodetect_board
215+
TERM=xterm minicom -D $RPMSG_DIR
216+
;;
173217
generate)
174218
generate_packaged_script $2 $3
175219
echo "$(readlink -f "$3") generated successfully."
@@ -179,7 +223,10 @@ case "$1" in
179223
echo " https://github.com/stm32duino/Arduino_Core_STM32/tree/master/variants/STM32MP157_DK/README.md"
180224
;;
181225
*)
182-
echo "Usage: $0 [start|stop|restart|generate|install|uninstall]"
226+
echo "Usage: $0 [start|stop|restart]"
227+
echo " $0 [install|uninstall]"
228+
echo " $0 [monitor|send-msg|send-file|minicom]"
229+
echo " $0 [generate]"
183230
echo ""
184231
echo "run_arduino.sh is a helper script that helps managing an Arduino binary"
185232
echo "file for the coprocessor using remoteproc framework."
@@ -199,6 +246,19 @@ case "$1" in
199246
echo "$0 uninstall"
200247
echo " Uninstall the autostart service."
201248
echo ""
249+
echo "$0 monitor"
250+
echo " Monitor data received from the coprocessor via RPMsg serial (VirtIOSerial)."
251+
echo " This command cannot send any data to the coprocessor."
252+
echo ""
253+
echo "$0 send-msg <message>"
254+
echo " Send a message to the coprocessor via RPMsg serial (VirtIOSerial)."
255+
echo ""
256+
echo "$0 send-file <filename>"
257+
echo " Send a file content to the coprocessor via RPMsg serial (VirtIOSerial)."
258+
echo ""
259+
echo "$0 minicom"
260+
echo " Launch minicom interactive serial communication program."
261+
echo ""
202262
echo "$0 stop"
203263
echo " Stop the coprocessor."
204264
echo ""

macosx/run_arduino_gen.sh

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
set -e
44

55
REMOTEPROC_DIR="/sys/class/remoteproc/remoteproc0"
6+
RPMSG_DIR="/dev/ttyRPMSG0"
67
ELF_NAME="arduino.ino.elf"
78
ELF_INSTALL_PATH="/lib/firmware/$ELF_NAME"
89
INSTALL_PATH="/usr/local/arduino/run_arduino.sh"
@@ -143,22 +144,48 @@ systemd_uninstall() {
143144
echo "File deleted: $INSTALL_PATH"
144145
}
145146

147+
try_send() {
148+
# Wait for /dev/ttyRPMSGx for 5 seconds, because the virtual device can be
149+
# created later depending on where Serial.begin() is located in the Arduino code.
150+
count=0
151+
while [ ! -c $RPMSG_DIR ]; do
152+
if [ $count -eq 2 ]; then
153+
echo "Waiting for virtual serial $RPMSG_DIR is created..."
154+
elif [ $count -ge 5 ]; then
155+
echo "No virtual serial $RPMSG_DIR is created."
156+
echo "If you didn't enable the virtual serial, ignore this message."
157+
return 0
158+
fi
159+
sleep 1;
160+
count=$(expr $count + 1)
161+
done
162+
# Linux host must send any dummy data first to finish initialization of rpmsg
163+
# on the coprocessor side. This message should be discarded.
164+
# See: https://github.com/OpenAMP/open-amp/issues/182
165+
echo "DUMMY" >$RPMSG_DIR
166+
echo "Virtual serial $RPMSG_DIR connection established."
167+
}
146168

147169
case "$1" in
148170
start)
149171
autodetect_board
150172
firmware_load
151173
firmware_stop
152174
firmware_start
175+
try_send
176+
echo "Arduino firmware started."
153177
;;
154178
stop)
155179
autodetect_board
156180
firmware_stop
181+
echo "Arduino firmware stopped."
157182
;;
158183
restart)
159184
autodetect_board
160185
firmware_stop
161186
firmware_start
187+
try_send
188+
echo "Arduino firmware restarted."
162189
;;
163190
install)
164191
autodetect_board
@@ -170,6 +197,23 @@ case "$1" in
170197
systemd_uninstall
171198
echo "Auto-start service $(basename $SYSTEMD_SERVICE_PATH) uninstalled."
172199
;;
200+
monitor)
201+
autodetect_board
202+
stty igncr onlcr -echo -F $RPMSG_DIR
203+
cat $RPMSG_DIR
204+
;;
205+
send-msg)
206+
autodetect_board
207+
echo "${@:2}" >$RPMSG_DIR
208+
;;
209+
send-file)
210+
autodetect_board
211+
dd if="$2" of=$RPMSG_DIR
212+
;;
213+
minicom)
214+
autodetect_board
215+
TERM=xterm minicom -D $RPMSG_DIR
216+
;;
173217
generate)
174218
generate_packaged_script $2 $3
175219
echo "$(readlink -f "$3") generated successfully."
@@ -179,7 +223,10 @@ case "$1" in
179223
echo " https://github.com/stm32duino/Arduino_Core_STM32/tree/master/variants/STM32MP157_DK/README.md"
180224
;;
181225
*)
182-
echo "Usage: $0 [start|stop|restart|generate|install|uninstall]"
226+
echo "Usage: $0 [start|stop|restart]"
227+
echo " $0 [install|uninstall]"
228+
echo " $0 [monitor|send-msg|send-file|minicom]"
229+
echo " $0 [generate]"
183230
echo ""
184231
echo "run_arduino.sh is a helper script that helps managing an Arduino binary"
185232
echo "file for the coprocessor using remoteproc framework."
@@ -199,6 +246,19 @@ case "$1" in
199246
echo "$0 uninstall"
200247
echo " Uninstall the autostart service."
201248
echo ""
249+
echo "$0 monitor"
250+
echo " Monitor data received from the coprocessor via RPMsg serial (VirtIOSerial)."
251+
echo " This command cannot send any data to the coprocessor."
252+
echo ""
253+
echo "$0 send-msg <message>"
254+
echo " Send a message to the coprocessor via RPMsg serial (VirtIOSerial)."
255+
echo ""
256+
echo "$0 send-file <filename>"
257+
echo " Send a file content to the coprocessor via RPMsg serial (VirtIOSerial)."
258+
echo ""
259+
echo "$0 minicom"
260+
echo " Launch minicom interactive serial communication program."
261+
echo ""
202262
echo "$0 stop"
203263
echo " Stop the coprocessor."
204264
echo ""

win/run_arduino_gen.sh

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
set -e
44

55
REMOTEPROC_DIR="/sys/class/remoteproc/remoteproc0"
6+
RPMSG_DIR="/dev/ttyRPMSG0"
67
ELF_NAME="arduino.ino.elf"
78
ELF_INSTALL_PATH="/lib/firmware/$ELF_NAME"
89
INSTALL_PATH="/usr/local/arduino/run_arduino.sh"
@@ -143,22 +144,48 @@ systemd_uninstall() {
143144
echo "File deleted: $INSTALL_PATH"
144145
}
145146

147+
try_send() {
148+
# Wait for /dev/ttyRPMSGx for 5 seconds, because the virtual device can be
149+
# created later depending on where Serial.begin() is located in the Arduino code.
150+
count=0
151+
while [ ! -c $RPMSG_DIR ]; do
152+
if [ $count -eq 2 ]; then
153+
echo "Waiting for virtual serial $RPMSG_DIR is created..."
154+
elif [ $count -ge 5 ]; then
155+
echo "No virtual serial $RPMSG_DIR is created."
156+
echo "If you didn't enable the virtual serial, ignore this message."
157+
return 0
158+
fi
159+
sleep 1;
160+
count=$(expr $count + 1)
161+
done
162+
# Linux host must send any dummy data first to finish initialization of rpmsg
163+
# on the coprocessor side. This message should be discarded.
164+
# See: https://github.com/OpenAMP/open-amp/issues/182
165+
echo "DUMMY" >$RPMSG_DIR
166+
echo "Virtual serial $RPMSG_DIR connection established."
167+
}
146168

147169
case "$1" in
148170
start)
149171
autodetect_board
150172
firmware_load
151173
firmware_stop
152174
firmware_start
175+
try_send
176+
echo "Arduino firmware started."
153177
;;
154178
stop)
155179
autodetect_board
156180
firmware_stop
181+
echo "Arduino firmware stopped."
157182
;;
158183
restart)
159184
autodetect_board
160185
firmware_stop
161186
firmware_start
187+
try_send
188+
echo "Arduino firmware restarted."
162189
;;
163190
install)
164191
autodetect_board
@@ -170,6 +197,23 @@ case "$1" in
170197
systemd_uninstall
171198
echo "Auto-start service $(basename $SYSTEMD_SERVICE_PATH) uninstalled."
172199
;;
200+
monitor)
201+
autodetect_board
202+
stty igncr onlcr -echo -F $RPMSG_DIR
203+
cat $RPMSG_DIR
204+
;;
205+
send-msg)
206+
autodetect_board
207+
echo "${@:2}" >$RPMSG_DIR
208+
;;
209+
send-file)
210+
autodetect_board
211+
dd if="$2" of=$RPMSG_DIR
212+
;;
213+
minicom)
214+
autodetect_board
215+
TERM=xterm minicom -D $RPMSG_DIR
216+
;;
173217
generate)
174218
generate_packaged_script $2 $3
175219
echo "$(readlink -f "$3") generated successfully."
@@ -179,7 +223,10 @@ case "$1" in
179223
echo " https://github.com/stm32duino/Arduino_Core_STM32/tree/master/variants/STM32MP157_DK/README.md"
180224
;;
181225
*)
182-
echo "Usage: $0 [start|stop|restart|generate|install|uninstall]"
226+
echo "Usage: $0 [start|stop|restart]"
227+
echo " $0 [install|uninstall]"
228+
echo " $0 [monitor|send-msg|send-file|minicom]"
229+
echo " $0 [generate]"
183230
echo ""
184231
echo "run_arduino.sh is a helper script that helps managing an Arduino binary"
185232
echo "file for the coprocessor using remoteproc framework."
@@ -199,6 +246,19 @@ case "$1" in
199246
echo "$0 uninstall"
200247
echo " Uninstall the autostart service."
201248
echo ""
249+
echo "$0 monitor"
250+
echo " Monitor data received from the coprocessor via RPMsg serial (VirtIOSerial)."
251+
echo " This command cannot send any data to the coprocessor."
252+
echo ""
253+
echo "$0 send-msg <message>"
254+
echo " Send a message to the coprocessor via RPMsg serial (VirtIOSerial)."
255+
echo ""
256+
echo "$0 send-file <filename>"
257+
echo " Send a file content to the coprocessor via RPMsg serial (VirtIOSerial)."
258+
echo ""
259+
echo "$0 minicom"
260+
echo " Launch minicom interactive serial communication program."
261+
echo ""
202262
echo "$0 stop"
203263
echo " Stop the coprocessor."
204264
echo ""

0 commit comments

Comments
 (0)