From 7abe8ebdbf67cb5149d3779c4d29d3dd0f3544e5 Mon Sep 17 00:00:00 2001 From: Roger Clark Date: Tue, 7 Apr 2015 08:50:06 +1000 Subject: [PATCH] Updated linux upload router with version from @ahull --- tools/linux/upload_router | 85 +++++++++++++++++++++++++++++---------- 1 file changed, 64 insertions(+), 21 deletions(-) diff --git a/tools/linux/upload_router b/tools/linux/upload_router index dbda037..b74244d 100755 --- a/tools/linux/upload_router +++ b/tools/linux/upload_router @@ -1,4 +1,3 @@ - #!/bin/bash # Translates the windows Arduino IDE upload call - something like.. # @@ -9,6 +8,27 @@ # dfu-util -D ./STM32_Blink.cpp.bin -d 1eaf:0003 --intf 0 --alt 1 # # + +function leaf_status() +{ + +this_leaf_status=$(lsusb |grep "1eaf" | awk '{ print $NF}') +# Find the mode of the leaf bootloader +case $this_leaf_status in + "1eaf:0003") + echo "dfu" + ;; + "1eaf:0004") + echo "ttyACMx" + ;; + *) + #echo "$this_leaf_status" + echo "unknown" + ;; +esac +} + + DEVICE="$3" # Lowercase the 1eaf device name, since in Windows land everybody shouts. DEVICE=${DEVICE,,} @@ -17,30 +37,57 @@ BINFILE="$4.bin" INTERFACE="$6" ALT_INTERFACE="$2" +# You will need the usb-reset code, see https://github.com/rogerclarkmelbourne/Arduino_STM32/wiki/Using-a-generic-stm32-board-on-linux-with-Maple-bootloader +# USBRESET=$(which usb-reset) || USBRESET="./usb-reset" -echo -e "\n\rPlease unplug and replug the USB cable to the STB device..." + +# Check to see if a maple compatible board is attached +LEAF_STATUS=$(leaf_status) + +# Borard not found, or no boot loader on board. +if [[ $(leaf_status) = "unknown" ]] +then + echo "STM32 Maple Bootloader compatible board not found." + sleep 5 + exit 1 +fi + +# We got this far, so we need to get the board in bootloader mode. +# After the timeout period, the board goes back in to serial mode, we need it in dfu mode, which happens for the first few seconds at power on +# so we ask the user to unplug and re-plug the board. +echo -e "\n\rSTM32 Maple board is in $LEAF_STATUS mode." + +echo "Please unplug and replug the USB cable to the Maple device." sleep 2 -while [[ $(lsusb |grep -i "1eaf") ]] +# On unplugging the board will be "unknown" +while [[ $(leaf_status) != "unknown" ]] +do + echo -n "." + sleep 1 +done +# On re-plugging the board will be "dfu" +while [[ $(leaf_status) != "dfu" ]] +do + echo -n "." + sleep 1 +done + +echo -e "\n\rProgramming STM32 device with dfu-util" +until dfu-util -D "$BINFILE" -d "$DEVICE" --intf "$INTERFACE" --alt "$ALT_INTERFACE" 2>&1 do echo -n "." sleep 1 done -until dfu-util -v -D "$BINFILE" -d "$DEVICE" --intf "$INTERFACE" --alt "$ALT_INTERFACE" -do - echo -n "." - sleep 1 -done - -echo -e "\n\rUnplug and replug the USB cable to the STM board again please...." -while [[ $(lsusb |grep -i "1eaf\:0003") ]] +echo -e "\n\rUnplug and replug the USB cable to the STM32 board again please...." +while [[ $(leaf_status) != "unknown" ]] do echo -n "." sleep 1 done echo -e "\n\rReconnecting" -while [ -z "$(lsusb |grep -i "1eaf\:0003")" ] +while [[ $(leaf_status) = "unknown" ]] do echo -n "." sleep 1 @@ -53,17 +100,13 @@ do sleep 1 done - "$USBRESET" "/dev/bus/usb/$(lsusb |grep "1eaf" |awk '{print $2,$4}'|sed 's/\://g'|sed 's/ /\//g')" >/dev/null 2>&1 -for i in {1..4} + +while [[ $(leaf_status) = "unknown" ]] do echo -n "." sleep 1 done - -echo -e "\n\rSerial port re-created... $(ls "/dev/ttyACM"*)\n\r" -for i in {1..4} -do - echo -n "." - sleep 1 -done \ No newline at end of file +THIS_TTY=$(find /dev/ttyACM* -cmin -2) +echo -e "\n\rSTM32 Maple board serial port re-created..." +echo -e "\n\rSerial port is $THIS_TTY Please allow 15 seconds before attempting to read from serial port."