2 # Convenience script for loading firmware onto a teensy type device
3 # By default, initiates teensy-load-cli
7 PROG_NAME=$(basename $0)
9 # Parse all the command line arguments
10 while (( "$#" >= "1" )); do
15 AUTO_SCREEN_SESSION="$2"
23 echo "Usage: $PROG_NAME [options...]"
25 echo "Loads the most recent built firmware (@TARGET_BIN@) to the device."
29 echo " -a, --autoscreen SERIAL_PORT Use screen on the specified serial port after loading."
30 echo " e.g. /dev/ttyACM0"
31 echo " -f, --fastload SERIAL_PORT Send the reload command to the debug terminal."
32 echo " e.g. /dev/ttyACM0"
33 echo " NOTE: May not work due to non-functional terminal, or disable remote flashing"
34 echo " -h, --help This message."
38 echo "INVALID ARG: '$1'"
43 # Shift to the next argument
47 # First check to see teensy-loader-cli has been compiled
48 if [ ! -e teensy-loader-cli/teensy-loader-cli ]; then
49 # Compile teensy-loader-cli
50 mkdir -p teensy-loader-cli
52 cmake -G "Unix Makefiles" @CMAKE_SOURCE_DIR@/LoadFile
57 # If a SERIAL_PORT was specified set the uC into reflash mode
58 # XXX May not be successful if uC is not in a good state (or does not allow remote flashing)
59 if [[ "$SERIAL_PORT" != "" ]] && [[ -e "$SERIAL_PORT" ]]; then
60 echo "NOTE: This may fail if the uC is in a bad state or does not support remote flashing"
61 printf "reload\r" > $SERIAL_PORT
65 # Loads the hex file onto the teensy
66 teensy-loader-cli/teensy-loader-cli -mmcu=@MCU@ -w @TARGET_HEX@
69 # Load Screen Session if specified
70 if (( "$EXIT_STATUS" == "0" )) && [[ "$AUTO_SCREEN_SESSION" != "" ]]; then
71 if type screen &>/dev/null; then
73 screen $AUTO_SCREEN_SESSION
75 echo "screen is not installed"