Skip to content

Commit

Permalink
Add wait loop after upload-reset instead of fixed delay
Browse files Browse the repository at this point in the history
  • Loading branch information
hanyazou committed Oct 22, 2017
1 parent 8905517 commit 0c9aab8
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions tools/macosx/maple_upload
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash

MAXWAITCOUNT=40 # about 4000ms

set -e

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

# ----------------- IMPORTANT -----------------
# The 2nd parameter to upload-reset is the delay after resetting before it exits
# This value is in milliseonds
# You may need to tune this to your system
# 750ms to 1500ms seems to work on my Mac

${DIR}/upload-reset ${dummy_port_fullpath} 750
${DIR}/upload-reset ${dummy_port_fullpath}

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

# wait for the DFU device after upload-reset command reboot target
COUNTER=0
while ! ${DFU_UTIL} -d ${usbID} -l | grep -e '^Found DFU: ' && ((COUNTER++ < ${MAXWAITCOUNT})); do
sleep 0.1
done
if ((${MAXWAITCOUNT} <= $COUNTER)); then
echo "$0: error: cannot find ${usbID}" >&2
exit 2
fi

${DFU_UTIL} -d ${usbID} -a ${altID} -D ${binfile} -R ${dfuse_addr} -R

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

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

Expand Down

0 comments on commit 0c9aab8

Please sign in to comment.