中级会员
 
- 积分
- 222
- 金钱
- 222
- 注册时间
- 2021-1-19
- 在线时间
- 81 小时
|
在有时候不知道系统是在哪里造成的重启,可以使用下面的函数去在系统重启打印查看重启的原因。当然,如果有J-Link等能很快就知道了,但是有的项目的特定条件并不能使用在线模拟调试的时候,只能是通过这样的方式去知道重启的原因。
本贴记录一下这样的问题,这里只是一些常用的重启原因,具体详细的请自行去往RCC_GetFlagStatus()查找你认为的原因
适用于F103系列,其他的系列自己看依据自己的情况自行修改
- void Check_Rst(void)
- {
- printf(" CSR = %x\r\n", RCC->CSR);
- if(RCC_GetFlagStatus(RCC_FLAG_PINRST) != RESET ) // NRST 引脚复位
- {
- printf("PIN reset \r\n");
- }
- if(RCC_GetFlagStatus(RCC_FLAG_PORRST) != RESET ) // 上电掉电复位
- {
- printf("POR/PDR reset \r\n");
- }
- if(RCC_GetFlagStatus(RCC_FLAG_SFTRST) != RESET ) // 软件复位
- {
- printf("Software reset \r\n");
- }
- if(RCC_GetFlagStatus(RCC_FLAG_IWDGRST) != RESET ) // 独立看门狗复位
- {
- printf("Independent watchdog reset \r\n");
- }
- if(RCC_GetFlagStatus(RCC_FLAG_WWDGRST) != RESET ) // 窗口看门狗复位
- {
- printf("Window watchdog reset \r\n");
- }
- if(RCC_GetFlagStatus(RCC_FLAG_LPWRRST) != RESET ) // 低功耗复位
- {
- printf("(Low-power reset \r\n");
- }
- RCC_ClearFlag(); //清除复位标志
- printf("\r\n");
- }
复制代码 以下为RCC_GetFlagStatus()在库函数的描述
- /**
- * @brief Checks whether the specified RCC flag is set or not.
- * [url=home.php?mod=space&uid=271674]@param[/url] RCC_FLAG: specifies the flag to check.
- *
- * For @b STM32_Connectivity_line_devices, this parameter can be one of the
- * following values:
- * @arg RCC_FLAG_HSIRDY: HSI oscillator clock ready
- * @arg RCC_FLAG_HSERDY: HSE oscillator clock ready
- * @arg RCC_FLAG_PLLRDY: PLL clock ready
- * @arg RCC_FLAG_PLL2RDY: PLL2 clock ready
- * @arg RCC_FLAG_PLL3RDY: PLL3 clock ready
- * @arg RCC_FLAG_LSERDY: LSE oscillator clock ready
- * @arg RCC_FLAG_LSIRDY: LSI oscillator clock ready
- * @arg RCC_FLAG_PINRST: Pin reset
- * @arg RCC_FLAG_PORRST: POR/PDR reset
- * @arg RCC_FLAG_SFTRST: Software reset
- * @arg RCC_FLAG_IWDGRST: Independent Watchdog reset
- * @arg RCC_FLAG_WWDGRST: Window Watchdog reset
- * @arg RCC_FLAG_LPWRRST: Low Power reset
- *
- * For @b other_STM32_devices, this parameter can be one of the following values:
- * @arg RCC_FLAG_HSIRDY: HSI oscillator clock ready
- * @arg RCC_FLAG_HSERDY: HSE oscillator clock ready
- * @arg RCC_FLAG_PLLRDY: PLL clock ready
- * @arg RCC_FLAG_LSERDY: LSE oscillator clock ready
- * @arg RCC_FLAG_LSIRDY: LSI oscillator clock ready
- * @arg RCC_FLAG_PINRST: Pin reset
- * @arg RCC_FLAG_PORRST: POR/PDR reset
- * @arg RCC_FLAG_SFTRST: Software reset
- * @arg RCC_FLAG_IWDGRST: Independent Watchdog reset
- * @arg RCC_FLAG_WWDGRST: Window Watchdog reset
- * @arg RCC_FLAG_LPWRRST: Low Power reset
- *
- * @retval The new state of RCC_FLAG (SET or RESET).
- */
复制代码
|
|