Skip to content

Commit 1902867

Browse files
committed
Add wait loop after upload-reset instead of fixed delay
1 parent 7e543fc commit 1902867

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

tools/macosx/maple_upload

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/bin/bash
22

3+
MAXWAITCOUNT=40 # about 4000ms
4+
35
set -e
46

57
if [ $# -lt 4 ]; then
@@ -25,13 +27,7 @@ DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
2527
#fi
2628
# ------------------ End of old code -----------------
2729

28-
# ----------------- IMPORTANT -----------------
29-
# The 2nd parameter to upload-reset is the delay after resetting before it exits
30-
# This value is in milliseonds
31-
# You may need to tune this to your system
32-
# 750ms to 1500ms seems to work on my Mac
33-
34-
${DIR}/upload-reset ${dummy_port_fullpath} 750
30+
${DIR}/upload-reset ${dummy_port_fullpath}
3531

3632
if [ $# -eq 5 ]; then
3733
dfuse_addr="--dfuse-address $5"
@@ -50,12 +46,22 @@ if [ ! -x ${DFU_UTIL} ]; then
5046
exit 2
5147
fi
5248

49+
# wait for the DFU device after upload-reset command reboot target
50+
COUNTER=0
51+
while ! ${DFU_UTIL} -d ${usbID} -l | grep -e '^Found DFU: ' && ((COUNTER++ < ${MAXWAITCOUNT})); do
52+
sleep 0.1
53+
done
54+
if ((${MAXWAITCOUNT} <= $COUNTER)); then
55+
echo "$0: error: cannot find ${usbID}" >&2
56+
exit 2
57+
fi
58+
5359
${DFU_UTIL} -d ${usbID} -a ${altID} -D ${binfile} -R ${dfuse_addr} -R
5460

5561
echo -n Waiting for ${dummy_port_fullpath} serial...
5662

5763
COUNTER=0
58-
while ! dd if=${dummy_port_fullpath} of=/dev/null count=0 > /dev/null 2>&1 && ((COUNTER++ < 40)); do
64+
while ! dd if=${dummy_port_fullpath} of=/dev/null count=0 > /dev/null 2>&1 && ((COUNTER++ < ${MAXWAITCOUNT})); do
5965
sleep 0.1
6066
done
6167

0 commit comments

Comments
 (0)