Skip to content

Commit

Permalink
Added script for updating through avrdude #featureadd
Browse files Browse the repository at this point in the history
  • Loading branch information
pyr0ball committed Oct 2, 2019
1 parent 4608808 commit 59649de
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions scripts/upload-firmware.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/bin/bash

read -r -d '' usage << EOF
upload-firmware.sh [-h] [-b] m328pb [-d] /dev/ttyUSB0||COM3 [-f] firmware.hex [-i] [-u] -- firmware upload script for Pyr0-Piezo AVR boards
Usage:
-h show this help text
-b Specify a board type. Default is m328pb. Other option is m88p
-d Specify a serial device
-f Specify a firmware file
-i Program over ICSP
-u Program over UART
EOF

# Default values
serialdevice=COM3
board=m328pb
lowfuse=0xE2
highfuse=0xD6
exfuse=0xF6
firmwarebin=Pyr0_Piezo_Sensor_m328pb_v2.x.x.hex

# Programming functions
program-icsp() {
avrdude -c avrisp -p $board -b19200 -P$serialdevice -U lfuse:w:$lowfuse:m -U hfuse:w:$highfuse:m -U efuse:w:$exfuse:m -U flash:w:$firmwarebin -v
}

program-uart() {
avrdude -c stk500v1 -p $board -b19200 -P$serialdevice -U flash:w:$firmwarebin -v
}

# Options parser

while getopts ":b:d:f:i:u" opt
do
case ${opt} in
h) echo "$usage"
exit
;;
b) board="$2";
shift ;;
d) serialdevice="$2";
shift ;;
f) firmwarebin="$2";
shift ;;
i) program-icsp
shift ;;
u) program-uart
shift ;;
\?) printf "illegal option: -%s\n" "$OPTARG" >&2
echo "$usage" >&2
exit 1
;;
esac
done
if [ $OPTIND == 1 ] ; then
program-icsp
fi
shift $((OPTIND - 1))

0 comments on commit 59649de

Please sign in to comment.