Skip to content

Commit

Permalink
[sw/image_gen] ✨ update UART upload script
Browse files Browse the repository at this point in the history
  • Loading branch information
stnolting committed Jun 11, 2024
1 parent 1724eae commit 86ada21
Showing 1 changed file with 24 additions and 19 deletions.
43 changes: 24 additions & 19 deletions sw/image_gen/uart_upload.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,22 @@ set -e

if [ $# -ne 2 ]
then
echo "Upload image via serial port (UART) to the NEORV32 bootloader."
echo "Reset processor before starting the upload."
echo "Usage: [sudo] sh uart_upload.sh <serial port> <NEORV32 executable>"
echo "Example: sudo sh uart_upload.sh /dev/ttyS6 path/to/project/neorv32_exe.bin"
printf "Upload and execute application image via serial port (UART) to the NEORV32 bootloader.\n"
printf "Reset processor before starting the upload.\n\n"
printf "Usage: sh uart_upload.sh <serial port> <NEORV32 executable>\n"
printf "Example: sh uart_upload.sh /dev/ttyS6 path/to/project/neorv32_exe.bin\n"
exit
fi

# configure serial port
stty -F "$1" 19200 -hup raw -echo -echoe -echok -echoctl -echoke -crtscts cs8 -cstopb noflsh clocal cread
stty -F "$1" 19200 -hup raw -echo -echoe -echok -echoctl -echoke -ixon cs8 -cstopb noflsh clocal cread

# trigger fast upload mode and get response
# abort autoboot sequence
printf " " > $1 # send any char that triggers no command

# execute upload command and get response
exec 3<$1 # redirect serial output to fd 3
cat <&3 > uart_upload.response.dat & # redirect serial output to file
cat <&3 > uart_upload.response.tmp & # redirect serial output to file
PID=$! # save pid to kill cat
printf "u" > $1 # send upload command to serial port
sleep 0.5s # wait for bootloader response
Expand All @@ -27,18 +30,18 @@ exec 3<$1 # redirect serial output to fd 3
exec 3<&- # free fd 3

# check response
if ! grep -Fq "Awaiting neorv32_exe.bin" uart_upload.response.dat;
if ! grep -Fq "Awaiting neorv32_exe.bin" uart_upload.response.tmp;
then
echo "Bootloader response error."
echo "Reset processor before starting the upload."
rm -f uart_upload.response.dat
printf "Bootloader response error!\n"
printf "Reset processor before starting the upload.\n"
rm -f uart_upload.response.tmp
exit
fi

# send executable and get response
echo -n "Uploading... "
printf "Uploading executable..."
exec 3<$1 # redirect serial output to fd 3
cat <&3 > uart_upload.response.dat & # redirect serial output to file
cat <&3 > uart_upload.response.tmp & # redirect serial output to file
PID=$! # save pid to kill cat
cat "$2" > "$1" # send executable to serial port
sleep 3s # wait for bootloader response
Expand All @@ -47,12 +50,14 @@ exec 3<$1 # redirect serial output to fd 3
exec 3<&- # free fd 3

# check response
if ! grep -Fq "OK" uart_upload.response.dat;
if ! grep -Fq "OK" uart_upload.response.tmp;
then
echo "Upload error."
rm -f uart_upload.response.dat
exit
printf " FAILED!\n"
else
printf " OK\n"
echo "Starting application..."
printf "e" > $1
fi

rm -f uart_upload.response.dat
echo "Done."
rm -f uart_upload.response.tmp
exit

0 comments on commit 86ada21

Please sign in to comment.