Adding stm32 auto-upload scripts for Windows, Mac, and Linux (#184)

This commit is contained in:
Ben Lye
2018-08-16 09:29:47 +01:00
committed by GitHub
parent 1dc52773f4
commit 685de52538
11 changed files with 234 additions and 8 deletions

View File

@@ -0,0 +1,45 @@
#!/bin/bash
#set -e
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
}
# Get the directory where the script is running.
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
# Check to see if a maple compatible board is attached
LEAF_STATUS=$(leaf_status)
# Board not found, or no boot loader on board.
if [[ $(leaf_status) = "unknown" ]]
then
# No maple board detected
echo "Maple device not found. Attempting serial upload."
SERIAL_UPLOAD=${DIR}/serial_upload_inc_bootloader
echo "${SERIAL_UPLOAD}" $1 0x8000000 $2 $3
"${SERIAL_UPLOAD}" $1 0x8000000 $2 $3
else
# Maple board detected
echo "Maple device found. Attempting USB upload."
MAPLE_UPLOAD=${DIR}/maple_upload
echo "${MAPLE_UPLOAD}" $1 2 1eaf:0003 $2
"${MAPLE_UPLOAD}" $1 2 1eaf:0003 $2
fi

View File

@@ -37,6 +37,8 @@ fi
"${RESET_UTIL}" ${dummy_port_fullpath} 750
# Give the board a chance to reset to DFU mode
sleep 0.5
#DFU_UTIL=$(dirname $0)/dfu-util/dfu-util
DFU_UTIL=/usr/bin/dfu-util

View File

@@ -1,5 +1,5 @@
ATTRS{idProduct}=="1001", ATTRS{idVendor}=="0110", MODE="664", GROUP="plugdev"
ATTRS{idProduct}=="1002", ATTRS{idVendor}=="0110", MODE="664", GROUP="plugdev"
ATTRS{idProduct}=="0003", ATTRS{idVendor}=="1eaf", MODE="664", GROUP="plugdev" SYMLINK+="maple"
ATTRS{idProduct}=="0004", ATTRS{idVendor}=="1eaf", MODE="664", GROUP="plugdev" SYMLINK+="maple"
ATTRS{idProduct}=="0003", ATTRS{idVendor}=="1eaf", MODE="664", GROUP="plugdev" SYMLINK+="maple", ENV{ID_MM_DEVICE_IGNORE}="1"
ATTRS{idProduct}=="0004", ATTRS{idVendor}=="1eaf", MODE="664", GROUP="plugdev" SYMLINK+="maple", ENV{ID_MM_DEVICE_IGNORE}="1"

View File

@@ -0,0 +1,67 @@
#!/bin/bash
shopt -s extglob
function list_usb()
{
while IFS=: read key value; do
key="${key##+( )}"
value="${value##+( )}"
case "$key" in
"Product ID")
p="${value% *}"
;;
"Vendor ID")
v="${value%% *}"
;;
"Manufacturer")
m="${value}"
;;
"Location ID")
l="${value}"
printf "%s:%s %s (%s)\n" "$v" "$p" "$l" "$m"
;;
esac
done < <( system_profiler SPUSBDataType )
}
function leaf_status()
{
this_leaf_status=$(echo "$(list_usb)" | grep "1eaf" | awk '{ print $1}')
# Find the mode of the leaf bootloader
case $this_leaf_status in
"0x1eaf:0x0003")
echo "dfu"
;;
"0x1eaf:0x0004")
echo "ttyACMx"
;;
*)
# echo "$this_leaf_status"
echo "unknown"
;;
esac
}
# Get the directory where the script is running.
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
# Check to see if a maple compatible board is attached
LEAF_STATUS=$(leaf_status)
# Board not found, or no boot loader on board.
if [[ $(leaf_status) = "unknown" ]]
then
# No maple board detected
echo "Maple device not found. Attempting serial upload."
SERIAL_UPLOAD=${DIR}/serial_upload_inc_bootloader
echo "${SERIAL_UPLOAD}" $1 0x8000000 $2 $3
"${SERIAL_UPLOAD}" $1 0x8000000 $2 $3
else
# Maple board detected
echo "Maple device found. Attempting USB upload."
MAPLE_UPLOAD=${DIR}/maple_upload
echo "${MAPLE_UPLOAD}" $1 2 1eaf:0003 $2
"${MAPLE_UPLOAD}" $1 2 1eaf:0003 $2
fi

View File

@@ -33,6 +33,9 @@ DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
${DIR}/upload-reset ${dummy_port_fullpath} 750
# Give the board a chance to reset to DFU mode
sleep 0.5
if [ $# -eq 5 ]; then
dfuse_addr="--dfuse-address $5"
else

View File

@@ -0,0 +1,69 @@
@echo off
REM Script to automatically select upload method for stm32-based multi-protocol module.
set driverLetter=%~dp0
set driverLetter=%driverLetter:~0,2%
%driverLetter%
cd %~dp0
set comport=%1
set fwpath=%2
set fwpath=%fwpath:/=\%
set blpath=%3
set blpath=%blpath:/=\%
:MAPLE_CHECK
REM Look for a Maple USB device
ECHO.
ECHO Looking for Maple device ...
maple_find.exe
ECHO.
if %errorlevel% equ 0 (
GOTO USB_FLASH
) else (
GOTO FTDI_CHECK
)
:USB_FLASH
ECHO Attempting to flash module via Maple USB ...
ECHO java -jar maple_loader.jar %comport% 2 "1EAF:0003" "%fwpath%"
java -jar maple_loader.jar %comport% 2 "1EAF:0003" "%fwpath%"
ECHO.
ECHO Done.
ECHO.
GOTO :EOF
:FTDI_CHECK
REM Attempt to read from the STM module via the specified serial port
ECHO Probing serial port %comport% for STM32 in BOOT0 mode ...
stm32flash.exe -b 115200 %comport%
if %errorlevel% equ 0 (
ECHO Found module on %comport%
GOTO FTDI_FLASH
) ELSE (
ECHO Module in BOOT0 mode not found on %comport%
GOTO :EOF
)
:FTDI_FLASH
ECHO.
ECHO Flashing module via FTDI adapter on %comport%
ECHO.
ECHO Erasing ...
ECHO stm32flash.exe -o -b 115200 %comport%
stm32flash.exe -o -b 115200 %comport%
ECHO Writing bootloader ...
ECHO stm32flash.exe -v -g 0x8000000 -b 115200 -w %blpath% %comport%
stm32flash.exe -v -g 0x8000000 -b 115200 -w %blpath% %comport%
ECHO Writing Multi firmware ...
ECHO stm32flash.exe -v -s 8 -e 0 -g 0x8002000 -b 115200 -w %fwpath% %comport%
stm32flash.exe -v -s 8 -e 0 -g 0x8002000 -b 115200 -w %fwpath% %comport%
ECHO.
ECHO Done.
GOTO :EOF

Binary file not shown.