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.

71 lines
2.8 KiB

  1. /** \file
  2. *
  3. * This file contains special DoxyGen information for the generation of the main page and other special
  4. * documentation pages. It is not a project source file.
  5. */
  6. /**
  7. * \page Page_SoftwareBootloaderStart Entering the Bootloader via Software
  8. *
  9. * A common requirement of many applications is the ability to jump to the programmed bootloader of a chip
  10. * on demand, via the code's firmware (i.e. not as a result of any physical user interaction with the
  11. * hardware). This might be required because the device does not have any physical user input, or simply
  12. * just to streamline the device upgrade process on the host PC.
  13. *
  14. * The following C code snippets may be used to enter the bootloader upon request by the user application.
  15. * By using the watchdog to physically reset the controller, it is ensured that all system hardware is
  16. * completely reset to their defaults before the bootloader is run. This is important; since bootloaders
  17. * are written to occupy a very limited space, they usually make assumptions about the register states based
  18. * on the default values after a hard-reset of the chip.
  19. *
  20. * \section Sec_SoftareBootAVR8 AVR8 Architecture
  21. * The following software bootloader jump code is written for the AVR8 architecture.
  22. *
  23. * \code
  24. * #include <avr/wdt.h>
  25. * #include <avr/io.h>
  26. * #include <util/delay.h>
  27. *
  28. * #include <LUFA/Common/Common.h>
  29. * #include <LUFA/Drivers/USB/USB.h>
  30. *
  31. * uint32_t Boot_Key ATTR_NO_INIT;
  32. *
  33. * #define MAGIC_BOOT_KEY 0xDC42ACCA
  34. * #define BOOTLOADER_START_ADDRESS (FLASH_SIZE_BYTES - BOOTLOADER_SEC_SIZE_BYTES)
  35. *
  36. * void Bootloader_Jump_Check(void) ATTR_INIT_SECTION(3);
  37. * void Bootloader_Jump_Check(void)
  38. * {
  39. * // If the reset source was the bootloader and the key is correct, clear it and jump to the bootloader
  40. * if ((MCUSR & (1 << WDRF)) && (Boot_Key == MAGIC_BOOT_KEY))
  41. * {
  42. * Boot_Key = 0;
  43. * ((void (*)(void))BOOTLOADER_START_ADDRESS)();
  44. * }
  45. * }
  46. *
  47. * void Jump_To_Bootloader(void)
  48. * {
  49. * // If USB is used, detach from the bus and reset it
  50. * USB_Disable();
  51. *
  52. * // Disable all interrupts
  53. * cli();
  54. *
  55. * // Wait two seconds for the USB detachment to register on the host
  56. * Delay_MS(2000);
  57. *
  58. * // Set the bootloader key to the magic value and force a reset
  59. * Boot_Key = MAGIC_BOOT_KEY;
  60. * wdt_enable(WDTO_250MS);
  61. * for (;;);
  62. * }
  63. * \endcode
  64. *
  65. * Note that the bootloader magic key can be any arbitrary value. The <em>FLASH_SIZE_BYTES</em> and
  66. * <em>BOOTLOADER_SEC_SIZE_BYTES</em> tokens should be replaced with the total flash size of the AVR
  67. * in bytes, and the allocated size of the bootloader section for the target AVR.
  68. *
  69. */