/** * @file HW_RESET_ATY.c * * @param Project DEVICE_GENERAL_ATY_LIB * * @author ATY * * @copyright * - Copyright 2017 - 2025 MZ-ATY * - This code follows: * - MZ-ATY Various Contents Joint Statement - * * https://mengze.top/MZ-ATY_VCJS * - CC 4.0 BY-NC-SA - * * https://creativecommons.org/licenses/by-nc-sa/4.0/ * - Your use will be deemed to have accepted the terms of this statement. * * @brief Familiar functions of soft reset for CMSIS device * * @version * - 1_01_221029 > ATY * -# Preliminary version, first Release ******************************************************************************** */ #ifndef __HW_RESET_ATY_C #define __HW_RESET_ATY_C #include "HW_RESET_ATY.h" /******************************* For user *************************************/ /******************************************************************************/ /** * @brief reset chip */ __WEAK_ATY void SoftReset(void) { #if defined (__STC51_ATY) IAP_CONTR |= 0x60; // @STCISP# Auto ISP Flash Download #elif defined(__HC32_ATY) || \ defined(__STM32_SPL_ATY) || \ defined(__STM32_HAL_ATY)|| \ defined(__STM32_LL_ATY) // defined(__ICCARM__) || // defined(__CC_ARM) // for all CMSIS devices // __set_FAULTMASK(1); // close all IT __disable_irq(); __NVIC_SystemReset(); // reset #endif } void SoftReset_HAL(void) { // __set_FAULTMASK(1); // close all IT __disable_irq(); __NVIC_SystemReset(); // reset } /** * @brief * @note if the peripheral configurations between Bootloader and App are not consistent, * the peripherals need to be manually reset after the jump. Otherwise, make sure that * the peripheral settings used in the Bootloader match those in the App, including * system clock dividers and other clock-related parameters. * * remember to __enable_irq() at app main very begining */ void JumpToApp(uint32_t addr) { // Disable global interrupts __disable_irq(); HAL_DeInit(); /* execute the new program */ uint32_t JumpAddress = *(__IO uint32_t*) (addr + 4); /* Jump to user application */ typedef void (*pFunction)(void); pFunction JumpToApplication = (pFunction)JumpAddress; /* Initialize user application's Stack Pointer */ __set_MSP(*(__IO uint32_t*) addr); JumpToApplication(); } void UsbReconnect(void) { // put after SystemClock_Config(); and before MX_GPIO_Init(); // restart usb connect GPIO_InitTypeDef GPIO_InitStruct; __HAL_RCC_GPIOA_CLK_ENABLE(); GPIO_InitStruct.Pin = GPIO_PIN_12; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_PULLDOWN; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, GPIO_PIN_RESET); HAL_Delay(200); HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, GPIO_PIN_SET); HAL_Delay(200); } #endif /* __HW_RESET_ATY_C */ /******************************** End Of File *********************************/