Keyboard firmwares for Atmel AVR and Cortex-M
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

jump_bootloader.c 1.1KB

1234567891011121314151617181920212223242526272829303132333435
  1. // this code from:
  2. // http://www.pjrc.com/teensy/jump_to_bootloader.html
  3. #include <avr/io.h>
  4. #include <avr/interrupt.h>
  5. #include <util/delay.h>
  6. void jump_bootloader(void) {
  7. cli();
  8. // disable watchdog, if enabled
  9. // disable all peripherals
  10. UDCON = 1;
  11. USBCON = (1<<FRZCLK); // disable USB
  12. UCSR1B = 0;
  13. _delay_ms(5);
  14. #if defined(__AVR_AT90USB162__) // Teensy 1.0
  15. DDRB = 0; DDRC = 0; DDRD = 0;
  16. TIMSK0 = 0; TIMSK1 = 0;
  17. asm volatile("jmp 0x1F00");
  18. #elif defined(__AVR_ATmega32U4__) // Teensy 2.0
  19. DDRB = 0; DDRC = 0; DDRD = 0; DDRE = 0; DDRF = 0;
  20. TIMSK0 = 0; TIMSK1 = 0; TIMSK3 = 0; TIMSK4 = 0;
  21. ADCSRA = 0;
  22. asm volatile("jmp 0x3F00");
  23. #elif defined(__AVR_AT90USB646__) // Teensy++ 1.0
  24. DDRA = 0; DDRB = 0; DDRC = 0; DDRD = 0; DDRE = 0; DDRF = 0;
  25. TIMSK0 = 0; TIMSK1 = 0; TIMSK2 = 0; TIMSK3 = 0;
  26. ADCSRA = 0;
  27. asm volatile("jmp 0x7E00");
  28. #elif defined(__AVR_AT90USB1286__) // Teensy++ 2.0
  29. DDRA = 0; DDRB = 0; DDRC = 0; DDRD = 0; DDRE = 0; DDRF = 0;
  30. TIMSK0 = 0; TIMSK1 = 0; TIMSK2 = 0; TIMSK3 = 0;
  31. ADCSRA = 0;
  32. asm volatile("jmp 0xFE00");
  33. #endif
  34. }