Nucleo-F411RE (STM32F411)LL库体验 2 -sysclk的配置
1、Nucleo-F411RE 时钟源
Nucleo-F411RE开发版只有一个8M的晶振,看起来像是给st-link提供时钟的,所以猜测F411RE时钟的来源应该来自st-link(stm32F103c8t6)的mco输出。
mco输出频率为8M。
HSI频率为16M。
2、设置工作主频100M
a、采用HSE+PLL
假设mco输入频率8M,经过PLLM,4分频变成2M。然后经过PLLN,倍频100,变成200M,那么再经过
PLLP 2分频就可变成100M的时钟频率。
如果工作频率80M,那么就修改倍频80即可。
LL库代码如下:
/**
* @brief System Clock Configuration
* @retval None
*/
void SystemClock_HSE_PLL_100M_Config(void)
{
LL_FLASH_SetLatency(LL_FLASH_LATENCY_3);
while(LL_FLASH_GetLatency()!= LL_FLASH_LATENCY_3)
{
}
LL_PWR_SetRegulVoltageScaling(LL_PWR_REGU_VOLTAGE_SCALE1);
// while (LL_PWR_IsActiveFlag_VOS() == 0)
// {
// }
LL_RCC_HSE_EnableBypass();
LL_RCC_HSE_Enable();
/* Wait till HSE is ready */
while(LL_RCC_HSE_IsReady() != 1)
{
}
LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSE, LL_RCC_PLLM_DIV_4, 100, LL_RCC_PLLP_DIV_2);
LL_RCC_PLL_Enable();
/* Wait till PLL is ready */
while(LL_RCC_PLL_IsReady() != 1)
{
}
LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1);
LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_2);
LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1);
LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL);
/* Wait till System clock is ready */
while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL)
{
}
LL_Init1msTick(100000000);
LL_SetSystemCoreClock(100000000);
LL_RCC_SetTIMPrescaler(LL_RCC_TIM_PRESCALER_TWICE);
}
b、采用HSI+PLL的方式
HSI的频率为16M,假设经过PLLM 8分频变成2M,经过PLLN 100倍频变成200M,经过PLLP 2分频即可得到100M的工作频率。
如果想要设定80M工作频率,修改倍频80倍即可。
代码如下:
/**
* HSI + PLL 100M
*/
void SystemClock_HSI_PLL_100M_Config(void)
{
LL_FLASH_SetLatency(LL_FLASH_LATENCY_3);
while(LL_FLASH_GetLatency()!= LL_FLASH_LATENCY_3)
{
}
LL_PWR_SetRegulVoltageScaling(LL_PWR_REGU_VOLTAGE_SCALE1);
// while (LL_PWR_IsActiveFlag_VOS() == 0)
// {
// }
LL_RCC_HSI_SetCalibTrimming(16);
LL_RCC_HSI_Enable();
/* Wait till HSI is ready */
while(LL_RCC_HSI_IsReady() != 1)
{
}
LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLLM_DIV_8, 100, LL_RCC_PLLP_DIV_2);
LL_RCC_PLL_Enable();
/* Wait till PLL is ready */
while(LL_RCC_PLL_IsReady() != 1)
{
}
LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1);
LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_2);
LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1);
LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL);
/* Wait till System clock is ready */
while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL)
{
}
LL_Init1msTick(100000000);
LL_SetSystemCoreClock(100000000);
LL_RCC_SetTIMPrescaler(LL_RCC_TIM_PRESCALER_TWICE);
}
3、不使用锁频环PLL
a、HSE最高8M工作主频
LL库设定代码如下:
/**
* HSE提供信号,不经过pll倍频
*/
void SystemClock_HSE_8M_Config(void)
{
LL_FLASH_SetLatency(LL_FLASH_LATENCY_0);
while(LL_FLASH_GetLatency()!= LL_FLASH_LATENCY_0)
{
}
LL_PWR_SetRegulVoltageScaling(LL_PWR_REGU_VOLTAGE_SCALE1);
// while (LL_PWR_IsActiveFlag_VOS() == 0)
// {
// }
LL_RCC_HSE_EnableBypass();
LL_RCC_HSE_Enable();
/* Wait till HSE is ready */
while(LL_RCC_HSE_IsReady() != 1)
{
}
LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1);
LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_2);
LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1);
LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_HSE);
/* Wait till System clock is ready */
while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_HSE)
{
}
LL_Init1msTick(8000000);
LL_SetSystemCoreClock(8000000);
LL_RCC_SetTIMPrescaler(LL_RCC_TIM_PRESCALER_TWICE);
}
b、HSL最高16M工作主频
LL库设定代码如下:
/**
* HSI提供信号,不经过pll倍频
*/
void SystemClock_HSI_16M_Config(void)
{
LL_FLASH_SetLatency(LL_FLASH_LATENCY_0);
while(LL_FLASH_GetLatency()!= LL_FLASH_LATENCY_0)
{
}
LL_PWR_SetRegulVoltageScaling(LL_PWR_REGU_VOLTAGE_SCALE1);
// while (LL_PWR_IsActiveFlag_VOS() == 0)
// {
// }
LL_RCC_HSI_SetCalibTrimming(16);
LL_RCC_HSI_Enable();
/* Wait till HSI is ready */
while(LL_RCC_HSI_IsReady() != 1)
{
}
LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1);
LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_2);
LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1);
LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_HSI);
/* Wait till System clock is ready */
while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_HSI)
{
}
LL_Init1msTick(16000000);
LL_SetSystemCoreClock(16000000);
LL_RCC_SetTIMPrescaler(LL_RCC_TIM_PRESCALER_TWICE);
}
4、AHB APB1 APB2时钟
设定AHB不分频
APB1 2分频
APB2不分频
假定输入100M,那么APB=sysclk=100M,APB1=PLCK1 = 50M,APB2=PLK2=100M
5、获取各部分时钟
6、打印信息
7、 代码
代码下载