STM32 进行软件复位的方法

platform:stm32f103xx
include:core_cm3.h

/**
  rief   System Reset
  details Initiates a system reset request to reset the MCU.
 */
__NO_RETURN __STATIC_INLINE void __NVIC_SystemReset(void)
{
  __DSB();                                                          /* Ensure all outstanding memory accesses included
                                                                       buffered write are completed before reset */
  SCB->AIRCR  = (uint32_t)((0x5FAUL << SCB_AIRCR_VECTKEY_Pos)    |
                           (SCB->AIRCR & SCB_AIRCR_PRIGROUP_Msk) |
                            SCB_AIRCR_SYSRESETREQ_Msk    );         /* Keep priority group unchanged */
  __DSB();                                                          /* Ensure completion of memory access */

  for(;;)                                                           /* wait until reset */
  {
    __NOP();
  }
}
/**
  rief   Set Fault Mask
  details Assigns the given value to the Fault Mask register.
  param [in]    faultMask  Fault Mask value to set
 */
__STATIC_INLINE void __set_FAULTMASK(uint32_t faultMask)
{
  register uint32_t __regFaultMask       __ASM("faultmask");
  __regFaultMask = (faultMask & (uint32_t)1U);
}

直接调用soft_reset即可,亲测有效。

void soft_reset(void)
{
	// 关闭所有中断
    __set_FAULTMASK(1); 
    // 复位
    NVIC_SystemReset(); 
}
原文地址:https://www.cnblogs.com/unclemac/p/12783365.html