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.

bootloader.c 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #include <avr/io.h>
  2. #include <avr/interrupt.h>
  3. #include <util/delay.h>
  4. #include "bootloader.h"
  5. /* Start Bootloader from Application
  6. * See
  7. * http://www.pjrc.com/teensy/jump_to_bootloader.html
  8. * http://www.fourwalledcubicle.com/files/LUFA/Doc/120219/html/_page__software_bootloader_start.html
  9. */
  10. /* Boot Section Size in bytes
  11. * Teensy halfKay 512
  12. * Atmel DFU loader 4096
  13. * LUFA bootloader 4096
  14. */
  15. #ifndef BOOT_SIZE
  16. #define BOOT_SIZE 512
  17. #endif
  18. #define FLASH_SIZE (FLASHEND + 1)
  19. #define BOOTLOADER_START (FLASHEND - BOOT_SIZE)
  20. void bootloader_jump(void) {
  21. cli();
  22. // disable watchdog, if enabled
  23. // disable all peripherals
  24. UDCON = 1;
  25. USBCON = (1<<FRZCLK); // disable USB
  26. UCSR1B = 0;
  27. _delay_ms(5);
  28. #if defined(__AVR_AT90USB162__)
  29. EIMSK = 0; PCICR = 0; SPCR = 0; ACSR = 0; EECR = 0;
  30. TIMSK0 = 0; TIMSK1 = 0; UCSR1B = 0;
  31. DDRB = 0; DDRC = 0; DDRD = 0;
  32. PORTB = 0; PORTC = 0; PORTD = 0;
  33. #elif defined(__AVR_ATmega32U4__)
  34. EIMSK = 0; PCICR = 0; SPCR = 0; ACSR = 0; EECR = 0; ADCSRA = 0;
  35. TIMSK0 = 0; TIMSK1 = 0; TIMSK3 = 0; TIMSK4 = 0; UCSR1B = 0; TWCR = 0;
  36. DDRB = 0; DDRC = 0; DDRD = 0; DDRE = 0; DDRF = 0; TWCR = 0;
  37. PORTB = 0; PORTC = 0; PORTD = 0; PORTE = 0; PORTF = 0;
  38. #elif defined(__AVR_AT90USB646__)
  39. EIMSK = 0; PCICR = 0; SPCR = 0; ACSR = 0; EECR = 0; ADCSRA = 0;
  40. TIMSK0 = 0; TIMSK1 = 0; TIMSK2 = 0; TIMSK3 = 0; UCSR1B = 0; TWCR = 0;
  41. DDRA = 0; DDRB = 0; DDRC = 0; DDRD = 0; DDRE = 0; DDRF = 0;
  42. PORTA = 0; PORTB = 0; PORTC = 0; PORTD = 0; PORTE = 0; PORTF = 0;
  43. #elif defined(__AVR_AT90USB1286__)
  44. EIMSK = 0; PCICR = 0; SPCR = 0; ACSR = 0; EECR = 0; ADCSRA = 0;
  45. TIMSK0 = 0; TIMSK1 = 0; TIMSK2 = 0; TIMSK3 = 0; UCSR1B = 0; TWCR = 0;
  46. DDRA = 0; DDRB = 0; DDRC = 0; DDRD = 0; DDRE = 0; DDRF = 0;
  47. PORTA = 0; PORTB = 0; PORTC = 0; PORTD = 0; PORTE = 0; PORTF = 0;
  48. #endif
  49. // start Bootloader
  50. ((void (*)(void))BOOTLOADER_START)();
  51. }