annotate LoadFile/load.teensy @ 412:e7a3be42ae1e

Debug code for interconnect cable debugging
author Jacob Alexander <haata@kiibohd.com>
date Sat, 20 Feb 2016 13:27:49 -0800
parents 99f93dec8fea
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
401
99f93dec8fea Start removing select Linux-isms
Dan McGregor <dan.mcgregor@usask.ca>
parents: 307
diff changeset
1 #!/usr/bin/env bash
276
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
2 # Convenience script for loading firmware onto a teensy type device
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
3 # By default, initiates teensy-load-cli
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
4
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
5 SERIAL_PORT=""
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
6 AUTO_SCREEN_SESSION=""
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
7 PROG_NAME=$(basename $0)
207
8b11031e38a7 Adding convenience loader scripts for DFU based microcontrollers
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
8
276
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
9 # Parse all the command line arguments
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
10 while (( "$#" >= "1" )); do
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
11 # Scan each argument
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
12 key="$1"
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
13 case $key in
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
14 -a|--autoscreen)
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
15 AUTO_SCREEN_SESSION="$2"
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
16 shift
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
17 ;;
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
18 -f|--fastload)
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
19 SERIAL_PORT="$2"
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
20 shift
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
21 ;;
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
22 -h|--help)
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
23 echo "Usage: $PROG_NAME [options...]"
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
24 echo ""
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
25 echo "Loads the most recent built firmware (@TARGET_BIN@) to the device."
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
26 echo " (load.teensy)"
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
27 echo ""
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
28 echo "Arguments:"
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
29 echo " -a, --autoscreen SERIAL_PORT Use screen on the specified serial port after loading."
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
30 echo " e.g. /dev/ttyACM0"
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
31 echo " -f, --fastload SERIAL_PORT Send the reload command to the debug terminal."
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
32 echo " e.g. /dev/ttyACM0"
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
33 echo " NOTE: May not work due to non-functional terminal, or disable remote flashing"
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
34 echo " -h, --help This message."
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
35 exit 1
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
36 ;;
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
37 *)
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
38 echo "INVALID ARG: '$1'"
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
39 exit 2
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
40 ;;
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
41 esac
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
42
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
43 # Shift to the next argument
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
44 shift
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
45 done
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
46
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
47 # First check to see teensy-loader-cli has been compiled
207
8b11031e38a7 Adding convenience loader scripts for DFU based microcontrollers
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
48 if [ ! -e teensy-loader-cli/teensy-loader-cli ]; then
8b11031e38a7 Adding convenience loader scripts for DFU based microcontrollers
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
49 # Compile teensy-loader-cli
8b11031e38a7 Adding convenience loader scripts for DFU based microcontrollers
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
50 mkdir -p teensy-loader-cli
8b11031e38a7 Adding convenience loader scripts for DFU based microcontrollers
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
51 cd teensy-loader-cli
8b11031e38a7 Adding convenience loader scripts for DFU based microcontrollers
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
52 cmake -G "Unix Makefiles" @CMAKE_SOURCE_DIR@/LoadFile
281
71882cd1c362 Check for needed programs
Rowan Decker <Smasher816@gmail.com>
parents: 276
diff changeset
53 make || exit 3
207
8b11031e38a7 Adding convenience loader scripts for DFU based microcontrollers
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
54 cd -
8b11031e38a7 Adding convenience loader scripts for DFU based microcontrollers
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
55 fi
8b11031e38a7 Adding convenience loader scripts for DFU based microcontrollers
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
56
276
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
57 # If a SERIAL_PORT was specified set the uC into reflash mode
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
58 # XXX May not be successful if uC is not in a good state (or does not allow remote flashing)
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
59 if [[ "$SERIAL_PORT" != "" ]] && [[ -e "$SERIAL_PORT" ]]; then
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
60 echo "NOTE: This may fail if the uC is in a bad state or does not support remote flashing"
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
61 printf "reload\r" > $SERIAL_PORT
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
62 sleep 1
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
63 fi
207
8b11031e38a7 Adding convenience loader scripts for DFU based microcontrollers
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
64
276
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
65 # Loads the hex file onto the teensy
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
66 teensy-loader-cli/teensy-loader-cli -mmcu=@MCU@ -w @TARGET_HEX@
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
67 EXIT_STATUS=$?
207
8b11031e38a7 Adding convenience loader scripts for DFU based microcontrollers
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
68
276
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
69 # Load Screen Session if specified
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
70 if (( "$EXIT_STATUS" == "0" )) && [[ "$AUTO_SCREEN_SESSION" != "" ]]; then
281
71882cd1c362 Check for needed programs
Rowan Decker <Smasher816@gmail.com>
parents: 276
diff changeset
71 if type screen &>/dev/null; then
307
ecd2ae35d25c Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents: 281
diff changeset
72 sleep 2
281
71882cd1c362 Check for needed programs
Rowan Decker <Smasher816@gmail.com>
parents: 276
diff changeset
73 screen $AUTO_SCREEN_SESSION
71882cd1c362 Check for needed programs
Rowan Decker <Smasher816@gmail.com>
parents: 276
diff changeset
74 else
71882cd1c362 Check for needed programs
Rowan Decker <Smasher816@gmail.com>
parents: 276
diff changeset
75 echo "screen is not installed"
71882cd1c362 Check for needed programs
Rowan Decker <Smasher816@gmail.com>
parents: 276
diff changeset
76 exit 3
71882cd1c362 Check for needed programs
Rowan Decker <Smasher816@gmail.com>
parents: 276
diff changeset
77 fi
276
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
78 fi
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
79
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
80 exit $EXIT_STATUS
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
81