Skip to content

Commit 666b5b3

Browse files
Updated stlink_upload script for Linux to enhanced code from @ahull
1 parent 4f9a83e commit 666b5b3

1 file changed

Lines changed: 44 additions & 1 deletion

File tree

tools/linux/serial_upload

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,45 @@
11
#!/bin/bash
2-
$(dirname $0)/stm32flash/stm32flash -g 0x8000000 -b 230400 -w "$4" /dev/"$1"
2+
3+
# Check for leaf device.
4+
function leaf_status()
5+
{
6+
7+
this_leaf_status=$(lsusb |grep "1eaf" | awk '{ print $NF}')
8+
# Find the mode of the leaf bootloader
9+
case $this_leaf_status in
10+
"1eaf:0003")
11+
echo "dfu"
12+
;;
13+
"1eaf:0004")
14+
echo "ttyACMx"
15+
;;
16+
*)
17+
#echo "$this_leaf_status"
18+
echo "unknown"
19+
;;
20+
esac
21+
}
22+
23+
# 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
24+
#
25+
USBRESET=$(which usb-reset) || USBRESET="./usb-reset"
26+
27+
# Check to see if a maple compatible board is attached
28+
LEAF_STATUS=$(leaf_status)
29+
echo "USB Status [$LEAF_STATUS]"
30+
31+
$(dirname $0)/stlink/st-flash write "$4" 0x8000000
32+
33+
sleep 4
34+
# Reset the usb device to bring up the tty rather than DFU
35+
"$USBRESET" "/dev/bus/usb/$(lsusb |grep "1eaf" |awk '{print $2,$4}'|sed 's/\://g'|sed 's/ /\//g')" >/dev/null 2>&1
36+
# Check to see if a maple compatible board is attached
37+
LEAF_STATUS=$(leaf_status)
38+
echo "USB Status [$LEAF_STATUS]"
39+
# Check to see if the tty came up
40+
TTY_DEV=$(find /dev -cmin -2 |grep ttyAC)
41+
echo -e "Waiting for tty device $TTY_DEV \n"
42+
sleep 20
43+
echo -e "$TTY_DEV should now be available.\n"
44+
exit 0
45+

0 commit comments

Comments
 (0)