微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > 启动过程都在这个文件的开头描述了system_stm32f10x.c

启动过程都在这个文件的开头描述了system_stm32f10x.c

时间:11-27 来源:互联网 点击:

RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLSRC_HSE | RCC_CFGR_PLLXTPRE_HSE_Div2 | RCC_CFGR_PLLMULL6);

#endif

RCC->CR |= RCC_CR_PLLON;

while((RCC->CR & RCC_CR_PLLRDY) == 0)

{

}

RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW));

RCC->CFGR |= (uint32_t)RCC_CFGR_SW_PLL;

while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS) != (uint32_t)0x08)

{

}

}

else

{

}

}

#elif defined SYSCLK_FREQ_36MHz

static void SetSysClockTo36(void)

{

__IO uint32_t StartUpCounter = 0, HSEStatus = 0;

RCC->CR |= ((uint32_t)RCC_CR_HSEON);

do

{

HSEStatus = RCC->CR & RCC_CR_HSERDY;

StartUpCounter++;

} while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));

if ((RCC->CR & RCC_CR_HSERDY) != RESET)

{

HSEStatus = (uint32_t)0x01;

}

else

{

HSEStatus = (uint32_t)0x00;

}

if (HSEStatus == (uint32_t)0x01)

{

FLASH->ACR |= FLASH_ACR_PRFTBE;

FLASH->ACR &= (uint32_t)((uint32_t)~FLASH_ACR_LATENCY);

FLASH->ACR |= (uint32_t)FLASH_ACR_LATENCY_1;

RCC->CFGR |= (uint32_t)RCC_CFGR_HPRE_div1;

RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE2_div1;

RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE1_div1;

#ifdef STM32F10X_CL

RCC->CFGR &= (uint32_t)~(RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLSRC | RCC_CFGR_PLLMULL);

RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLXTPRE_PREdiv1 | RCC_CFGR_PLLSRC_PREdiv1 |

RCC_CFGR_PLLMULL9);

RCC->CFGR2 &= (uint32_t)~(RCC_CFGR2_PREdiv2 | RCC_CFGR2_PLL2MUL |

RCC_CFGR2_PREdiv1 | RCC_CFGR2_PREdiv1SRC);

RCC->CFGR2 |= (uint32_t)(RCC_CFGR2_PREdiv2_div5 | RCC_CFGR2_PLL2MUL8 |

RCC_CFGR2_PREdiv1SRC_PLL2 | RCC_CFGR2_PREdiv1_div10);

RCC->CR |= RCC_CR_PLL2ON;

while((RCC->CR & RCC_CR_PLL2RDY) == 0)

{

}

#else

RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_PLLSRC | RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLMULL));

RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLSRC_HSE | RCC_CFGR_PLLXTPRE_HSE_Div2 | RCC_CFGR_PLLMULL9);

#endif

RCC->CR |= RCC_CR_PLLON;

while((RCC->CR & RCC_CR_PLLRDY) == 0)

{

}

RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW));

RCC->CFGR |= (uint32_t)RCC_CFGR_SW_PLL;

while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS) != (uint32_t)0x08)

{

}

}

else

{

}

}

#elif defined SYSCLK_FREQ_48MHz

static void SetSysClockTo48(void)

{

__IO uint32_t StartUpCounter = 0, HSEStatus = 0;

RCC->CR |= ((uint32_t)RCC_CR_HSEON);

do

{

HSEStatus = RCC->CR & RCC_CR_HSERDY;

StartUpCounter++;

} while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));

if ((RCC->CR & RCC_CR_HSERDY) != RESET)

{

HSEStatus = (uint32_t)0x01;

}

else

{

HSEStatus = (uint32_t)0x00;

}

if (HSEStatus == (uint32_t)0x01)

{

FLASH->ACR |= FLASH_ACR_PRFTBE;

FLASH->ACR &= (uint32_t)((uint32_t)~FLASH_ACR_LATENCY);

FLASH->ACR |= (uint32_t)FLASH_ACR_LATENCY_1;

RCC->CFGR |= (uint32_t)RCC_CFGR_HPRE_div1;

RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE2_div1;

RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE1_div2;

#ifdef STM32F10X_CL

RCC->CFGR2 &= (uint32_t)~(RCC_CFGR2_PREdiv2 | RCC_CFGR2_PLL2MUL |

RCC_CFGR2_PREdiv1 | RCC_CFGR2_PREdiv1SRC);

RCC->CFGR2 |= (uint32_t)(RCC_CFGR2_PREdiv2_div5 | RCC_CFGR2_PLL2MUL8 |

RCC_CFGR2_PREdiv1SRC_PLL2 | RCC_CFGR2_PREdiv1_div5);

RCC->CR |= RCC_CR_PLL2ON;

while((RCC->CR & RCC_CR_PLL2RDY) == 0)

{

}

RCC->CFGR &= (uint32_t)~(RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLSRC | RCC_CFGR_PLLMULL);

RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLXTPRE_PREdiv1 | RCC_CFGR_PLLSRC_PREdiv1 |

RCC_CFGR_PLLMULL6);

#else

RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_PLLSRC | RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLMULL));

RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLSRC_HSE | RCC_CFGR_PLLMULL6);

#endif

RCC->CR |= RCC_CR_PLLON;

while((RCC->CR & RCC_CR_PLLRDY) == 0)

{

}

RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW));

RCC->CFGR |= (uint32_t)RCC_CFGR_SW_PLL;

while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS) != (uint32_t)0x08)

{

}

}

else

{

}

}

#elif defined SYSCLK_FREQ_56MHz

static void SetSysClockTo56(void)

{

__IO uint32_t StartUpCounter = 0, HSEStatus = 0;

RCC->CR |= ((uint32_t)RCC_CR_HSEON);

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top