我们产品有3个模式,正常工作模式(48MHZ HSI),休眠模式(8MHZ HSI),省电模式(48MHZ HSI)
1, 上电默认会将产品配置到正常工作模式,但是当系统从省电模式恢复到正常工作模式时,系统会死机。(注:当我们MASK下面的时钟初始化代码就不会有这个问题。而且不是所有的机子都会出现)
2, 可是在休眠模式恢复到正常工作模式时,就不会死机。是运行同一段代码。
时钟初始化代码为:
LL_RCC_DeInit();
LL_FLASH_SetLatency(LL_FLASH_LATENCY_0);
/[i] LSI configura
tion and activation /
if(0 == LL_RCC_LSI_IsReady())
{
LL_RCC_LSI_Enable();
while(0 == LL_RCC_LSI_IsReady());}
s_eClockFreq = eClock;
LL_UTILS_PLLInitTypeDef stPllConf = {LL_RCC_PLLM_DIV_1, 1, LL_RCC_PLLR_DIV_2};
LL_UTILS_ClkInitTypeDef stClkConf = {LL_RCC_SYSCLK_DIV_1, LL_RCC_APB1_DIV_1};
/[i] Main PLL configuration and activation /
switch(eClock)
{
case E_CLOCK_FREQ_48MHZ:
// 16 * 12 / 2 / 2 = 48MstPllConf = {LL_RCC_PLLM_DIV_2, 12, LL_RCC_PLLR_DIV_2};stClkConf = {LL_RCC_SYSCLK_DIV_1, LL_RCC_APB1_DIV_1};LL_PLL_ConfigSystemClock_HSI( stPllConf, stClkConf);break;case E_CLOCK_FREQ_32MHZ:
// 16 * 8 / 2 = 64MstPllConf = {LL_RCC_PLLM_DIV_1, 8, LL_RCC_PLLR_DIV_2};// 64 / 2 = 32MstClkConf = {LL_RCC_SYSCLK_DIV_2, LL_RCC_APB1_DIV_1};LL_PLL_ConfigSystemClock_HSI( stPllConf, stClkConf);break;case E_CLOCK_FREQ_24MHZ:
// 16 * 12 / 2 / 2 = 48MstPllConf = {LL_RCC_PLLM_DIV_2, 12, LL_RCC_PLLR_DIV_2};// 48 / 2 = 24MstClkConf = {LL_RCC_SYSCLK_DIV_2, LL_RCC_APB1_DIV_1};LL_PLL_ConfigSystemClock_HSI( stPllConf, stClkConf);break;case E_CLOCK_FREQ_16MHZ:
// default is HSIbreak;case E_CLOCK_FREQ_4MHZ:
LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_4);break;case E_CLOCK_FREQ_8MHZ:
default:
LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_2);break;}
// update system clock frequency
SystemCoreClockUpdate();
LL_RCC_GetSystemClocksFreq( s_stSystemClocks);
// system tick configure
LL_SYSTICK_SetClkSource(LL_SYSTICK_CLKSOURCE_HCLK);
SysTick_Config((s_stSystemClocks.HCLK_Frequency / 1000));
// Enable used peripheral clock
Drv_Clk_EnableUsedPeripheralsClock();