Skip to content

Commit

Permalink
Updated linux stlink_upload
Browse files Browse the repository at this point in the history
  • Loading branch information
rogerclarkmelbourne committed May 5, 2015
1 parent e7e552f commit 5916e8c
Showing 1 changed file with 45 additions and 1 deletion.
46 changes: 45 additions & 1 deletion tools/linux/stlink_upload
Original file line number Diff line number Diff line change
@@ -1,2 +1,46 @@

#!/bin/bash
$(dirname $0)/stlink/st-flash write "$4" 0x8000000

# Check for leaf device.
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
}

# 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"

# Check to see if a maple compatible board is attached
LEAF_STATUS=$(leaf_status)
echo "USB Status [$LEAF_STATUS]"

$(dirname $0)/stlink/st-flash write "$4" 0x8000000

sleep 4
# Reset the usb device to bring up the tty rather than DFU
"$USBRESET" "/dev/bus/usb/$(lsusb |grep "1eaf" |awk '{print $2,$4}'|sed 's/\://g'|sed 's/ /\//g')" >/dev/null 2>&1
# Check to see if a maple compatible board is attached
LEAF_STATUS=$(leaf_status)
echo "USB Status [$LEAF_STATUS]"
# Check to see if the tty came up
TTY_DEV=$(find /dev -cmin -2 |grep ttyAC)
echo -e "Waiting for tty device $TTY_DEV \n"
sleep 20
echo -e "$TTY_DEV should now be available.\n"
exit 0

1 comment on commit 5916e8c

@RickKimball
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This script fails now as it has an extra line at the beginning now. This causes an error:

/mnt/vbox/shared/Arduino_STM32_Sketch/hardware/Arduino_STM32/tools/linux/stlink_upload: 5: /mnt/vbox/shared/Arduino_STM32_Sketch/hardware/Arduino_STM32/tools/linux/stlink_upload: Syntax error: "(" unexpected

http://stackoverflow.com/questions/12910744/why-should-the-shebang-line-always-be-the-first-line

Please sign in to comment.