Skip to content

Commit acb6d26

Browse files
committed
[maple_upload] Improve script on linux
This makes it possible to recover if upload-reset isn't working, for example if a board is running a sketch without USB CDC enabled Changes: * Uncomment `set -e` * Ask the user to manually reset their device if upload-reset fails * Retry dfu-util if no device is found * Print periods while waiting for serial port * Exit with an error if script times out while waiting for serial port * Send all messages to STDERR
1 parent c67dd1d commit acb6d26

File tree

1 file changed

+33
-7
lines changed

1 file changed

+33
-7
lines changed

linux/maple_upload.sh

+33-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
#set -e
3+
set -e
44

55
if [ $# -lt 4 ]; then
66
echo "Usage: $0 $# <dummy_port> <altID> <usbID> <binfile>" >&2
@@ -24,16 +24,42 @@ DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
2424
# This value is in milliseonds
2525
# You may need to tune this to your system
2626
# 750ms to 1500ms seems to work on my Mac
27+
# This is less critical now that we automatically retry dfu-util
2728

28-
"${DIR}/upload-reset" "${dummy_port_fullpath}" 750
29+
if ! "${DIR}/upload-reset" "${dummy_port_fullpath}" 750
30+
then
31+
echo "****************************************" >&2
32+
echo "* Could not automatically reset device *" >&2
33+
echo "* Please manually reset device! *" >&2
34+
echo "****************************************" >&2
35+
sleep 2 # Wait for user to see message.
36+
fi
2937

30-
"${DIR}/dfu-util.sh" -d "${usbID}" -a "${altID}" -D "${binfile}" ${dfuse_addr} -R
38+
COUNTER=10
39+
while "${DIR}/dfu-util.sh" -d "${usbID}" -a "${altID}" -D "${binfile}" ${dfuse_addr} -R ; ((ret=$?))
40+
do
41+
if [ $ret -eq 74 ] && [ $((--COUNTER)) -gt 0 ]
42+
then
43+
# I/O error, probably because no DFU device was found
44+
echo "Trying ${COUNTER} more time(s)" >&2
45+
sleep 1
46+
else
47+
exit $ret
48+
fi
49+
done
3150

32-
echo -n Waiting for "${dummy_port_fullpath}" serial...
51+
echo -n "Waiting for ${dummy_port_fullpath} serial..." >&2
3352

34-
COUNTER=0
35-
while [ ! -r "${dummy_port_fullpath}" ] && ((COUNTER++ < 40)); do
53+
COUNTER=40
54+
while [ ! -r "${dummy_port_fullpath}" ] && ((COUNTER--)); do
55+
echo -n "." >&2
3656
sleep 0.1
3757
done
3858

39-
echo Done
59+
if [ $COUNTER -eq -1 ]
60+
then
61+
echo " Timed out." >&2
62+
exit 1
63+
else
64+
echo " Done." >&2
65+
fi

0 commit comments

Comments
 (0)