annotate LoadFile/load.dfu @ 449:45feb80a2ad1

Major USB update, fixes most (if not all) known issues USB - General - Refactored descriptors - Enabled/Disable USB endpoints - Added debug flags for special features - Code cleanup - Interface count calculation based off of enabled endpoints - Delayed wTotalLength calculation to simplify descriptor offsets - Re-ordered endpoints and interfaces - Added more debug output - Added usbInitTime to show how long keyboard initialization took (Useful when debugging bad init sequences) - Added function for usb_resume() which takes care of the resume sequence * Resume is now only called if packets are starting to timeout USB - Special Options - Added enableDeviceRestartOnUSBTimeout * A last resort hammer for bad USB Chipsets/OSs, don't use if you can help it * Disabled - Added enableUSBResume * Enables host resume wake-up signalling, required to wake a computer from sleep * Enabled - Added enableUSBLowPowerNegotiation * Enables power negotiation hack * Required to use firmware with an IPad and other hard-limit low-power USB hosts * Hasn't been tested with the recent changes * Disabled - Added enableUSBSuspend * Enables power down events on host USB bus suspend * Enabled USB - Keyboard - Attempted to cleanup HID SET_REPORT * Works much better * Still has an issue under Linux which generates *a lot* of NAKs (initializes quickly regardless) + Not present on other keyboards + SETUP -> OUT -> IN : This sequence is the problem + Specifically during the OUT phase - Enabled USB - CDC Virtual Serial Port - Code cleanup - Added convenience struct USBCDCLineCoding for easier debugging - Attempted to cleanup CDC_SET_LING_CODING * Works much better * Still has an issue under Linux which generates *a lot* of NAKs (initializes quickly regardless) + SETUP -> OUT -> IN : This sequence is the problem + Specifically during the OUT phase + Likely the same issues as HID SET_REPORT - Enabled USB - Mouse - Enabled USB - Joystick - Disabled USB - RawIO - Initial code, API not used yet - Disabled DFU - Updated load script, now faster
author Jacob Alexander <haata@kiibohd.com>
date Tue, 31 May 2016 00:19:45 -0700
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: 297
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 dfu type device
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
3 # By default, initiates dfu-util
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
4
449
45feb80a2ad1 Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents: 401
diff changeset
5 SERIAL_PORT="/dev/kiibohd"
45feb80a2ad1 Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents: 401
diff changeset
6 AUTO_SCREEN_SESSION="/dev/kiibohd"
45feb80a2ad1 Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents: 401
diff changeset
7 NOSCREEN=0
276
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
8 PROG_NAME=$(basename $0)
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
9
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
10 # Parse all the command line arguments
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
11 while (( "$#" >= "1" )); do
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
12 # Scan each argument
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
13 key="$1"
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
14 case $key in
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
15 -a|--autoscreen)
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
16 AUTO_SCREEN_SESSION="$2"
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
17 shift
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
18 ;;
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
19 -f|--fastload)
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
20 SERIAL_PORT="$2"
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
21 shift
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
22 ;;
449
45feb80a2ad1 Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents: 401
diff changeset
23 -n|--noscreen)
45feb80a2ad1 Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents: 401
diff changeset
24 NOSCREEN=1
45feb80a2ad1 Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents: 401
diff changeset
25 shift
45feb80a2ad1 Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents: 401
diff changeset
26 ;;
276
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
27 -h|--help)
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
28 echo "Usage: $PROG_NAME [options...]"
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
29 echo ""
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
30 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
31 echo " (load.dfu)"
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
32 echo ""
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
33 echo "Arguments:"
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
34 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
35 echo " e.g. /dev/ttyACM0"
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
36 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
37 echo " e.g. /dev/ttyACM0"
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
38 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
39 echo " -h, --help This message."
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
40 exit 1
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
41 ;;
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 echo "INVALID ARG: '$1'"
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
44 exit 2
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
45 ;;
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
46 esac
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
47
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
48 # Shift to the next argument
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
49 shift
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
50 done
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
51
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
52 # 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
53 # 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
54 if [[ "$SERIAL_PORT" != "" ]] && [[ -e "$SERIAL_PORT" ]]; then
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
55 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
56 printf "reload\r" > $SERIAL_PORT
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
57 fi
207
8b11031e38a7 Adding convenience loader scripts for DFU based microcontrollers
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
58
8b11031e38a7 Adding convenience loader scripts for DFU based microcontrollers
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
59 # Load via dfu-util
8b11031e38a7 Adding convenience loader scripts for DFU based microcontrollers
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
60 # Used for McHCK based uCs
281
71882cd1c362 Check for needed programs
Rowan Decker <Smasher816@gmail.com>
parents: 276
diff changeset
61 if type dfu-util &>/dev/null; then
449
45feb80a2ad1 Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents: 401
diff changeset
62 # Wait for device to appear
45feb80a2ad1 Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents: 401
diff changeset
63 while true; do
45feb80a2ad1 Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents: 401
diff changeset
64 dfu-util -l | grep -q "Kiibohd DFU"
45feb80a2ad1 Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents: 401
diff changeset
65 if [ $? -eq 0 ]; then
45feb80a2ad1 Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents: 401
diff changeset
66 break
45feb80a2ad1 Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents: 401
diff changeset
67 fi
45feb80a2ad1 Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents: 401
diff changeset
68 sleep 0.1
45feb80a2ad1 Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents: 401
diff changeset
69 done
281
71882cd1c362 Check for needed programs
Rowan Decker <Smasher816@gmail.com>
parents: 276
diff changeset
70 dfu-util -D @TARGET_BIN@
71882cd1c362 Check for needed programs
Rowan Decker <Smasher816@gmail.com>
parents: 276
diff changeset
71 EXIT_STATUS=$?
71882cd1c362 Check for needed programs
Rowan Decker <Smasher816@gmail.com>
parents: 276
diff changeset
72 else
71882cd1c362 Check for needed programs
Rowan Decker <Smasher816@gmail.com>
parents: 276
diff changeset
73 echo "dfu-util is required to reprogram the device"
71882cd1c362 Check for needed programs
Rowan Decker <Smasher816@gmail.com>
parents: 276
diff changeset
74 exit 3
71882cd1c362 Check for needed programs
Rowan Decker <Smasher816@gmail.com>
parents: 276
diff changeset
75 fi
207
8b11031e38a7 Adding convenience loader scripts for DFU based microcontrollers
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
76
276
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
77 # Load Screen Session if specified
449
45feb80a2ad1 Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents: 401
diff changeset
78 if (( "$EXIT_STATUS" == "0" )) && [[ "$AUTO_SCREEN_SESSION" != "" ]] && [[ $NOSCREEN -ne 1 ]]; then
281
71882cd1c362 Check for needed programs
Rowan Decker <Smasher816@gmail.com>
parents: 276
diff changeset
79 if type screen &>/dev/null; then
449
45feb80a2ad1 Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents: 401
diff changeset
80 # Wait for interface
45feb80a2ad1 Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents: 401
diff changeset
81 while [ ! -e $AUTO_SCREEN_SESSION ]; do
45feb80a2ad1 Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents: 401
diff changeset
82 sleep 0.1
45feb80a2ad1 Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents: 401
diff changeset
83 done
281
71882cd1c362 Check for needed programs
Rowan Decker <Smasher816@gmail.com>
parents: 276
diff changeset
84 screen $AUTO_SCREEN_SESSION
71882cd1c362 Check for needed programs
Rowan Decker <Smasher816@gmail.com>
parents: 276
diff changeset
85 else
71882cd1c362 Check for needed programs
Rowan Decker <Smasher816@gmail.com>
parents: 276
diff changeset
86 echo "screen is not installed"
71882cd1c362 Check for needed programs
Rowan Decker <Smasher816@gmail.com>
parents: 276
diff changeset
87 exit 3
71882cd1c362 Check for needed programs
Rowan Decker <Smasher816@gmail.com>
parents: 276
diff changeset
88 fi
276
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
89 fi
207
8b11031e38a7 Adding convenience loader scripts for DFU based microcontrollers
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
90
276
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
91 exit $EXIT_STATUS
2a3468f5d8be Updating load scripts with command line arguments
Jacob Alexander <haata@kiibohd.com>
parents: 207
diff changeset
92