/** * @brief To select HSI as System clock source * @caller ADC_Icc_Test * @param None * @retval None */ void SetHSICLK(void) { /* Enable HSI Clock */ RCC_HSICmd(ENABLE); /*!< Wait till HSI is ready */ while (RCC_GetFlagStatus(RCC_FLAG_HSIRDY) == RESET); /* Enable 64-bit access */ FLASH_ReadAccess64Cmd(ENABLE); /* Enable Prefetch Buffer */ FLASH_PrefetchBufferCmd(ENABLE); /* Flash 1 wait state */ FLASH_SetLatency(FLASH_Latency_1); RCC_SYSCLKConfig(RCC_SYSCLKSource_HSI); while (RCC_GetSYSCLKSource() != 0x04); RCC_HCLKConfig(RCC_SYSCLK_Div1); /* PCLK2 = HCLK */ RCC_PCLK2Config(RCC_HCLK_Div1); /* PCLK1 = HCLK */ RCC_PCLK1Config(RCC_HCLK_Div1); }
/** * @brief Selects HSE as System clock source and configure HCLK, PCLK2 and PCLK1 prescalers. * @param None * @retval None */ void SetHCLKTo8(void) { /* SYSCLK, HCLK, PCLK2 and PCLK1 configuration -----------------------------*/ /* RCC system reset(for debug purpose) */ RCC_DeInit(); /* Enable HSE */ RCC_HSEConfig(RCC_HSE_ON); /* Wait till HSE is ready */ HSEStartUpStatus = RCC_WaitForHSEStartUp(); if (HSEStartUpStatus == SUCCESS) { /* Flash 0 wait state */ FLASH_SetLatency(FLASH_Latency_0); /* Disable Prefetch Buffer */ FLASH_PrefetchBufferCmd(DISABLE); /* Disable 64-bit access */ FLASH_ReadAccess64Cmd(DISABLE); /* Enable the PWR APB1 Clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); /* Select the Voltage Range 2 (1.5V) */ PWR_VoltageScalingConfig(PWR_VoltageScaling_Range2); /* Wait Until the Voltage Regulator is ready */ while (PWR_GetFlagStatus(PWR_FLAG_VOS) != RESET) {} /* HCLK = SYSCLK */ RCC_HCLKConfig(RCC_SYSCLK_Div1); /* PCLK2 = HCLK */ RCC_PCLK2Config(RCC_HCLK_Div1); /* PCLK1 = HCLK */ RCC_PCLK1Config(RCC_HCLK_Div1); /* Select HSE as system clock source */ RCC_SYSCLKConfig(RCC_SYSCLKSource_HSE); /* Wait till HSE is used as system clock source */ while (RCC_GetSYSCLKSource() != 0x08) {} } else { /* If HSE fails to start-up, the application will have wrong clock configuration. User can add here some code to deal with this error */ /* Go to infinite loop */ while (1) {} } }
/** * @brief To select MSI as System clock source * @caller ADC_Icc_Test * @param Frequence, DIV by 2 ot not , With or without RTC * @retval None */ void SetHSICLKToMSI(uint32_t freq,bool div2,bool With_RTC) { /* RCC system reset */ RCC_DeInit(); /* Flash 1 wait state */ FLASH_SetLatency(FLASH_Latency_0); /* Disable Prefetch Buffer */ FLASH_PrefetchBufferCmd(DISABLE); /* Disable 64-bit access */ FLASH_ReadAccess64Cmd(DISABLE); /* Disable FLASH during SLeep */ FLASH_SLEEPPowerDownCmd(ENABLE); /* Enable the PWR APB1 Clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); /* Select the Voltage Range 3 (1.2V) */ PWR_VoltageScalingConfig(PWR_VoltageScaling_Range3); /* Wait Until the Voltage Regulator is ready */ while (PWR_GetFlagStatus(PWR_FLAG_VOS) != RESET) {} /* To configure the MSI frequency */ RCC_MSIRangeConfig(freq); /* Select MSI as system clock source */ RCC_SYSCLKConfig(RCC_SYSCLKSource_MSI); /* Wait till MSI is used as system clock source */ while (RCC_GetSYSCLKSource() != 0x00) {} if (div2) { RCC_HCLKConfig(RCC_SYSCLK_Div2); } RCC_HSICmd(DISABLE); /* Disable HSE clock */ RCC_HSEConfig(RCC_HSE_OFF); /* Disable LSE clock */ if (! With_RTC) RCC_LSEConfig(RCC_LSE_OFF); /* Disable LSI clock */ RCC_LSICmd(DISABLE); }
void initPowerSubsystem() { RCC_MSIRangeConfig(RCC_MSIRange_4); new_power_state = POWER_STATE_MED_SPEED; currentCPU_HZ = powerStateClockFrequency(new_power_state); SysTick_Config(powerStateClockFrequency(new_power_state) / configTICK_RATE_HZ); current_power_state = new_power_state; PWR_VoltageScalingConfig(PWR_VoltageScaling_Range3); FLASH_SetLatency(FLASH_Latency_0); FLASH_PrefetchBufferCmd(DISABLE); FLASH_ReadAccess64Cmd(DISABLE); }
/** * @brief Selects MSI (64KHz) as System clock source and configure * HCLK, PCLK2 and PCLK1 prescalers. * @param None * @retval None */ void SetHCLKToMSI_64KHz(void) { /* RCC system reset */ RCC_DeInit(); /* Flash 0 wait state */ FLASH_SetLatency(FLASH_Latency_0); /* Disable Prefetch Buffer */ FLASH_PrefetchBufferCmd(DISABLE); /* Disable 64-bit access */ FLASH_ReadAccess64Cmd(DISABLE); /* Enable the PWR APB1 Clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); /* Select the Voltage Range 3 (1.2V) */ PWR_VoltageScalingConfig(PWR_VoltageScaling_Range3); /* Wait Until the Voltage Regulator is ready */ while (PWR_GetFlagStatus(PWR_FLAG_VOS) != RESET) {} /* HCLK = SYSCLK */ RCC_HCLKConfig(RCC_SYSCLK_Div1); /* PCLK2 = HCLK */ RCC_PCLK2Config(RCC_HCLK_Div1); /* PCLK1 = HCLK */ RCC_PCLK1Config(RCC_HCLK_Div1); /* Set MSI clock range to 64KHz */ RCC_MSIRangeConfig(RCC_MSIRange_0); /* Select MSI as system clock source */ RCC_SYSCLKConfig(RCC_SYSCLKSource_MSI); /* Wait till PLL is used as system clock source */ while (RCC_GetSYSCLKSource() != 0x00) {} }
/** * @brief Selects MSI (Default Value, 2MHz) as System clock source and configure * HCLK, PCLK2 and PCLK1 prescalers. * @param None * @retval None */ void SetHCLKToMSI_2MHz(void) { /* RCC system reset */ RCC_DeInit(); /* Flash 0 wait state */ FLASH_SetLatency(FLASH_Latency_0); /* Disable Prefetch Buffer */ FLASH_PrefetchBufferCmd(DISABLE); /* Disable 64-bit access */ FLASH_ReadAccess64Cmd(DISABLE); /* Enable the PWR APB1 Clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); /* Select the Voltage Range 3 (1.2V) */ PWR_VoltageScalingConfig(PWR_VoltageScaling_Range3); /* Wait Until the Voltage Regulator is ready */ while (PWR_GetFlagStatus(PWR_FLAG_VOS) != RESET) {} }
/** * @brief Selects HSI as System clock source and configure HCLK, PCLK2 and PCLK1 prescalers. * @param None * @retval None */ void SetHCLKToHSI(void) { __IO uint32_t StartUpCounter = 0, HSIStatus = 0; /* SYSCLK, HCLK, PCLK2 and PCLK1 configuration -----------------------------*/ /* RCC system reset(for debug purpose) */ RCC_DeInit(); /* Enable HSI */ RCC_HSICmd(ENABLE); /* Wait till HSI is ready and if Time out is reached exit */ do { HSIStatus = RCC_GetFlagStatus(RCC_FLAG_HSIRDY); StartUpCounter++; } while ((HSIStatus == 0) && (StartUpCounter != HSI_STARTUP_TIMEOUT)); if (RCC_GetFlagStatus(RCC_FLAG_HSIRDY) != RESET) { HSIStatus = (uint32_t)0x01; } else { HSIStatus = (uint32_t)0x00; } if (HSIStatus == 0x01) { /* Flash 0 wait state */ FLASH_SetLatency(FLASH_Latency_0); /* Disable Prefetch Buffer */ FLASH_PrefetchBufferCmd(DISABLE); /* Disable 64-bit access */ FLASH_ReadAccess64Cmd(DISABLE); /* Enable the PWR APB1 Clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); /* Select the Voltage Range 1 (1.8V) */ PWR_VoltageScalingConfig(PWR_VoltageScaling_Range1); /* Wait Until the Voltage Regulator is ready */ while (PWR_GetFlagStatus(PWR_FLAG_VOS) != RESET) {} /* HCLK = SYSCLK */ RCC_HCLKConfig(RCC_SYSCLK_Div1); /* PCLK2 = HCLK */ RCC_PCLK2Config(RCC_HCLK_Div1); /* PCLK1 = HCLK */ RCC_PCLK1Config(RCC_HCLK_Div1); /* Select HSI as system clock source */ RCC_SYSCLKConfig(RCC_SYSCLKSource_HSI); /* Wait till HSI is used as system clock source */ while (RCC_GetSYSCLKSource() != 0x04) {} } else { /* If HSI fails to start-up, the application will have wrong clock configuration. User can add here some code to deal with this error */ /* Go to infinite loop */ while (1) {} } }
/** * @brief This function configures the system to enter Low Power Run mode for * current consumption measurement purpose. * The maximum clock when the system is in Low Power Run mode is ~128KHz. * This mode can only be entered when Voltage Range 2 is selected. * Low Power Run Mode from SRAM: * ============================= * - System Running at MSI (~32KHz) * - Flash 0 wait state * - Voltage Range 2 * - Code running from Internal SRAM * - All peripherals OFF * - FLASH switched OFF * - VDD from 1.65V to 3.6V * - Current Consumption ~10.5uA * - Wakeup using Key Button PA.00 * Low Power Run Mode from FLASH: * ============================== * - System Running at MSI (~32KHz) * - Flash 0 wait state * - Voltage Range 2 * - Code running from Internal FLASH * - All peripherals OFF * - VDD from 1.65V to 3.6V * - Current Consumption ~25uA * - Wakeup using Key Button PA.00 * @param None * @retval None */ void LowPowerRunMode_Measure(void) { /* Configure the System Clock to MSI Range 0 (65KHz). ----------------------*/ /* RCC system reset */ RCC_DeInit(); /* Flash 0 wait state */ FLASH_SetLatency(FLASH_Latency_0); /* Disable Prefetch Buffer */ FLASH_PrefetchBufferCmd(DISABLE); /* Disable 64-bit access */ FLASH_ReadAccess64Cmd(DISABLE); /* Enable the PWR APB1 Clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); /* Select the Voltage Range 2 (1.5V) */ PWR_VoltageScalingConfig(PWR_VoltageScaling_Range2); /* Wait Until the Voltage Regulator is ready */ while(PWR_GetFlagStatus(PWR_FLAG_VOS) != RESET) { } /* HCLK = SYSCLK/2 = ~32KHz */ RCC_HCLKConfig(RCC_SYSCLK_Div2); /* PCLK2 = HCLK */ RCC_PCLK2Config(RCC_HCLK_Div1); /* PCLK1 = HCLK */ RCC_PCLK1Config(RCC_HCLK_Div1); /* Set MSI clock range to 65.536KHz */ RCC_MSIRangeConfig(RCC_MSIRange_0); /* Select MSI as system clock source */ RCC_SYSCLKConfig(RCC_SYSCLKSource_MSI); /* Wait till PLL is used as system clock source */ while (RCC_GetSYSCLKSource() != 0x00) {} /* Configure all GPIO as analog to reduce current consumption on non used IOs */ /* Enable GPIOs clock */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOB | RCC_AHBPeriph_GPIOC | RCC_AHBPeriph_GPIOD | RCC_AHBPeriph_GPIOE | RCC_AHBPeriph_GPIOH | RCC_AHBPeriph_GPIOF | RCC_AHBPeriph_GPIOG, ENABLE); GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All; GPIO_Init(GPIOC, &GPIO_InitStructure); GPIO_Init(GPIOD, &GPIO_InitStructure); GPIO_Init(GPIOE, &GPIO_InitStructure); GPIO_Init(GPIOH, &GPIO_InitStructure); GPIO_Init(GPIOF, &GPIO_InitStructure); GPIO_Init(GPIOG, &GPIO_InitStructure); GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_Init(GPIOB, &GPIO_InitStructure); /* Disable GPIOs clock */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOB | RCC_AHBPeriph_GPIOC | RCC_AHBPeriph_GPIOD | RCC_AHBPeriph_GPIOE | RCC_AHBPeriph_GPIOH | RCC_AHBPeriph_GPIOF | RCC_AHBPeriph_GPIOG, DISABLE); /* Configure Key Button*/ STM_EVAL_PBInit(BUTTON_KEY,BUTTON_MODE_GPIO); /* Wait Until Key button pressed */ while(STM_EVAL_PBGetState(BUTTON_KEY) == RESET) { } /* Wait Until Key button pressed */ while(STM_EVAL_PBGetState(BUTTON_KEY) != RESET) { } /* Enter RUN LP Mode */ PWR_EnterLowPowerRunMode(ENABLE); /* Wait until the system enters RUN LP and the Regulator is in LP mode */ while(PWR_GetFlagStatus(PWR_FLAG_REGLP) == RESET) { } /* Jump to Internal SRAM and Switch the internal FLASH OFF */ #if defined (LP_RUN_SRAM_MODE) LowPowerRunModeSRAM_Measure(); #elif defined (LP_RUN_FLASH_MODE) /* Wait Until Key button pressed */ while(STM_EVAL_PBGetState(BUTTON_KEY) == RESET) { } /* Wait Until Key button pressed */ while(STM_EVAL_PBGetState(BUTTON_KEY) != RESET) { } #endif /* Exit the RUN LP Mode */ PWR_EnterLowPowerRunMode(DISABLE); /* Wait until the system exits RUN LP and the Regulator is in main mode */ while(PWR_GetFlagStatus(PWR_FLAG_REGLP) != RESET) { } /* Infinite loop */ while (1) { } }
/** * @brief This function configures the system to enter Low Power Sleep mode for * current consumption measurement purpose. * The maximum clock when the system is in Low Power Run mode is ~128KHz. * This mode can only be entered when Voltage Range 2 is selected. * Low Power Sleep Mode * ==================== * - System Running at MSI (~32KHz) * - Flash 0 wait state * - Voltage Range 2 * - Code running from Internal FLASH * - All peripherals OFF * - VDD from 1.65V to 3.6V * - Current Consumption ~4.07uA * - Wakeup using EXTI Line (Key Button PA.00) * @param None * @retval None */ void LowPowerSleepMode_Measure(void) { /* Configure the System Clock to MSI Range 0 (65KHz). ----------------------*/ /* RCC system reset */ RCC_DeInit(); /* Flash 0 wait state */ FLASH_SetLatency(FLASH_Latency_0); /* Disable Prefetch Buffer */ FLASH_PrefetchBufferCmd(DISABLE); /* Disable 64-bit access */ FLASH_ReadAccess64Cmd(DISABLE); /* Enable the PWR APB1 Clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); /* Select the Voltage Range 2 (1.5V) */ PWR_VoltageScalingConfig(PWR_VoltageScaling_Range2); /* Wait Until the Voltage Regulator is ready */ while(PWR_GetFlagStatus(PWR_FLAG_VOS) != RESET) { } /* HCLK = SYSCLK/2 = ~32KHz */ RCC_HCLKConfig(RCC_SYSCLK_Div2); /* PCLK2 = HCLK */ RCC_PCLK2Config(RCC_HCLK_Div1); /* PCLK1 = HCLK */ RCC_PCLK1Config(RCC_HCLK_Div1); /* Set MSI clock range to 65.536KHz */ RCC_MSIRangeConfig(RCC_MSIRange_0); /* Select MSI as system clock source */ RCC_SYSCLKConfig(RCC_SYSCLKSource_MSI); /* Wait till PLL is used as system clock source */ while (RCC_GetSYSCLKSource() != 0x00) {} /* Configure all GPIO as analog to reduce current consumption on non used IOs */ /* Enable GPIOs clock */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOB | RCC_AHBPeriph_GPIOC | RCC_AHBPeriph_GPIOD | RCC_AHBPeriph_GPIOE | RCC_AHBPeriph_GPIOH | RCC_AHBPeriph_GPIOF | RCC_AHBPeriph_GPIOG, ENABLE); GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All; GPIO_Init(GPIOC, &GPIO_InitStructure); GPIO_Init(GPIOD, &GPIO_InitStructure); GPIO_Init(GPIOE, &GPIO_InitStructure); GPIO_Init(GPIOH, &GPIO_InitStructure); GPIO_Init(GPIOF, &GPIO_InitStructure); GPIO_Init(GPIOG, &GPIO_InitStructure); GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_Init(GPIOB, &GPIO_InitStructure); /* Disable GPIOs clock */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOB | RCC_AHBPeriph_GPIOC | RCC_AHBPeriph_GPIOD | RCC_AHBPeriph_GPIOE | RCC_AHBPeriph_GPIOH | RCC_AHBPeriph_GPIOF | RCC_AHBPeriph_GPIOG, DISABLE); /* Configure Key Button*/ STM_EVAL_PBInit(BUTTON_KEY,BUTTON_MODE_GPIO); /* Wait Until Key button pressed */ while(STM_EVAL_PBGetState(BUTTON_KEY) == RESET) { } /* Wait Until Key button pressed */ while(STM_EVAL_PBGetState(BUTTON_KEY) != RESET) { } /* Configure Key Button*/ STM_EVAL_PBInit(BUTTON_KEY,BUTTON_MODE_EXTI); /* Enable The ultra Low Power Mode */ PWR_UltraLowPowerCmd(ENABLE); /* Enable the power down mode during Sleep mode */ FLASH_SLEEPPowerDownCmd(ENABLE); /* Request to enter SLEEP mode with regulator in low power mode */ PWR_EnterSleepMode(PWR_Regulator_LowPower, PWR_SLEEPEntry_WFI); /* Initialize LED1 on STM32L152-EVAL board */ STM_EVAL_LEDInit(LED1); /* Infinite loop */ while (1) { /* Toggle The LED1 */ STM_EVAL_LEDToggle(LED1); /* Inserted Delay */ for(index = 0; index < 0x5FF; index++); } }
/** * @brief This function configures the system to enter Sleep mode for * current consumption measurement purpose. * Sleep Mode * ========== * - System Running at HSI (16MHz) * - Flash 1 wait state * - Voltage Range 2 * - Code running from Internal FLASH * - Current Consumption ~1mA * - Wakeup using EXTI Line (Key Button PA.00) * @param None * @retval None */ void SleepMode_Measure(void) { /* Configure System Clock to HSI (16MHz) */ __IO uint32_t StartUpCounter = 0, HSIStatus = 0; /* SYSCLK, HCLK, PCLK2 and PCLK1 configuration -----------------------------*/ /* RCC system reset(for debug purpose) */ RCC_DeInit(); /* Enable HSI */ RCC_HSICmd(ENABLE); /* Wait till HSI is ready and if Time out is reached exit */ do { HSIStatus = RCC_GetFlagStatus(RCC_FLAG_HSIRDY); StartUpCounter++; } while((HSIStatus == 0) && (StartUpCounter != HSI_STARTUP_TIMEOUT)); if (RCC_GetFlagStatus(RCC_FLAG_HSIRDY) != RESET) { HSIStatus = (uint32_t)0x01; } else { HSIStatus = (uint32_t)0x00; } if (HSIStatus == 0x01) { /* Enable 64-bit access */ FLASH_ReadAccess64Cmd(ENABLE); /* Enable Prefetch Buffer */ FLASH_PrefetchBufferCmd(ENABLE); /* Flash 1 wait state */ FLASH_SetLatency(FLASH_Latency_1); /* Enable the PWR APB1 Clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); /* Select the Voltage Range 2 (1.5V) */ PWR_VoltageScalingConfig(PWR_VoltageScaling_Range2); /* Wait Until the Voltage Regulator is ready */ while(PWR_GetFlagStatus(PWR_FLAG_VOS) != RESET) { } /* HCLK = SYSCLK */ RCC_HCLKConfig(RCC_SYSCLK_Div1); /* PCLK2 = HCLK */ RCC_PCLK2Config(RCC_HCLK_Div1); /* PCLK1 = HCLK */ RCC_PCLK1Config(RCC_HCLK_Div1); /* Select HSI as system clock source */ RCC_SYSCLKConfig(RCC_SYSCLKSource_HSI); /* Wait till HSI is used as system clock source */ while (RCC_GetSYSCLKSource() != 0x04) {} } else { /* If HSI fails to start-up, the application will have wrong clock configuration. User can add here some code to deal with this error */ /* Go to infinite loop */ while (1) {} } /* Configure all GPIO as analog to reduce current consumption on non used IOs */ /* Enable GPIOs clock */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOB | RCC_AHBPeriph_GPIOC | RCC_AHBPeriph_GPIOD | RCC_AHBPeriph_GPIOE | RCC_AHBPeriph_GPIOH | RCC_AHBPeriph_GPIOF | RCC_AHBPeriph_GPIOG, ENABLE); GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All; GPIO_Init(GPIOC, &GPIO_InitStructure); GPIO_Init(GPIOD, &GPIO_InitStructure); GPIO_Init(GPIOE, &GPIO_InitStructure); GPIO_Init(GPIOH, &GPIO_InitStructure); GPIO_Init(GPIOF, &GPIO_InitStructure); GPIO_Init(GPIOG, &GPIO_InitStructure); GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_Init(GPIOB, &GPIO_InitStructure); /* Disable GPIOs clock */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOB | RCC_AHBPeriph_GPIOC | RCC_AHBPeriph_GPIOD | RCC_AHBPeriph_GPIOE | RCC_AHBPeriph_GPIOH | RCC_AHBPeriph_GPIOF | RCC_AHBPeriph_GPIOG, DISABLE); /* Configure Key Button*/ STM_EVAL_PBInit(BUTTON_KEY,BUTTON_MODE_GPIO); /* Wait Until Key button pressed */ while(STM_EVAL_PBGetState(BUTTON_KEY) == RESET) { } /* Wait Until Key button pressed */ while(STM_EVAL_PBGetState(BUTTON_KEY) != RESET) { } /* Configure Key Button*/ STM_EVAL_PBInit(BUTTON_KEY,BUTTON_MODE_EXTI); /* Request to enter SLEEP mode with regulator ON */ PWR_EnterSleepMode(PWR_Regulator_ON, PWR_SLEEPEntry_WFI); /* Initialize LED1 on STM32L152-EVAL board */ STM_EVAL_LEDInit(LED1); /* Infinite loop */ while (1) { /* Toggle The LED1 */ STM_EVAL_LEDToggle(LED1); /* Inserted Delay */ for(index = 0; index < 0x5FFFF; index++); } }
//**************************************************************************// void hal_system_RCC_init(void) { RCC_DeInit();//RCC system reset(for debug purpose) RCC_HSEConfig(RCC_HSE_ON);//Enable HSE //RCC_HSEConfig(RCC_HSE_ON); if ( RCC_WaitForHSEStartUp() == SUCCESS) { FLASH_ReadAccess64Cmd(ENABLE); FLASH_PrefetchBufferCmd(ENABLE); // Flash 0 wait state FLASH_SetLatency(FLASH_Latency_1); //Power enable RCC->APB1ENR |= RCC_APB1ENR_PWREN; // Select the Voltage Range 1 (1.8 V) */ PWR->CR = PWR_CR_VOS_0; // HCLK = SYSCLK RCC_HCLKConfig(RCC_SYSCLK_Div1); // PCLK2 = HCLK RCC_PCLK2Config(RCC_HCLK_Div1); // PCLK1 = HCLK RCC_PCLK1Config(RCC_HCLK_Div1); //PLLCLK = 16MHz *4/2 = 32 MHz RCC_PLLConfig(RCC_PLLSource_HSE, RCC_PLLMul_4,RCC_PLLDiv_2);//RCC_PLLDiv_2 //RCC_PLLConfig(RCC_PLLSource_HSI, RCC_PLLMul_4,RCC_PLLDiv_2); RCC_PLLCmd(ENABLE);// Enable PLL while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)// Wait till PLL is ready {} RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);//Select PLL as system clock source //RCC_HCLKConfig(RCC_SYSCLK_Div1);// HCLK = SYSCLK //RCC_PCLK2Config(RCC_HCLK_Div1);// PCLK2 = HCLK/4 //RCC_PCLK1Config(RCC_HCLK_Div1);//RCC_HCLK_Div1 PCLK1 = HCLK/1 /* Wait till PLL is used as system clock source */ // while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS) != (uint32_t)RCC_CFGR_SWS_HSE) // { // } } //SystemInit(); /*RCC_ClocksTypeDef RCC_ClockFreq; RCC_ClockFreq.SYSCLK_Frequency=RCC_SYSCLKSource_HSE; RCC_ClockFreq.HCLK_Frequency=RCC_SYSCLK_Div1; RCC_ClockFreq.PCLK1_Frequency=RCC_HCLK_Div1; RCC_ClockFreq.PCLK2_Frequency=RCC_HCLK_Div2; RCC_GetClocksFreq(&RCC_ClockFreq);*/ RCC_ClockSecuritySystemCmd(ENABLE); }