├── .gitignore ├── rebootor ├── Makefile ├── rebootor.elf ├── rebootor.c ├── usb.h ├── rebootor.hex └── usb.c ├── blink_slow.ino ├── Makefile.bsd ├── freebsd-teensy.conf ├── Makefile ├── README.md ├── blink_slow_Teensy2pp.hex ├── blink_slow_Teensy2.hex ├── blink_slow_TeensyLC.hex ├── blink_slow_Teensy30.hex ├── blink_slow_Teensy32.hex ├── blink_slow_Teensy35.hex ├── blink_slow_Teensy36.hex └── blink_slow_Teensy40.hex /.gitignore: -------------------------------------------------------------------------------- 1 | teensy_loader_cli 2 | teensy_loader_cli.exe* 3 | *.swp 4 | -------------------------------------------------------------------------------- /rebootor/Makefile: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PaulStoffregen/teensy_loader_cli/HEAD/rebootor/Makefile -------------------------------------------------------------------------------- /rebootor/rebootor.elf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PaulStoffregen/teensy_loader_cli/HEAD/rebootor/rebootor.elf -------------------------------------------------------------------------------- /blink_slow.ino: -------------------------------------------------------------------------------- 1 | // Simple LED blink 2 | 3 | const int led = LED_BUILTIN; 4 | 5 | void setup() { 6 | pinMode(led, OUTPUT); 7 | } 8 | 9 | void loop() { 10 | digitalWrite(led, HIGH); 11 | delay(1000); 12 | digitalWrite(led, LOW); 13 | delay(1000); 14 | } 15 | 16 | -------------------------------------------------------------------------------- /Makefile.bsd: -------------------------------------------------------------------------------- 1 | OS ?= FreeBSD 2 | #OS ?= NetBSD 3 | #OS ?= OpenBSD 4 | 5 | CFLAGS ?= -O2 -Wall 6 | CC ?= gcc 7 | 8 | .if $(OS) == "FreeBSD" 9 | CFLAGS += -DUSE_LIBUSB 10 | LIBS = -lusb 11 | .elif $(OS) == "NetBSD" || $(OS) == "OpenBSD" 12 | CFLAGS += -DUSE_UHID 13 | LIBS = 14 | .endif 15 | 16 | 17 | teensy_loader_cli: teensy_loader_cli.c 18 | $(CC) $(CFLAGS) -s -o teensy_loader_cli teensy_loader_cli.c $(LIBS) 19 | 20 | clean: 21 | rm -f teensy_loader_cli 22 | -------------------------------------------------------------------------------- /freebsd-teensy.conf: -------------------------------------------------------------------------------- 1 | # To make Teensy user-accessible in FreeBSD, it's necessary (as root) 2 | # to put the attached file in the directory /usr/local/etc/devd, and 3 | # then type "/etc/rc.d/devd restart". Then when the Teensy is 4 | # attached, the device will be readable/writable by everybody. 5 | # 6 | # contributed by George Mitchell, george at m5p dot com 7 | # 8 | # Change permissions for Teensy device 9 | notify 100 { 10 | match "system" "USB"; 11 | match "subsystem" "DEVICE"; 12 | match "type" "ATTACH"; 13 | match "vendor" "0x16c0"; 14 | match "product" "0x0478"; 15 | # Select appropriate action 16 | # action "chown YOURUSERNAME /dev/$cdev"; 17 | # action "chgrp YOURGROUPNAME /dev/$cdev"; 18 | action "chmod 666 /dev/$cdev"; 19 | }; 20 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | OS ?= LINUX 2 | #OS ?= WINDOWS 3 | #OS ?= MACOSX 4 | #OS ?= BSD 5 | 6 | # uncomment this to use libusb on Macintosh, instead of Apple's HID manager via IOKit 7 | # this is technically not the "correct" way to support Macs, but it's been reported to 8 | # work. 9 | #USE_LIBUSB ?= YES 10 | 11 | ifeq ($(OS), LINUX) # also works on FreeBSD 12 | CC ?= gcc 13 | CFLAGS ?= -O2 -Wall 14 | teensy_loader_cli: teensy_loader_cli.c 15 | $(CC) $(CFLAGS) $(CPPFLAGS) -s -DUSE_LIBUSB -o teensy_loader_cli teensy_loader_cli.c -lusb $(LDFLAGS) 16 | 17 | 18 | else ifeq ($(OS), WINDOWS) 19 | CC ?= i586-mingw32msvc-gcc 20 | CFLAGS ?= -O2 -Wall 21 | teensy_loader_cli.exe: teensy_loader_cli.c 22 | $(CC) $(CFLAGS) -s -DUSE_WIN32 -o teensy_loader_cli.exe teensy_loader_cli.c -lhid -lsetupapi -lwinmm 23 | 24 | 25 | else ifeq ($(OS), MACOSX) 26 | ifeq ($(USE_LIBUSB), YES) 27 | CC ?= gcc 28 | CFLAGS ?= -O2 -Wall 29 | teensy_loader_cli: teensy_loader_cli.c 30 | $(CC) $(CFLAGS) -s -DUSE_LIBUSB -DMACOSX -o teensy_loader_cli teensy_loader_cli.c -lusb -I /usr/local/include -L/usr/local/lib 31 | 32 | else 33 | CC ?= gcc 34 | SDK ?= $(shell xcrun --show-sdk-path) 35 | #SDK ?= /Developer/SDKs/MacOSX10.6.sdk # the old way... 36 | #SDK = /Developer_xcode32/SDKs/MacOSX10.5.sdk # the very old way! 37 | #CC = /Developer_xcode32/usr/bin/gcc-4.0 38 | #CFLAGS = -O2 -Wall -arch i386 -arch ppc 39 | CFLAGS ?= -O2 -Wall 40 | teensy_loader_cli: teensy_loader_cli.c 41 | ifeq ($(SDK),) 42 | $(error SDK was not found. To use this type of compilation please install Xcode) 43 | endif 44 | $(CC) $(CFLAGS) -DUSE_APPLE_IOKIT -isysroot $(SDK) -o teensy_loader_cli teensy_loader_cli.c -Wl,-syslibroot,$(SDK) -framework IOKit -framework CoreFoundation 45 | 46 | endif 47 | 48 | else ifeq ($(OS), BSD) # works on NetBSD and OpenBSD 49 | CC ?= gcc 50 | CFLAGS ?= -O2 -Wall 51 | teensy_loader_cli: teensy_loader_cli.c 52 | $(CC) $(CFLAGS) -s -DUSE_UHID -o teensy_loader_cli teensy_loader_cli.c 53 | 54 | 55 | endif 56 | 57 | 58 | clean: 59 | rm -f teensy_loader_cli teensy_loader_cli.exe* 60 | -------------------------------------------------------------------------------- /rebootor/rebootor.c: -------------------------------------------------------------------------------- 1 | /* Teensy Rebootor 2 | * http://www.pjrc.com/teensy 3 | * Copyright (c) 2010 PJRC.COM, LLC 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above description, website URL and copyright notice and this permission 13 | * notice shall be included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | * THE SOFTWARE. 22 | */ 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include "usb.h" 29 | 30 | #define CPU_PRESCALE(n) (CLKPR = 0x80, CLKPR = (n)) 31 | 32 | int main(void) 33 | { 34 | // set for 1 MHz clock 35 | CPU_PRESCALE(4); 36 | 37 | // set all pins as inputs with pullup resistors 38 | #if defined(PORTA) 39 | DDRF = 0; 40 | PORTF = 0xFF; 41 | #endif 42 | DDRB = 0; 43 | PORTB = 0xFF; 44 | DDRC = 0; 45 | PORTC = 0xFF; 46 | DDRD = 0; 47 | PORTD = 0xFF; 48 | #if defined(PORTE) 49 | DDRE = 0; 50 | PORTE = 0xFF; 51 | #endif 52 | #if defined(PORTF) 53 | DDRF = 0; 54 | PORTF = 0xFF; 55 | #endif 56 | 57 | // initialize USB 58 | usb_init(); 59 | 60 | // do nothing (USB code handles reboot message) 61 | while (1) { 62 | _delay_ms(1); 63 | // put the CPU into low power idle mode 64 | set_sleep_mode(SLEEP_MODE_IDLE); 65 | cli(); 66 | sleep_enable(); 67 | sei(); 68 | sleep_cpu(); 69 | sleep_disable(); 70 | } 71 | } 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /rebootor/usb.h: -------------------------------------------------------------------------------- 1 | #ifndef usb_serial_h__ 2 | #define usb_serial_h__ 3 | 4 | #include 5 | 6 | void usb_init(void); // initialize everything 7 | 8 | 9 | // Everything below this point is only intended for usb_serial.c 10 | #ifdef USB_PRIVATE_INCLUDE 11 | #include 12 | #include 13 | #include 14 | 15 | #define EP_TYPE_CONTROL 0x00 16 | #define EP_TYPE_BULK_IN 0x81 17 | #define EP_TYPE_BULK_OUT 0x80 18 | #define EP_TYPE_INTERRUPT_IN 0xC1 19 | #define EP_TYPE_INTERRUPT_OUT 0xC0 20 | #define EP_TYPE_ISOCHRONOUS_IN 0x41 21 | #define EP_TYPE_ISOCHRONOUS_OUT 0x40 22 | 23 | #define EP_SINGLE_BUFFER 0x02 24 | #define EP_DOUBLE_BUFFER 0x06 25 | 26 | #define EP_SIZE(s) ((s) > 32 ? 0x30 : \ 27 | ((s) > 16 ? 0x20 : \ 28 | ((s) > 8 ? 0x10 : \ 29 | 0x00))) 30 | 31 | #define MAX_ENDPOINT 4 32 | 33 | #define LSB(n) (n & 255) 34 | #define MSB(n) ((n >> 8) & 255) 35 | 36 | #if defined(__AVR_AT90USB162__) 37 | #define HW_CONFIG() 38 | #define PLL_CONFIG() (PLLCSR = ((1< : Specify Processor. You must specify the target processor. This syntax is the same as used by gcc, which makes integrating with your Makefile easier, we also now support passing in a logical name. Valid options are: 28 | --mcu=TEENSY2 Teensy 2.0 29 | --mcu=TEENSY2PP Teensy++ 2.0 30 | --mcu=TEENSYLC Teensy LC 31 | --mcu=TEENSY30 Teensy 3.0 32 | --mcu=TEENSY31 Teensy 3.1 33 | --mcu=TEENSY32 Teensy 3.2 34 | --mcu=TEENSY35 Teensy 3.5 35 | --mcu=TEENSY36 Teensy 3.6 36 | --mcu=TEENSY40 Teensy 4.0 37 | --mcu=TEENSY41 Teensy 4.1 38 | --mcu=TEENSY_MICROMOD MicroMod Teensy 39 | --mcu=imxrt1062 Teensy 4.0 40 | --mcu=mk66fx1m0 Teensy 3.6 41 | --mcu=mk64fx512 Teensy 3.5 42 | --mcu=mk20dx256 Teensy 3.2 & 3.1 43 | --mcu=mk20dx128 Teensy 3.0 44 | --mcu=mkl26z64 Teensy LC 45 | --mcu=at90usb1286 Teensy++ 2.0 46 | --mcu=atmega32u4 Teensy 2.0 47 | --mcu=at90usb646 Teensy++ 1.0 48 | --mcu=at90usb162 Teensy 1.0 49 | ``` 50 | 51 | Caution: HEX files compiled with USB support must be compiled for the correct chip. If you load a file built for a different chip, often it will hang while trying to initialize the on-chip USB controller (each chip has a different PLL-based clock generator). On some PCs, this can "confuse" your USB port and a cold reboot may be required to restore USB functionality. When a Teensy has been programmed with such incorrect code, the reset button must be held down BEFORE the USB cable is connected, and then released only after the USB cable is fully connected. 52 | 53 | Optional command line parameters: 54 | 55 | `-w` : Wait for device to appear. When the pushbuttons has not been pressed and HalfKay may not be running yet, this option makes teensy_loader_cli wait. It is safe to use this when HalfKay is already running. The hex file is read before waiting to verify it exists, and again immediately after the device is detected. 56 | 57 | `-r` : Use hard reboot if device not online. Perform a hard reset using a second Teensy 2.0 running this [rebooter](rebootor) code, with pin C7 connected to the reset pin on your main Teensy. While this requires using a second board, it allows a Makefile to fully automate reprogramming your Teensy. This method is recommended for fully automated usage, such as Travis CI with PlatformIO. No manual button press is required! 58 | 59 | `-s` : Use soft reboot (Linux only) if device not online. Perform a soft reset request by searching for any Teensy running USB Serial code built by Teensyduino. A request to reboot is transmitted to the first device found. 60 | 61 | `-n` : No reboot after programming. After programming the hex file, do not reboot. HalfKay remains running. This option may be useful if you wish to program the code but do not intend for it to run until the Teensy is installed inside a system with its I/O pins connected. 62 | 63 | `-v` : Verbose output. Normally teensy_loader_cli prints only error messages if any operation fails. This enables verbose output, which can help with troubleshooting, or simply show you more status information. 64 | 65 | ## System Specific Setup 66 | 67 | Linux requires UDEV rules for non-root users. 68 | 69 | https://www.pjrc.com/teensy/00-teensy.rules 70 | 71 | FreeBSD requires a [device configuration file](freebsd-teensy.conf) for non-root users. 72 | 73 | OpenBSD's make is incompatible with most AVR makefiles. Use "`pkg_add -r gmake`", and then compile code with "`gmake all`" to obtain the .hex file. 74 | 75 | On Macintosh OS-X 10.8, Casey Rodarmor shared this tip: 76 | 77 | I recently had a little trouble getting the teensy cli loader working on Mac OSX 10.8. Apple moved the location of the SDKs around, so that they now reside inside of the xcode app itself. This is the line in the makefile that got it working for me: 78 | SDK ?= /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk 79 | 80 | ## Makefile Integration 81 | 82 | You can use teensy_loader_cli from your Makefile, to autoamtically program your freshly compiled code. Here is an example: 83 | 84 | ``` 85 | # Create final output files (.hex, .eep) from ELF output file. 86 | %.hex: %.elf 87 | @echo 88 | @echo $(MSG_FLASH) $@ 89 | $(OBJCOPY) -O $(FORMAT) -R .eeprom -R .fuse -R .lock -R .signature $< $@ 90 | teensy_loader_cli --mcu=$(MCU) -w -v $@ 91 | ``` 92 | 93 | Make requires the white space before any command to be a tab character (not 8 spaces), so please make sure you use tab. 94 | 95 | If you connect a second Teensy using the rebootor code, add the "-r" option and your code will always be programmed automaticallly without having to manually press the reset button! 96 | 97 | Scott Bronson contributed a [Makefile patch](http://www.pjrc.com/teensy/loader_cli.makefile.patch) to allow "make program" to work for the blinky example. 98 | 99 | ## PlatformIO Integration 100 | 101 | [Platformio](http://platformio.org) includes support for loading via teensy_loader. 102 | 103 | ## Errata 104 | 105 | Compiling on Mac OS-X 10.6 may require adding "-mmacosx-version-min=10.5" to the Makefile. Thanks to Morgan Sutherland for reporting this. 106 | 107 | `$(CC) $(CFLAGS) -DUSE_APPLE_IOKIT -isysroot $(SDK) -o teensy_loader_cli teensy_loader_cli.c -Wl,-syslibroot,$(SDK) -framework IOKit -framework CoreFoundation -mmacosx-version-min=10.5` 108 | -------------------------------------------------------------------------------- /blink_slow_Teensy2pp.hex: -------------------------------------------------------------------------------- 1 | :100000000BC1000026C1000024C1000022C1000075 2 | :1000100020C100001EC100001CC100001AC1000068 3 | :1000200018C1000016C100003BC20000B3C20000AE 4 | :1000300010C100000EC100000CC100000AC1000088 5 | :1000400008C1000006C1000004C1000002C1000098 6 | :1000500000C10000FEC00000FCC0000076C100002E 7 | :10006000F8C00000F6C00000F4C00000F2C00000BC 8 | :10007000F0C00000EEC00000ECC00000EAC00000CC 9 | :10008000E8C00000E6C00000E4C00000E2C00000DC 10 | :10009000E0C00000DEC0000000010000F801120016 11 | :1000A00002000072014900220000DC011C00210056 12 | :1000B0000084010900220100BB012100210100A4EC 13 | :1000C0000109000300006E01040103090438013432 14 | :1000D0000203090410012603030904DE0030300383 15 | :1000E00045006D0075006C006100740065006400DF 16 | :1000F0002000410072006400750069006E006F000E 17 | :100100002000530065007200690061006C0000006F 18 | :1001100026035400650065006E00730079006400DA 19 | :10012000750069006E006F002000520061007700CA 20 | :100130004800490044000000340354006500650095 21 | :100140006E00730079006400750069006E006F0036 22 | :100150002000520061007700480049004400200060 23 | :100160004400650076006900630065000000040338 24 | :10017000090409024900020100C03209040000021A 25 | :1001800003000002092111010001221C0007058360 26 | :1001900003400001070504034000010904010002B7 27 | :1001A000030000030921110100012221000705813C 28 | :1001B000034000010705020320000206C9FF0904ED 29 | :1001C000A15C7508150026FF009540097581029510 30 | :1001D000200976910295040976B102C006ABFF0AA8 31 | :1001E0000002A1017508150026FF00954009018154 32 | :1001F00002954009029102C0120100020000004075 33 | :10020000C016860402010001000101C13601C026AA 34 | :1002100001C13601C036000011241FBECFEFD0E26D 35 | :10022000DEBFCDBF11E0A0E0B1E0E2E0F9E000E028 36 | :100230000BBF02C007900D92A030B107D9F721E0A3 37 | :10024000A0E0B1E001C01D92A930B207E1F753D39D 38 | :1002500056C3D6CE569A08955E9A68EE73E080E053 39 | :1002600090E0B3D05E9868EE73E080E090E0ADC0BF 40 | :100270001DBA109268001CBC10BE1FBA10927A0002 41 | :1002800010926E0010926F00109270001092710028 42 | :100290001092C9001092BC0011B814B817B81AB85F 43 | :1002A0001DB810BA12B815B818B81BB81EB811BAD4 44 | :1002B0000895F894E1E6F0E020E8208381E080836F 45 | :1002C00093E094BD95BDEEE6F0E09081916090835F 46 | :1002D0008093800092E0909381008093B00090938F 47 | :1002E000B100809390009093910085E880937A000C 48 | :1002F00020937B0010927E00A9D078940895F89402 49 | :1003000084B7877F84BF80916000806180936000A4 50 | :100310001092600080E197E20197F1F781E080930D 51 | :10032000E00080E28093D80080E395E70197F1F741 52 | :100330009FDF0C9400FEFFCFF8949ADF80E395E7EF 53 | :100340000197F1F70C940000FFCF8F938FB78F9335 54 | :10035000809100018A5F8D37D0F4809300018091F5 55 | :1003600001018E5F80930101D8F0809102018F4FCF 56 | :1003700080930201A8F0809103018F4F80930301C5 57 | :1003800078F0809104018F4F8093040109C08D574C 58 | :1003900080930001809101018D5F8093010128F716 59 | :1003A00080910501885F8093050158F080910601D6 60 | :1003B0008F4F8093060128F0809107018F4F809323 61 | :1003C00007018F918FBF8F911895CF92DF92EF9297 62 | :1003D000FF926B017C0119D09B01C114D104E1048F 63 | :1003E000F10429F4FF90EF90DF90CF9008950DD0A5 64 | :1003F000621B730B683E734080F381E0C81AD1081A 65 | :10040000E108F10828513C4FE8CF0FB6F89466B5E3 66 | :1004100015B27091050180910601909107010FBE00 67 | :1004200010FE05C06F3F19F0785F8F4F9F4F11246A 68 | :100430000024660F001C660F001C660F001C70294C 69 | :1004400008958091E80080FFFCCF08958091D80046 70 | :1004500087FF02C085FF23C081E88093D70080EA30 71 | :100460008093D80086E189BD09B400FEFDCF80E904 72 | :100470008093D8001092E00010920F0110920E01AC 73 | :1004800010920D0110920C0110920B0110920A01B2 74 | :10049000109209011092E1008CE08093E20008952F 75 | :1004A0001F920F920FB60F9211242F938F939F9349 76 | :1004B0002091E1001092E10023FF0FC01092E900AB 77 | :1004C00081E08093EB001092EC0082E38093ED00DA 78 | :1004D00088E08093F00010920F0122FF2FC08091DE 79 | :1004E0000F01882359F180910D01882379F0815003 80 | :1004F00080930D0181110AC081E08093E900809111 81 | :10050000E80085FD44C08AE38093E80080910B01F8 82 | :1005100090910C01882331F0815090E090930C0170 83 | :1005200080930B018091090190910A01882331F099 84 | :10053000815090E090930A018093090120FF0CC044 85 | :1005400080E18093E20010920F0181E080930E0120 86 | :1005500080EA8093D80019BC80910E01882379F03D 87 | :1005600024FF0DC086E189BD09B400FEFDCF80E9FE 88 | :100570008093D8008DE08093E20010920E019F914D 89 | :100580008F912F910F900FBE0F901F901895109282 90 | :10059000F100B5CF1F920F920FB60F9211240BB638 91 | :1005A0000F92EF92FF920F931F932F933F934F93CE 92 | :1005B0005F936F937F938F939F93AF93BF93CF93EB 93 | :1005C000DF93EF93FF931092E9008091E80083FF9F 94 | :1005D00021C0E090F100F090F100C091F100D091C5 95 | :1005E000F1000091F1001091F1002091F1003091A3 96 | :1005F000F10082EF8093E80086E0F8125CC08AE0A8 97 | :10060000E8E9F0E045915591C417D50739F03596E2 98 | :100610008150C1F781E28093EB002BC04591559149 99 | :100620000417150711F03396F3CF45915591849136 100 | :100630002F3F310519F010F02FEF30E0821708F44A 101 | :10064000282F3EEF8091E800982F9570D9F382FD16 102 | :1006500010C0822F213408F080E4982F911124C01B 103 | :10066000922F981B892F3093E80091111BC02034E2 104 | :10067000C8F4FF91EF91DF91CF91BF91AF919F911E 105 | :100680008F917F916F915F914F913F912F911F912A 106 | :100690000F91FF90EF900F900BBE0F900FBE0F9039 107 | :1006A0001F901895282FCECFFA0145914093F10065 108 | :1006B000AF019150D3CF85E0F81208C08EEF809340 109 | :1006C000E800BFDEC068C093E300D3CF99E0F91221 110 | :1006D00022C0E11067C0C0930F0110920D018EEF90 111 | :1006E0008093E80081E0EAE0F2E08093E9009591F0 112 | :1006F0009093EB00992331F095919093EC009591B4 113 | :100700009093ED008F5F853081F78EE18093EA0052 114 | :100710001092EA00AECF88E0F8120CC090E8E9121F 115 | :1007200041C08FDE80910F018093F1008EEF8093A6 116 | :10073000E8009FCFF11012C084DE22E8E21209C067 117 | :100740000093E900F090EB00F5FAFF24F0F8109226 118 | :10075000E900F092F1001092F100E8CF8F2D8D7F2B 119 | :10076000813001F582E0E8121DC0209709F09BC09E 120 | :10077000402F4F778FEF840F853008F094C08EEFB5 121 | :100780008093E8004093E90093E0F91609F442CF22 122 | :1007900089E18093EB0081E090E001C0880F4A95E9 123 | :1007A000EAF7B4CF0115110509F081C021EAE21280 124 | :1007B00023C081E0F8122ECF80E43EEF01C0892FE4 125 | :1007C0009091E800292F2570D9F392FD52CF982FF0 126 | :1007D000813408F090E4292F21110AC0282F291B09 127 | :1007E000922F3093E8002111EACF803440F741CFB7 128 | :1007F0001092F1002150F0CF81E2E81249C099E057 129 | :10080000F91208CF8091E80082FFFCCF8BEF809334 130 | :10081000E80017DE8BCF1092F10091505EC089E0A6 131 | :10082000F81236C091E2E912F5CEC115D34009F0B5 132 | :10083000F1CE2430310509F0EDCE8091E80082FF41 133 | :10084000FCCF3091F1002091F1009091F100809166 134 | :10085000F1004BEF4093E8004EEF4093E800393A47 135 | :1008600051F4253409F0D6CE923C09F0D3CE8B3624 136 | :1008700009F0D0CE44DD3B3809F0CCCE253C09F060 137 | :10088000C9CE9D3109F0C6CE803709F0C3CE54DD04 138 | :1008900099ECF912BFCE20E4E212BCCE8EEF809329 139 | :1008A000E800CFDDF4CF0115110509F4B3CE013016 140 | :1008B000110571F781E0F812B2CF91EA3EEFE9122B 141 | :1008C000A9CE8091E800982F9570D9F382FDD1CE02 142 | :1008D000822F213408F080E4982F91119CCF922F21 143 | :1008E000981B892F3093E800911103C0203408F43D 144 | :1008F000C0CE282FE6CFDDDCADDCAEDCFECFF89439 145 | :02090000FFCF27 146 | :00000001FF 147 | -------------------------------------------------------------------------------- /blink_slow_Teensy2.hex: -------------------------------------------------------------------------------- 1 | :1000000015C100002EC100002CC100002AC1000053 2 | :1000100028C1000026C1000024C1000022C1000048 3 | :1000200020C100001EC100004CC20000C4C200007C 4 | :1000300018C1000016C1000014C1000012C1000068 5 | :1000400010C100000EC100000CC100000AC1000078 6 | :1000500008C1000006C1000004C1000087C1000003 7 | :1000600000C10000FEC00000FCC00000FAC000009B 8 | :10007000F8C00000F6C00000F4C00000F2C00000AC 9 | :10008000F0C00000EEC00000ECC00000EAC00000BC 10 | :10009000E8C00000E6C00000E4C00000E2C00000CC 11 | :1000A000E0C00000DEC00000DCC000000001000075 12 | :1000B0000C02120002000086014900220000F0013B 13 | :1000C0001C0021000098010900220100CF0121003D 14 | :1000D000210100B8010900030000820104010309A5 15 | :1000E000044C01340203090424012603030904F229 16 | :1000F0000030300345006D0075006C006100740035 17 | :100100006500640020004100720064007500690011 18 | :100110006E006F00200053006500720069006100EE 19 | :100120006C00000026035400650065006E0073003B 20 | :1001300079006400750069006E006F0020005200B5 21 | :100140006100770048004900440000003403540077 22 | :10015000650065006E007300790064007500690039 23 | :100160006E006F00200052006100770048004900D7 24 | :1001700044002000440065007600690063006500CB 25 | :1001800000000403090409024900020100C0320909 26 | :100190000400000203000002092111010001221CD9 27 | :1001A000000705830340000107050403400001091F 28 | :1001B00004010002030000030921110100012221B2 29 | :1001C0000007058103400001070502032000020625 30 | :1001D000C9FF0904A15C7508150026FF00954009B8 31 | :1001E00075810295200976910295040976B102C0C5 32 | :1001F00006ABFF0A0002A1017508150026FF009555 33 | :100200004009018102954009029102C012010002D9 34 | :1002100000000040C016860402010001000101C177 35 | :100220003601C02601C13601C036000011241FBEB0 36 | :10023000CFEFDAE0DEBFCDBF11E0A0E0B1E0ECE14E 37 | :10024000F9E002C005900D92A030B107D9F721E086 38 | :10025000A0E0B1E001C01D92A930B207E1F758D388 39 | :100260005BC3CECE569A08955E9A68EE73E080E046 40 | :1002700090E0BCD05E9868EE73E080E090E0B6C09D 41 | :100280001DBA109268001CBC10BE1FBA10927A00F2 42 | :1002900010926E0010926F00109271001092720016 43 | :1002A0001092C900ECEBF0E0108214B817B81AB83D 44 | :1002B0001DB810BA108215B818B81BB81EB811BAFC 45 | :1002C0000895F894E1E6F0E020E8208381E080835F 46 | :1002D00093E094BD95BDEEE6F0E09081916090834F 47 | :1002E0008093800092E0909381008093900090939F 48 | :1002F00091009093C00094E09093C1008093C2005D 49 | :100300008093C3001092C40085E880937A00209304 50 | :100310007B0010927E0010927D00A9D07894089501 51 | :10032000F89484B7877F84BF809160008061809358 52 | :1003300060001092600080E197E20197F1F781E0A0 53 | :100340008093E00080E28093D80080E395E70197F6 54 | :10035000F1F796DF0C94003FFFCFF89491DF80E334 55 | :1003600095E70197F1F70C940000FFCF8F938FB7BB 56 | :100370008F93809100018A5F8D37D0F480930001C4 57 | :10038000809101018E5F80930101D8F0809102017C 58 | :100390008F4F80930201A8F0809103018F4F8093CB 59 | :1003A000030178F0809104018F4F8093040109C00C 60 | :1003B0008D5780930001809101018D5F8093010131 61 | :1003C00028F780910501885F8093050158F080919E 62 | :1003D00006018F4F8093060128F0809107018F4F0F 63 | :1003E000809307018F918FBF8F911895CF92DF92E5 64 | :1003F000EF92FF926B017C0119D09B01C114D104D3 65 | :10040000E104F10429F4FF90EF90DF90CF9008957C 66 | :100410000DD0621B730B683E734080F381E0C81AF5 67 | :10042000D108E108F10828513C4FE8CF0FB6F89405 68 | :1004300066B515B270910501809106019091070192 69 | :100440000FBE10FE05C06F3F19F0785F8F4F9F4FB2 70 | :1004500011240024660F001C660F001C660F001C90 71 | :10046000702908958091E80080FFFCCF0895809165 72 | :10047000D80087FF02C085FF23C081E08093D700AA 73 | :1004800080EA8093D80082E189BD09B400FEFDCFE7 74 | :1004900080E98093D8001092E00010920F01109232 75 | :1004A0000E0110920D0110920C0110920B0110928E 76 | :1004B0000A01109209011092E1008CE08093E200A1 77 | :1004C00008951F920F920FB60F9211242F938F93BE 78 | :1004D0009F932091E1001092E10023FF0FC0109242 79 | :1004E000E90081E08093EB001092EC0082E38093BE 80 | :1004F000ED0088E08093F00010920F0122FF2FC0E2 81 | :1005000080910F01882359F180910D01882379F0A2 82 | :10051000815080930D0181110AC081E08093E90030 83 | :100520008091E80085FD44C08AE38093E8008091D3 84 | :100530000B0190910C01882331F0815090E0909351 85 | :100540000C0180930B018091090190910A0188238D 86 | :1005500031F0815090E090930A018093090120FFCF 87 | :100560000CC080E18093E20010920F0181E0809343 88 | :100570000E0180EA8093D80019BC80910E01882377 89 | :1005800079F024FF0DC082E189BD09B400FEFDCFE2 90 | :1005900080E98093D8008DE08093E20010920E01F4 91 | :1005A0009F918F912F910F900FBE0F901F901895D4 92 | :1005B0001092F100B5CF1F920F920FB60F92112437 93 | :1005C000EF92FF920F931F932F933F934F935F935D 94 | :1005D0006F937F938F939F93AF93BF93CF93DF934B 95 | :1005E000EF93FF931092E9008091E80083FF21C010 96 | :1005F000E090F100F090F100C091F100D091F10095 97 | :100600000091F1001091F1002091F1003091F10082 98 | :1006100082EF8093E80086E0F8125AC08AE0ECEAA4 99 | :10062000F0E045915591C417D50739F035968150C2 100 | :10063000C1F781E28093EB002BC0459155910417DF 101 | :10064000150711F03396F3CF4591559184912F3FC3 102 | :10065000310519F010F02FEF30E0821708F4282F41 103 | :100660003EEF8091E800982F9570D9F382FD10C07D 104 | :10067000822F213408F080E4982F911122C0922F0C 105 | :10068000981B892F3093E800911119C02034B8F4D9 106 | :10069000FF91EF91DF91CF91BF91AF919F918F919A 107 | :1006A0007F916F915F914F913F912F911F910F918A 108 | :1006B000FF90EF900F900FBE0F901F901895282F6E 109 | :1006C000D0CFFA0145914093F100AF019150D5CFC1 110 | :1006D00085E0F81208C08EEF8093E800C3DEC068A2 111 | :1006E000C093E300D5CF99E0F91222C0E11067C0B2 112 | :1006F000C0930F0110920D018EEF8093E80081E00E 113 | :10070000EEE1F2E08093E90095919093EB0099235C 114 | :1007100031F095919093EC0095919093ED008F5F5F 115 | :10072000853081F78EE18093EA001092EA00B0CF25 116 | :1007300088E0F8120CC090E8E91241C093DE809185 117 | :100740000F018093F1008EEF8093E800A1CFF110AC 118 | :1007500012C088DE22E8E21209C00093E900F0909E 119 | :10076000EB00F5FAFF24F0F81092E900F092F100A6 120 | :100770001092F100E8CF8F2D8D7F813001F582E05E 121 | :10078000E8121DC0209709F09BC0402F4F778FEFD4 122 | :10079000840F853008F094C08EEF8093E80040937A 123 | :1007A000E90093E0F91609F444CF89E18093EB0066 124 | :1007B00081E090E001C0880F4A95EAF7B4CF0115B7 125 | :1007C000110509F081C021EAE21223C081E0F8128C 126 | :1007D00030CF80E43EEF01C0892F9091E800292FAF 127 | :1007E0002570D9F392FD54CF982F813408F090E40E 128 | :1007F000292F21110AC0282F291B922F3093E8009E 129 | :100800002111EACF803440F743CF1092F1002150FC 130 | :10081000F0CF81E2E81249C099E0F9120ACF809145 131 | :10082000E80082FFFCCF8BEF8093E8001BDE8BCFCC 132 | :100830001092F10091505EC089E0F81236C091E24A 133 | :10084000E912F7CEC115D34009F0F3CE24303105BB 134 | :1008500009F0EFCE8091E80082FFFCCF3091F100EB 135 | :100860002091F1009091F1008091F1004BEF4093C5 136 | :10087000E8004EEF4093E800393A51F4253409F08E 137 | :10088000D8CE923C09F0D5CE8B3609F0D2CE48DDD9 138 | :100890003B3809F0CECE253C09F0CBCE9D3109F096 139 | :1008A000C8CE803709F0C5CE58DD99ECF912C1CE1B 140 | :1008B00020E4E212BECE8EEF8093E800D3DDF4CFC9 141 | :1008C0000115110509F4B5CE0130110571F781E06C 142 | :1008D000F812B2CF91EA3EEFE912ABCE8091E80078 143 | :1008E000982F9570D9F382FDD3CE822F213408F052 144 | :1008F00080E4982F91119CCF922F981B892F3093D1 145 | :10090000E800911103C0203408F4C2CE282FE6CFAE 146 | :0C091000D8DCA8DCA9DCFECFF894FFCFF7 147 | :00000001FF 148 | -------------------------------------------------------------------------------- /rebootor/usb.c: -------------------------------------------------------------------------------- 1 | /* Teensy Rebootor 2 | * http://www.pjrc.com/teensy/ 3 | * Copyright (c) 2010 PJRC.COM, LLC 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above description, website URL and copyright notice and this permission 13 | * notice shall be included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | * THE SOFTWARE. 22 | */ 23 | 24 | // Version 1.0: Initial Release 25 | 26 | #define USB_PRIVATE_INCLUDE 27 | #include "usb.h" 28 | #include 29 | 30 | /************************************************************************** 31 | * 32 | * Configurable Options 33 | * 34 | **************************************************************************/ 35 | 36 | #define STR_MANUFACTURER L"PJRC" 37 | #define STR_PRODUCT L"Rebootor" 38 | #define VENDOR_ID 0x16C0 39 | #define PRODUCT_ID 0x0477 40 | #define RX_SIZE 6 // receive packet size 41 | 42 | 43 | /************************************************************************** 44 | * 45 | * Endpoint Buffer Configuration 46 | * 47 | **************************************************************************/ 48 | 49 | #define ENDPOINT0_SIZE 32 50 | 51 | 52 | static const uint8_t PROGMEM endpoint_config_table[] = { 53 | 1, EP_TYPE_INTERRUPT_IN, EP_SIZE(8) | EP_SINGLE_BUFFER, 54 | 0, 55 | 0, 56 | 0 57 | }; 58 | 59 | 60 | /************************************************************************** 61 | * 62 | * Descriptor Data 63 | * 64 | **************************************************************************/ 65 | 66 | // Descriptors are the data that your computer reads when it auto-detects 67 | // this USB device (called "enumeration" in USB lingo). The most commonly 68 | // changed items are editable at the top of this file. Changing things 69 | // in here should only be done by those who've read chapter 9 of the USB 70 | // spec and relevant portions of any USB class specifications! 71 | 72 | 73 | static const uint8_t PROGMEM device_descriptor[] = { 74 | 18, // bLength 75 | 1, // bDescriptorType 76 | 0x00, 0x02, // bcdUSB 77 | 0, // bDeviceClass 78 | 0, // bDeviceSubClass 79 | 0, // bDeviceProtocol 80 | ENDPOINT0_SIZE, // bMaxPacketSize0 81 | LSB(VENDOR_ID), MSB(VENDOR_ID), // idVendor 82 | LSB(PRODUCT_ID), MSB(PRODUCT_ID), // idProduct 83 | 0x00, 0x01, // bcdDevice 84 | 1, // iManufacturer 85 | 2, // iProduct 86 | 0, // iSerialNumber 87 | 1 // bNumConfigurations 88 | }; 89 | 90 | static const uint8_t PROGMEM rawhid_hid_report_desc[] = { 91 | 0x06, 0x00, 0xFF, 92 | 0x0A, 0x00, 0x01, 93 | 0xA1, 0x01, // Collection 0x01 94 | 0x75, 0x08, // report size = 8 bits 95 | 0x15, 0x00, // logical minimum = 0 96 | 0x26, 0xFF, 0x00, // logical maximum = 255 97 | 0x95, RX_SIZE, // report count 98 | 0x09, 0x02, // usage 99 | 0x91, 0x02, // Output (array) 100 | 0xC0 // end collection 101 | }; 102 | 103 | 104 | #define CONFIG1_DESC_SIZE (9+9+9+7) 105 | #define RAWHID_HID_DESC_OFFSET (9+9) 106 | static const uint8_t PROGMEM config1_descriptor[CONFIG1_DESC_SIZE] = { 107 | // configuration descriptor, USB spec 9.6.3, page 264-266, Table 9-10 108 | 9, // bLength; 109 | 2, // bDescriptorType; 110 | LSB(CONFIG1_DESC_SIZE), // wTotalLength 111 | MSB(CONFIG1_DESC_SIZE), 112 | 1, // bNumInterfaces 113 | 1, // bConfigurationValue 114 | 0, // iConfiguration 115 | 0xC0, // bmAttributes 116 | 50, // bMaxPower 117 | 118 | // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12 119 | 9, // bLength 120 | 4, // bDescriptorType 121 | 0, // bInterfaceNumber 122 | 0, // bAlternateSetting 123 | 1, // bNumEndpoints 124 | 0x03, // bInterfaceClass (0x03 = HID) 125 | 0x00, // bInterfaceSubClass 126 | 0x00, // bInterfaceProtocol 127 | 0, // iInterface 128 | // HID interface descriptor, HID 1.11 spec, section 6.2.1 129 | 9, // bLength 130 | 0x21, // bDescriptorType 131 | 0x11, 0x01, // bcdHID 132 | 0, // bCountryCode 133 | 1, // bNumDescriptors 134 | 0x22, // bDescriptorType 135 | sizeof(rawhid_hid_report_desc), // wDescriptorLength 136 | 0, 137 | // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13 138 | 7, // bLength 139 | 5, // bDescriptorType 140 | 1 | 0x80, // bEndpointAddress 141 | 0x03, // bmAttributes (0x03=intr) 142 | 8, 0, // wMaxPacketSize 143 | 0x80 // bInterval 144 | }; 145 | 146 | // If you're desperate for a little extra code memory, these strings 147 | // can be completely removed if iManufacturer, iProduct, iSerialNumber 148 | // in the device desciptor are changed to zeros. 149 | struct usb_string_descriptor_struct { 150 | uint8_t bLength; 151 | uint8_t bDescriptorType; 152 | int16_t wString[]; 153 | }; 154 | static const struct usb_string_descriptor_struct PROGMEM string0 = { 155 | 4, 156 | 3, 157 | {0x0409} 158 | }; 159 | static const struct usb_string_descriptor_struct PROGMEM string1 = { 160 | sizeof(STR_MANUFACTURER), 161 | 3, 162 | STR_MANUFACTURER 163 | }; 164 | static const struct usb_string_descriptor_struct PROGMEM string2 = { 165 | sizeof(STR_PRODUCT), 166 | 3, 167 | STR_PRODUCT 168 | }; 169 | 170 | // This table defines which descriptor data is sent for each specific 171 | // request from the host (in wValue and wIndex). 172 | static const struct descriptor_list_struct { 173 | uint16_t wValue; 174 | uint16_t wIndex; 175 | const uint8_t *addr; 176 | uint8_t length; 177 | } PROGMEM descriptor_list[] = { 178 | {0x0100, 0x0000, device_descriptor, sizeof(device_descriptor)}, 179 | {0x0200, 0x0000, config1_descriptor, sizeof(config1_descriptor)}, 180 | {0x2200, 0, rawhid_hid_report_desc, sizeof(rawhid_hid_report_desc)}, 181 | {0x2100, 0, config1_descriptor+RAWHID_HID_DESC_OFFSET, 9}, 182 | {0x0300, 0x0000, (const uint8_t *)&string0, 4}, 183 | {0x0301, 0x0409, (const uint8_t *)&string1, sizeof(STR_MANUFACTURER)}, 184 | {0x0302, 0x0409, (const uint8_t *)&string2, sizeof(STR_PRODUCT)} 185 | }; 186 | #define NUM_DESC_LIST (sizeof(descriptor_list)/sizeof(struct descriptor_list_struct)) 187 | 188 | 189 | /************************************************************************** 190 | * 191 | * Variables - these are the only non-stack RAM usage 192 | * 193 | **************************************************************************/ 194 | 195 | // zero when we are not configured, non-zero when enumerated 196 | static volatile uint8_t usb_configuration=0; 197 | 198 | 199 | 200 | /************************************************************************** 201 | * 202 | * Public Functions - these are the API intended for the user 203 | * 204 | **************************************************************************/ 205 | 206 | 207 | // initialize USB 208 | void usb_init(void) 209 | { 210 | HW_CONFIG(); 211 | USB_FREEZE(); // enable USB 212 | PLL_CONFIG(); // config PLL 213 | while (!(PLLCSR & (1<= 40300) && (GCC_VERSION < 40302) 231 | #error "Buggy GCC 4.3.0 compiler, please upgrade!" 232 | #endif 233 | 234 | 235 | // USB Device Interrupt - handle all device-level events 236 | // the transmit buffer flushing is triggered by the start of frame 237 | // 238 | ISR(USB_GEN_vect) 239 | { 240 | uint8_t intbits; 241 | 242 | intbits = UDINT; 243 | UDINT = 0; 244 | if (intbits & (1<= NUM_DESC_LIST) { 311 | UECONX = (1< desc_length) len = desc_length; 333 | do { 334 | // wait for host ready for IN packet 335 | do { 336 | i = UEINTX; 337 | } while (!(i & ((1<= 1 && i <= MAX_ENDPOINT) { 396 | usb_send_in(); 397 | UENUM = i; 398 | if (bRequest == SET_FEATURE) { 399 | UECONX = (1<