STM32复位函数

/*软件复位*/
void G_mcuReset(void)
{
	printf("\r\n\r\n\r\n%s\r\n\r\n\r\n",__FUNCTION__);
    __set_FAULTMASK(1);
    HAL_NVIC_SystemReset();	
}

其实HAL_NVIC_SystemReset是
void HAL_NVIC_SystemReset(void)
{
  NVIC_SystemReset();
}

其实NVIC_SystemReset是	
__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();
  }
}
系统复位

那么内核复位呢?仅仅只是复位内核,必如外面LED是亮的 它不受影响 只是内存数据丢失!
https://blog.csdn.net/ybhuangfugui/article/details/73354918
黄工文章有,我们MX代码里面没有!

我自己写:
__STATIC_INLINE void NVIC_CoreReset(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_VECTRESET_Msk    );         /* Keep priority group unchanged */
  __DSB();                                                          /* Ensure completion of memory access */

  for(;;)                                                           /* wait until reset */
  {
    __NOP();
  }
}

其实NVIC_CoreReset和NVIC_SystemReset基本一样 我换了一个SCB_AIRCR_VECTRESET_Msk

它在。h已经有宏定义了!!

下次测试:
void G_CoreReset(void)
{
	printf("\r\n\r\n\r\n%s\r\n\r\n\r\n",__FUNCTION__);
    __set_FAULTMASK(1);
    HAL_NVIC_CoreReset();	
}

void HAL_NVIC_CoreReset(void)
{
  NVIC_CoreReset();
}

 

你可能感兴趣的:(STM32复位函数)