From 3d12b7066d27b591e0283e20ed066bc66e29fbe4 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Fri, 10 Nov 2023 21:34:40 -0700 Subject: refactor checkpoint: splitting MCU-specific code into arch/$MCU.[ch] Phew, that's a lot of changes! And there's still a lot more to do... --- bin/detect-mcu.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'bin') diff --git a/bin/detect-mcu.sh b/bin/detect-mcu.sh index 57670e2..93b624b 100755 --- a/bin/detect-mcu.sh +++ b/bin/detect-mcu.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env sh +#!/usr/bin/env bash # Anduril / FSM MCU type detection script # Copyright (C) 2014-2023 Selene ToyKeeper # SPDX-License-Identifier: GPL-3.0-or-later @@ -30,7 +30,7 @@ while [ -n "$TARGET" ]; do NUM=$( echo "$MCU" | sed 's/^avr//; s/^attiny//;' ) echo "export MCUNAME=${MCU}" echo "export MCU=0x${NUM}" - echo "export ATTINY=${NUM}" + [[ "$MCU" =~ "attiny" ]] && echo "export ATTINY=${NUM}" echo "export MCUFLAGS=\"-DMCUNAME=${MCU} -DMCU=0x${NUM} -DATTINY=${NUM}\"" exit fi -- cgit v1.2.3 From 486dd5543653b342fe64c0e5b1fcd342f0a02dbb Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Sun, 19 Nov 2023 01:53:59 -0700 Subject: added *unfinished* support for avr32dd20, plus a build target for a dev kit ADC doesn't work yet. No voltage, no temperature. I need to do a lot of refactoring on the ADC code. :( --- bin/flash-avr32dd20.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100755 bin/flash-avr32dd20.sh (limited to 'bin') diff --git a/bin/flash-avr32dd20.sh b/bin/flash-avr32dd20.sh new file mode 100755 index 0000000..ef8b0f3 --- /dev/null +++ b/bin/flash-avr32dd20.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +set -e + +[[ -z "$1" ]] && echo "No .hex file specified." && exit 1 +HEX="$1" + +#pymcuprog ping -t uart -u /dev/ttyUSB2 -d avr32dd20 +#pymcuprog erase -t uart -u /dev/ttyUSB2 -d avr32dd20 +#pymcuprog write verify -t uart -u /dev/ttyUSB2 -d avr32dd20 -f "$HEX" +#pymcuprog verify -t uart -u /dev/ttyUSB2 -d avr32dd20 -f "$HEX" + +pymcuprog write --erase --verify --timing -t uart -u /dev/ttyUSB2 -d avr32dd20 -f "$HEX" -- cgit v1.2.3 From 957a40fab65553842743f3c178afadcb5bb5c698 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Sun, 19 Nov 2023 01:55:01 -0700 Subject: added dac-scale.py: short script to calculate avrdd DAC+Vref values from level_calc.py ramp data --- bin/dac-scale.py | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100755 bin/dac-scale.py (limited to 'bin') diff --git a/bin/dac-scale.py b/bin/dac-scale.py new file mode 100755 index 0000000..d57f8c9 --- /dev/null +++ b/bin/dac-scale.py @@ -0,0 +1,89 @@ +#!/usr/bin/env python + +# +# Calculates DAC values and Vref values from a list of raw intensity values +# Usage: dac-scale.py 5,11,18,25,...,370474,384985,400000 +# Output: #defines suitable for use in hw/*/anduril.h +# Assumptions: +# - DAC data range is 0 to 1023 +# - DAC Vrefs are 1.024V and 2.5V +# - HDR is available and has 2 steps +# - HDR channel ratio is "highest_ramp_value / 2500" +# +# Output values thus have 4 "engine gears": +# - HDR low , 1.024V Vref +# - HDR low , 2.5 V Vref +# - HDR high, 1.024V Vref +# - HDR high, 2.5 V Vref +# + +def main(args): + max_pwm = 1023 + raw_pwm = [int(x) for x in args[0].split(',')] + ratio = raw_pwm[-1] / 2500.0 + cooked = [[]] + + def limit(p): + return min(max_pwm, int(p)) + + phase = 0 + for raw in raw_pwm: + if 0 == phase: + if raw <= 1023: + cooked[-1].append(limit(raw)) + else: + phase += 1 + cooked.append([]) + if 1 == phase: + if raw <= int(2500): + cooked[-1].append(limit(raw * 1.024 / 2.5)) + else: + phase += 1 + cooked.append([]) + if 2 == phase: + if raw <= int(1024 * ratio): + cooked[-1].append(limit(raw / ratio)) + else: + phase += 1 + cooked.append([]) + if 3 == phase: + cooked[-1].append(limit(raw * 1.024 / 2.5 / ratio)) + + # "gear change" boundaries + b1 = len(cooked[0]) + b2 = b1 + len(cooked[1]) + b3 = b2 + len(cooked[2]) + b4 = b3 + len(cooked[3]) + + #print(','.join(['%4i' % n for n in cooked])) + + def fmt_pwms(l): + return ','.join(['%4i' % n for n in l]) + + def fmt_tops(v, l): + return ','.join([' %s' % v for n in l]) + + lines = [] + + lines.append('// top level for each "gear": %i %i %i %i' % (b1, b2, b3, b4)) + + lines.append('#define PWM1_LEVELS \\') + lines.append(' ' + fmt_pwms(cooked[0]) + ', \\') + lines.append(' ' + fmt_pwms(cooked[1]) + ', \\') + lines.append(' ' + fmt_pwms(cooked[2]) + ', \\') + lines.append(' ' + fmt_pwms(cooked[3])) + lines.append('#define PWM2_LEVELS \\') + lines.append(' ' + fmt_tops('V10', cooked[0]) + ', \\') + lines.append(' ' + fmt_tops('V25', cooked[1]) + ', \\') + lines.append(' ' + fmt_tops('V10', cooked[2]) + ', \\') + lines.append(' ' + fmt_tops('V25', cooked[3])) + + lines.append('#define MAX_1x7135 %3i' % b2) + lines.append('#define HDR_ENABLE_LEVEL_MIN %3i' % (b2+1)) + + print('\n'.join(lines)) + +if __name__ == "__main__": + import sys + main(sys.argv[1:]) + -- cgit v1.2.3 From fdac6fcf22cd658785480c88c28243eeae62bcd0 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Thu, 30 Nov 2023 09:16:13 -0700 Subject: made the avr32dd20 flashing script more universal --- bin/flash-avr32dd20.sh | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) (limited to 'bin') diff --git a/bin/flash-avr32dd20.sh b/bin/flash-avr32dd20.sh index ef8b0f3..dcd4967 100755 --- a/bin/flash-avr32dd20.sh +++ b/bin/flash-avr32dd20.sh @@ -1,13 +1,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" -#pymcuprog ping -t uart -u /dev/ttyUSB2 -d avr32dd20 -#pymcuprog erase -t uart -u /dev/ttyUSB2 -d avr32dd20 -#pymcuprog write verify -t uart -u /dev/ttyUSB2 -d avr32dd20 -f "$HEX" -#pymcuprog verify -t uart -u /dev/ttyUSB2 -d avr32dd20 -f "$HEX" +# 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" +echo pymcuprog write \ + --erase \ + --verify \ + --timing \ + -t uart \ + -u "$TTYUSB" \ + -d "$MCUTYPE" \ + -f "$HEX" -pymcuprog write --erase --verify --timing -t uart -u /dev/ttyUSB2 -d avr32dd20 -f "$HEX" -- cgit v1.2.3