STM32-About the flag bit of RCC in K5

 

STM32 clock system block diagram

STM32 has 4 independent clock sources: HSI, HSE, LSI, LSE.
①, HSI is a high-speed internal clock, RC oscillator, the frequency is 8MHz, the accuracy is not high.
② HSE is a high-speed external clock, which can be connected to a quartz/ceramic resonator or an external clock source. The frequency range is 4MHz~16MHz .
③ LSI is a low-speed internal clock, RC oscillator, with a frequency of 40kHz, providing a low-power clock.  
④, LSE is a low-speed external clock, connected to a quartz crystal with a frequency of 32.768kHz.

Wherein the LSI as IWDGCLK (independent watchdog) and the RTC clock source clock source  used independently 

And HSI high-speed internal clock, HSE high-speed external clock, PLL phase-locked loop clock, these three are used as system clock after frequency division or frequency multiplication.

PLL is a phase-locked loop frequency multiplication output, and its clock input source can be selected as HSI/2, HSE or HSE/2 . The frequency multiplier can be selected from 2 to 16 times, but the maximum output frequency should not exceed 72MHz. As the clock source of the system clock after frequency multiplication

 

In MDK5, we set the system clock. First, we need to know which symbols are used to replace the system clock switch:

RCC_FLAG_HSIRDY: HSI oscillator clock ready
/*高速内部时钟振荡器准备就绪*/
RCC_FLAG_HSERDY: HSE oscillator clock ready   
/*高速外部时钟振荡器准备就绪*/                        
RCC_FLAG_PLLRDY: PLL clock ready
/*锁相环倍频输出准备就绪*/
RCC_FLAG_LSERDY: LSE oscillator clock ready
/*低速外部时钟振荡器准备就绪*/
RCC_FLAG_LSIRDY: LSI oscillator clock ready
/*低速内部时钟振荡器准备就绪*/
RCC_FLAG_PINRST: Pin reset
/*对引脚进行复位*/
RCC_FLAG_PORRST: POR/PDR reset
/*上电或断电复位*/
RCC_FLAG_SFTRST: Software reset
/*软件复位*/
RCC_FLAG_IWDGRST: Independent Watchdog reset
/*独立看门狗复位*/
RCC_FLAG_WWDGRST: Window Watchdog reset
/*窗看门狗复位*/
RCC_FLAG_LPWRRST: Low Power reset
/*低功耗复位*/

 Why use these symbols instead, can't we write it ourselves? First of all, we have to know that this is defined automatically by the system. We only need to call these parameters. This is the definition of them I found in the library file:

#define RCC_FLAG_HSIRDY                  ((uint8_t)0x21)
#define RCC_FLAG_HSERDY                  ((uint8_t)0x31)
#define RCC_FLAG_PLLRDY                  ((uint8_t)0x39)
#define RCC_FLAG_PLLI2SRDY               ((uint8_t)0x3B)

/* Flags in the BDCR register */
#define RCC_FLAG_LSERDY                  ((uint8_t)0x41)

/* Flags in the CSR register */
#define RCC_FLAG_LSIRDY                  ((uint8_t)0x61)
#define RCC_FLAG_BORRST                  ((uint8_t)0x79)
#define RCC_FLAG_PINRST                  ((uint8_t)0x7A)
#define RCC_FLAG_PORRST                  ((uint8_t)0x7B)
#define RCC_FLAG_SFTRST                  ((uint8_t)0x7C)
#define RCC_FLAG_IWDGRST                 ((uint8_t)0x7D)
#define RCC_FLAG_WWDGRST                 ((uint8_t)0x7E)
#define RCC_FLAG_LPWRRST                 ((uint8_t)0x7F)
int main(void)
{
  	/* 设置系统时钟 */
  	RCC_Configuration();
  	/* 设置 GPIO 端口 */
  	GPIO_Configuration();
	/* 设置 EXIT */
  	EXTI_Configuration();
  	/* 设置 NVIC */
  	NVIC_Configuration();
	/* 设置 USART1 */
	USART_Configuration();

  	/* 检查是否发生过独立看门狗复位 ,是则进入if()内部,否则进入else内部 */
	if(RCC_GetFlagStatus(RCC_FLAG_IWDGRST) != RESET)
	{
		printf("\r\n The STM32 has been reset by IWDG  \r\n");	
		/* 清除看门狗复位标志 */
    	RCC_ClearFlag();
	}
  	else
  	{
		printf("\r\n The STM32 has't been reset by IWDG before  \r\n");
		/* 设置 Systick 定时器 */
		SysTick_Configuration();
		/* 设置 IWDG */
		IWDG_Configuration();
  	}
 	while(1);
}

 

 

Guess you like

Origin blog.csdn.net/qq_39530692/article/details/112318465