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.

47 lines
1.7 KiB

  1. /* Copyright 2021 QMK
  2. *
  3. * This program is free software: you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation, either version 3 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "bootloader.h"
  17. #include <ch.h>
  18. #include <hal.h>
  19. #define DBGMCU_KEY_UNLOCK 0x4B5A6978
  20. #define DBGMCU_CMD_RESET 0x1
  21. __IO uint32_t *DBGMCU_KEY = (uint32_t *)DBGMCU_BASE + 0x0CU;
  22. __IO uint32_t *DBGMCU_CMD = (uint32_t *)DBGMCU_BASE + 0x08U;
  23. __attribute__((weak)) void bootloader_jump(void) {
  24. /* The MTIMER unit of the GD32VF103 doesn't have the MSFRST
  25. * register to generate a software reset request.
  26. * BUT instead two undocumented registers in the debug peripheral
  27. * that allow issueing a software reset. WHO would need the MSFRST
  28. * register anyway? Source:
  29. * https://github.com/esmil/gd32vf103inator/blob/master/include/gd32vf103/dbg.h */
  30. *DBGMCU_KEY = DBGMCU_KEY_UNLOCK;
  31. *DBGMCU_CMD = DBGMCU_CMD_RESET;
  32. }
  33. __attribute__((weak)) void mcu_reset(void) {
  34. // Confirmed by karlk90, there is no actual reset to bootloader.
  35. // This just resets the controller.
  36. *DBGMCU_KEY = DBGMCU_KEY_UNLOCK;
  37. *DBGMCU_CMD = DBGMCU_CMD_RESET;
  38. }
  39. /* Jumping to bootloader is not possible from user code. */
  40. void enter_bootloader_mode_if_requested(void) {}