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.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #include "bootloader.h"
  2. #include "ch.h"
  3. #include "hal.h"
  4. #ifdef STM32_BOOTLOADER_ADDRESS
  5. /* STM32 */
  6. #if defined(STM32F0XX)
  7. /* This code should be checked whether it runs correctly on platforms */
  8. #define SYMVAL(sym) (uint32_t)(((uint8_t *)&(sym)) - ((uint8_t *)0))
  9. extern uint32_t __ram0_end__;
  10. void bootloader_jump(void) {
  11. *((unsigned long *)(SYMVAL(__ram0_end__) - 4)) = 0xDEADBEEF; // set magic flag => reset handler will jump into boot loader
  12. NVIC_SystemReset();
  13. }
  14. #else /* defined(STM32F0XX) */
  15. #error Check that the bootloader code works on your platform and add it to bootloader.c!
  16. #endif /* defined(STM32F0XX) */
  17. #elif defined(KL2x) || defined(K20x) /* STM32_BOOTLOADER_ADDRESS */
  18. /* Kinetis */
  19. #if defined(KIIBOHD_BOOTLOADER)
  20. /* Kiibohd Bootloader (MCHCK and Infinity KB) */
  21. #define SCB_AIRCR_VECTKEY_WRITEMAGIC 0x05FA0000
  22. const uint8_t sys_reset_to_loader_magic[] = "\xff\x00\x7fRESET TO LOADER\x7f\x00\xff";
  23. void bootloader_jump(void) {
  24. __builtin_memcpy((void *)VBAT, (const void *)sys_reset_to_loader_magic, sizeof(sys_reset_to_loader_magic));
  25. // request reset
  26. SCB->AIRCR = SCB_AIRCR_VECTKEY_WRITEMAGIC | SCB_AIRCR_SYSRESETREQ_Msk;
  27. }
  28. #else /* defined(KIIBOHD_BOOTLOADER) */
  29. /* Default for Kinetis - expecting an ARM Teensy */
  30. void bootloader_jump(void) {
  31. chThdSleepMilliseconds(100);
  32. __BKPT(0);
  33. }
  34. #endif /* defined(KIIBOHD_BOOTLOADER) */
  35. #else /* neither STM32 nor KINETIS */
  36. void bootloader_jump(void) {}
  37. #endif