X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=common%2Fbootloader.c;h=cda295b1811e92f90baea342084b37a07139bcc1;hb=b9e265368fde73daff069788dcb58c8230d01b32;hp=cb971c7043771fbcbde4849c1e92bd5757387176;hpb=f427529a30487de45ebfbe6fbba9c290738878ab;p=tmk_firmware.git diff --git a/common/bootloader.c b/common/bootloader.c index cb971c7..cda295b 100644 --- a/common/bootloader.c +++ b/common/bootloader.c @@ -1,34 +1,107 @@ +#include +#include #include #include +#include #include #include "bootloader.h" -/* Start Bootloader from Application - * See - * http://www.pjrc.com/teensy/jump_to_bootloader.html - * http://www.fourwalledcubicle.com/files/LUFA/Doc/120219/html/_page__software_bootloader_start.html +#ifdef PROTOCOL_LUFA +#include +#endif + + +/* Boot Section Size in *BYTEs* + * Teensy halfKay 512 + * Teensy++ halfKay 1024 + * Atmel DFU loader 4096 + * LUFA bootloader 4096 + * USBaspLoader 2048 */ +#ifndef BOOTLOADER_SIZE +#warning To use bootloader_jump() you need to define BOOTLOADER_SIZE in config.h. +#define BOOTLOADER_SIZE 4096 +#endif -/* Boot Section Size in bytes - * Teensy halfKay 512 - * Atmel DFU loader 4096 - * LUFA bootloader 4096 +#define FLASH_SIZE (FLASHEND + 1L) +#define BOOTLOADER_START (FLASH_SIZE - BOOTLOADER_SIZE) + + +/* + * Entering the Bootloader via Software + * http://www.fourwalledcubicle.com/files/LUFA/Doc/120730/html/_page__software_bootloader_start.html */ -#ifndef BOOT_SIZE -#define BOOT_SIZE 512 +#define BOOTLOADER_RESET_KEY 0xB007B007 +uint32_t reset_key __attribute__ ((section (".noinit"))); + +/* initialize MCU status by watchdog reset */ +void bootloader_jump(void) { +#ifdef PROTOCOL_LUFA + USB_Disable(); + cli(); + _delay_ms(2000); #endif -#define FLASH_SIZE (FLASHEND + 1) -#define BOOTLOADER_START (FLASHEND - BOOT_SIZE) +#ifdef PROTOCOL_PJRC + cli(); + UDCON = 1; + USBCON = (1<