HW_RESET_ATY.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /**
  2. * @file HW_RESET_ATY.c
  3. *
  4. * @param Project DEVICE_GENERAL_ATY_LIB
  5. *
  6. * @author ATY
  7. *
  8. * @copyright
  9. * - Copyright 2017 - 2025 MZ-ATY
  10. * - This code follows:
  11. * - MZ-ATY Various Contents Joint Statement -
  12. * <a href="https://mengze.top/MZ-ATY_VCJS">
  13. * https://mengze.top/MZ-ATY_VCJS</a>
  14. * - CC 4.0 BY-NC-SA -
  15. * <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/">
  16. * https://creativecommons.org/licenses/by-nc-sa/4.0/</a>
  17. * - Your use will be deemed to have accepted the terms of this statement.
  18. *
  19. * @brief Familiar functions of soft reset for CMSIS device
  20. *
  21. * @version
  22. * - 1_01_221029 > ATY
  23. * -# Preliminary version, first Release
  24. ********************************************************************************
  25. */
  26. #ifndef __HW_RESET_ATY_C
  27. #define __HW_RESET_ATY_C
  28. #include "HW_RESET_ATY.h"
  29. /******************************* For user *************************************/
  30. /******************************************************************************/
  31. /**
  32. * @brief reset chip
  33. */
  34. __WEAK_ATY void SoftReset(void)
  35. {
  36. #if defined (__STC51_ATY)
  37. IAP_CONTR |= 0x60; // @STCISP# Auto ISP Flash Download
  38. #elif defined(__HC32_ATY) || \
  39. defined(__STM32_SPL_ATY) || \
  40. defined(__STM32_HAL_ATY)|| \
  41. defined(__STM32_LL_ATY)
  42. // defined(__ICCARM__) ||
  43. // defined(__CC_ARM)
  44. // for all CMSIS devices
  45. // __set_FAULTMASK(1); // close all IT
  46. __disable_irq();
  47. __NVIC_SystemReset(); // reset
  48. #endif
  49. }
  50. void SoftReset_HAL(void)
  51. {
  52. // __set_FAULTMASK(1); // close all IT
  53. __disable_irq();
  54. __NVIC_SystemReset(); // reset
  55. }
  56. /**
  57. * @brief
  58. * @note if the peripheral configurations between Bootloader and App are not consistent,
  59. * the peripherals need to be manually reset after the jump. Otherwise, make sure that
  60. * the peripheral settings used in the Bootloader match those in the App, including
  61. * system clock dividers and other clock-related parameters.
  62. *
  63. * remember to __enable_irq() at app main very begining
  64. */
  65. void JumpToApp(uint32_t addr)
  66. {
  67. // Disable global interrupts
  68. __disable_irq();
  69. HAL_DeInit();
  70. /* execute the new program */
  71. uint32_t JumpAddress = *(__IO uint32_t*) (addr + 4);
  72. /* Jump to user application */
  73. typedef void (*pFunction)(void);
  74. pFunction JumpToApplication = (pFunction)JumpAddress;
  75. /* Initialize user application's Stack Pointer */
  76. __set_MSP(*(__IO uint32_t*) addr);
  77. JumpToApplication();
  78. }
  79. void UsbReconnect(void)
  80. {
  81. // put after SystemClock_Config(); and before MX_GPIO_Init();
  82. // restart usb connect
  83. GPIO_InitTypeDef GPIO_InitStruct;
  84. __HAL_RCC_GPIOA_CLK_ENABLE();
  85. GPIO_InitStruct.Pin = GPIO_PIN_12;
  86. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  87. GPIO_InitStruct.Pull = GPIO_PULLDOWN;
  88. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  89. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  90. HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, GPIO_PIN_RESET);
  91. HAL_Delay(200);
  92. HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, GPIO_PIN_SET);
  93. HAL_Delay(200);
  94. }
  95. #endif /* __HW_RESET_ATY_C */
  96. /******************************** End Of File *********************************/