1234567891011121314151617181920212223242526272829303132333435363738394041 |
- #include "usbcas.h"
- /* ATmega32U4 with Caterina bootloader */
- #define FLASH_SIZE_BYTES 32768
- #define BOOTSZ 0
- #define BOOTLOADER_SEC_SIZE (4096 >> BOOTSZ)
- #define MAGIC_BOOT_KEY 0xdc42acca
- #define BOOTLOADER_START_ADDRESS (FLASH_SIZE_BYTES - BOOTLOADER_SEC_SIZE)
- static uint32_t boot_key_magic ATTR_NO_INIT;
- static void bootloader_jump_check(void) ATTR_INIT_SECTION(3);
- static void bootloader_jump_check(void)
- {
- void (* const bootloader)(void) =
- (void (*)(void))BOOTLOADER_START_ADDRESS;
- /*
- * If the reset source was the watch dog and the boot key magic is set,
- * clear the magic and jump into the boot loader
- */
- if (boot_key_magic == MAGIC_BOOT_KEY) {
- boot_key_magic = 0;
- bootloader();
- }
- }
- /*
- * Host sent BREAK; reboot into bootloader
- */
- void EVENT_CDC_Device_BreakSent(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo, const uint8_t duration)
- {
- /* Set the bootloader invocation key */
- boot_key_magic = MAGIC_BOOT_KEY;
- /* Arm the watchdog to force a hardware reset */
- wdt_enable(WDTO_250MS);
- /* Return to the main loop so we ack the send break correctly */
- }
|