aboutsummaryrefslogtreecommitdiff
path: root/bin/flash-avr32dd20.sh
blob: a4faab81d1a0f91d1ebf07bda7e8a2f7d5035da5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env bash
# AVR firmware flashing script, a wrapper for other tools
# Copyright (C) 2023 Selene ToyKeeper
# SPDX-License-Identifier: GPL-3.0-or-later

# Usage: flash-MCUTYPE.sh hex/foo.hex
# (where the script name specifies the type of MCU chip,
#  and the first parameter is the path to a .hex file)
# Example:
#   ./bin/flash-avr32dd20.sh hex/anduril.thefreeman-avr32dd20-devkit.hex

set -e

# Get the path to a .hex file
[[ -z "$1" ]] && echo "No .hex file specified." && exit 1
HEX="$1"

# assume the highest-numbered USB serial device is the correct one,
# since it was probably the most recently plugged in
TTYUSB=$(ls -1 /dev/tty* | grep -i usb | tail -1)

# figure out the MCU type...
# TODO: find the relevant hw/*/arch file and use that to get MCU type
# use $2 if it exists, and use the name of this script maybe
MCUTYPE="unset"
[[ -n "$2" ]] && MCUTYPE="$2"
#MCUTYPE=$(echo "$0" | sed 's/.*flash-\(.*\).sh.*/\1/')
[[ "$0" =~ flash-(.*).sh ]] && MCUTYPE="${BASH_REMATCH[1]}"

# Do the actual flashing
echo "Flashing $MCUTYPE MCU on port $TTYUSB: $HEX"
pymcuprog write \
    --erase \
    --verify \
    --timing \
    -t uart \
    -u "$TTYUSB" \
    -d "$MCUTYPE" \
    -f "$HEX"