/********************************************************************************************************* ** Function name: enter_low_power_mode ** Descriptions: enter_low_power_mode ** input parameters: none ** output parameters: none ** Returned value: none *********************************************************************************************************/ void enter_low_power_mode(POWER_MODE mode) { switch(mode) { case SLEEP: PWR_EnterSLEEPMode(PWR_Regulator_ON,PWR_SLEEPEntry_WFI); break; case STOP: PWR_EnterSTOPMode(PWR_Regulator_ON, PWR_STOPEntry_WFI); break; case LPSTOP: PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI); break; case STANDBY: PWR_EnterSTANDBYMode(); PWR_WakeUpPinCmd(ENABLE); break; default: break; } }
void HAL_Core_Execute_Stop_Mode(void) { /* Enable WKUP pin */ PWR_WakeUpPinCmd(ENABLE); /* Request to enter STOP mode with regulator in low power mode */ PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI); /* At this stage the system has resumed from STOP mode */ /* Enable HSE, PLL and select PLL as system clock source after wake-up from STOP */ /* Enable HSE */ RCC_HSEConfig(RCC_HSE_ON); /* Wait till HSE is ready */ if(RCC_WaitForHSEStartUp() != SUCCESS) { /* If HSE startup fails try to recover by system reset */ NVIC_SystemReset(); } /* Enable PLL */ RCC_PLLCmd(ENABLE); /* Wait till PLL is ready */ while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET); /* Select PLL as system clock source */ RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); /* Wait till PLL is used as system clock source */ while(RCC_GetSYSCLKSource() != 0x08); }
void Switchers_t::UpdateState(void) { if (FrontIsOn()) { if (BackIsOn()) { Acc.Disable(); TxOn(); } else { Acc.Enable(); TxOff(); } } else { Acc.Disable(); TxOff(); // Prepare to sleep: configure front switch GPIO line to be event source // Connect EXTI Line to front switch GPIO GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource1); // Configure front switch EXTI line EXTI_InitTypeDef EXTI_InitStructure; EXTI_InitStructure.EXTI_Line = EXTI_Line1; EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Event; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); // Enter sleep mode PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFE); // At this stage the system has resumed from STOP mode EXTI_InitStructure.EXTI_LineCmd = DISABLE; EXTI_Init(&EXTI_InitStructure); } }
/** * @brief This function configures the system to enter Stop mode for * current consumption measurement purpose. * STOP Mode * ========= * - Regulator in LP mode * - LSI, HSI and HSE OFF * - No IWDG * - Current Consumption ~0.5uA * - Wakeup using EXTI Line (Key Button PA.00) * @param None * @retval None */ void StopMode_Measure(void) { /* 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 Ultra low power mode */ PWR_UltraLowPowerCmd(ENABLE); /* Enter Stop Mode */ PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_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++); } }
void vApplicationIdleHook( void ) { if (jar_status == FULL) { PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI); } }
/** * @brief Prepare the system to enter STOP mode. * @param None * @retval None */ void STOPEntry(void) { /* Enable GPIOs clock */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOB | RCC_AHBPeriph_GPIOC | RCC_AHBPeriph_GPIOD | RCC_AHBPeriph_GPIOE | RCC_AHBPeriph_GPIOH, ENABLE); /* Configure all GPIO port pins in Analog mode */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_Init(GPIOC, &GPIO_InitStructure); GPIO_Init(GPIOD, &GPIO_InitStructure); GPIO_Init(GPIOE, &GPIO_InitStructure); GPIO_Init(GPIOH, &GPIO_InitStructure); #ifdef USE_STM32L152D_EVAL RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOF | RCC_AHBPeriph_GPIOG, ENABLE); GPIO_Init(GPIOF, &GPIO_InitStructure); GPIO_Init(GPIOG, &GPIO_InitStructure); #endif /* Request to enter STOP mode with regulator in low power */ PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI); }
void Sys_Standby(void) { stop_flag=1; // while(1) // { NVIC_SystemLPConfig(NVIC_LP_SLEEPDEEP,ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); //使能PWR和BKP外设时钟 PWR_WakeUpPinCmd(ENABLE); //使能唤醒管脚功能 //PWR_EnterSTANDBYMode(); //进入待命(STANDBY)模式 PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI); //在停机模式时,程序停在这个函数中 //PWR_EnterSTOPMode(PWR_Regulator_ON, PWR_STOPEntry_WFI); //在停机模式时,程序停在这个函数中 //WFI表示wait for interrupt,WFE表示wait for event //如果发生中断唤醒,会先执行中断程序 ,再执行PWR_EnterSTOPMode的下1行代码 //重新初始化 SystemInit(); //SoftReset(); // if(Check_WKUP()) // break; // if(longpress==0) // break; // } //重新初始化 //SystemInit(); }
/**----------------------------------------------------------------------------- * @brief Entree en mode Stop. */ void STOP_MODE() { EXTI_InitTypeDef EXTI_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; // Config IT SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource0); // Connect EXTI Line0 to PA0 pin // Configure EXTI Line0 EXTI_InitStructure.EXTI_Line = EXTI_Line0; EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); // Enable and set EXTI Line0 Interrupt to the lowest priority NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); // Config Mode Stop PWR_WakeUpPinCmd(ENABLE); PWR_BackupRegulatorCmd(DISABLE); PWR_FlashPowerDownCmd(ENABLE); /* Enable PWR and BKP clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); // Entree Mode Stop PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI); }
/*************************************************************************** Declaration : void sleep(char wdt_prescaler) Description : Sleep until WDT interrupt controlled by wdt_prescaler ***************************************************************************/ void sleep(int data_ms, char mode) { /* Enable the RTC Alarm interrupt */ RTC_ITConfig(RTC_IT_ALR, ENABLE); /* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask(); /* Alarm in data_ms */ // RTC_SetAlarm(RTC_GetCounter()+ data_ms<<5); RTC_SetAlarm(RTC_GetCounter()+ data_ms); /* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask(); /* Request to enter STOP mode with regulator ON */ PWR_EnterSTOPMode(PWR_Regulator_ON, PWR_STOPEntry_WFI); /* At this stage the system has resumed from STOP mode -------------------*/ /* Configures system clock after wake-up from STOP: enable HSE, PLL and select PLL as system clock source (HSE and PLL are disabled in STOP mode) */ /* Enable the RTC Alarm interrupt */ SYSCLKConfig_STOP(); RTC_ITConfig(RTC_IT_ALR, DISABLE); /* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask(); }
/******************************************************************************* * Function Name : main * Description : Main program. * Input : None * Output : None * Return : None *******************************************************************************/ int main(void) { #ifdef DEBUG debug(); #endif /* Clock configuration */ RCC_Configuration(); /* Enable PWR and BKP clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE); /* GPIO configuration */ GPIO_Configuration(); /* Configure EXTI Line to generate an interrupt on falling edge */ EXTI_Configuration(); /* Configure RTC clock source and prescaler */ RTC_Configuration(); /* NVIC configuration */ NVIC_Configuration(); /* Configure the SysTick to generate an interrupt each 1 millisecond */ SysTick_Configuration(); /* Turn on led connected to GPIO_LED Pin6 */ GPIO_SetBits(GPIO_LED, GPIO_Pin_6); while (1) { /* Insert 1.5 second delay */ Delay(1500); /* Wait till RTC Second event occurs */ RTC_ClearFlag(RTC_FLAG_SEC); while(RTC_GetFlagStatus(RTC_FLAG_SEC) == RESET); /* Alarm in 3 second */ RTC_SetAlarm(RTC_GetCounter()+ 3); /* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask(); /* Turn off led connected to GPIO_LED Pin6 */ GPIO_ResetBits(GPIO_LED, GPIO_Pin_6); /* Request to enter STOP mode with regulator in low power mode*/ PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI); /* At this stage the system has resumed from STOP mode -------------------*/ /* Turn on led connected to GPIO_LED Pin6 */ GPIO_SetBits(GPIO_LED, GPIO_Pin_6); /* Configures system clock after wake-up from STOP: enable HSE, PLL and select PLL as system clock source (HSE and PLL are disabled in STOP mode) */ SYSCLKConfig_STOP(); } }
/** * @brief Main program. * @param None * @retval None */ int main(void) { /* Setup the microcontroller system. Initialize the Embedded Flash Interface, initialize the PLL and update the SystemFrequency variable. */ SystemInit(); /* Initialize LEDs and Key Button mounted on STM3210X-EVAL board */ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); STM_EVAL_LEDInit(LED3); STM_EVAL_PBInit(Button_KEY, Mode_EXTI); /* Enable PWR and BKP clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE); /* Configure EXTI Line to generate an interrupt on falling edge */ EXTI_Configuration(); /* Configure RTC clock source and prescaler */ RTC_Configuration(); /* NVIC configuration */ NVIC_Configuration(); /* Configure the SysTick to generate an interrupt each 1 millisecond */ SysTick_Configuration(); /* Turn on LED1 */ STM_EVAL_LEDOn(LED1); while (1) { /* Insert 1.5 second delay */ Delay(1500); /* Wait till RTC Second event occurs */ RTC_ClearFlag(RTC_FLAG_SEC); while(RTC_GetFlagStatus(RTC_FLAG_SEC) == RESET); /* Alarm in 3 second */ RTC_SetAlarm(RTC_GetCounter()+ 3); /* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask(); /* Turn off LED1 */ STM_EVAL_LEDOff(LED1); /* Request to enter STOP mode with regulator in low power mode*/ PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI); /* At this stage the system has resumed from STOP mode -------------------*/ /* Turn on LED1 */ STM_EVAL_LEDOn(LED1); /* Configures system clock after wake-up from STOP: enable HSE, PLL and select PLL as system clock source (HSE and PLL are disabled in STOP mode) */ SYSCLKConfig_STOP(); } }
void task3(void) { OS_ERR err; BoardGPIOConfig();//IO口 UsartConfig();//串口设置配置 Nvic_Config(); SW_12V(1);//电源 SW_5V(1);//正负电源,用于检测回波Z FreqModuleInit();//测频率模块初始化 GetFreq(1); while(1) { // OSTimeDlyHMSM(0,0,500,0,OS_OPT_TIME_DLY,&err); // printf("SCT200T15002-Channel: 1 FREQUENCY:%f\r\n",GetFreq(1)); // printf("SCT200T15002-Channel: 2 FREQUENCY:%f\r\n",GetFreq(2)); // printf("SCT200T15002-Channel: 3 FREQUENCY:%f\r\n",GetFreq(3)); // printf("SCT200T15002-Channel: 4 FREQUENCY:%f\r\n",GetFreq(4)); OSTimeDlyHMSM(0,0,0,10,OS_OPT_TIME_DLY,&err); if(UploadFlag == 1)//确认需要上传数据了 { FreqModuleInit();//测频率模块初始化 GetFreq(1); printf("%s",aaa); printf("SCT200T15003-2015/7/8/Wednesday-15-36-9\r\n"); printf("SCT200T15003-ID=0x87031923 53578748 66eff48\r\n"); printf("SCT200T15003-Mode = 10 minutes Internal\r\n"); printf("SCT200T15003-Current voltage = 10.90V\r\n"); printf("SCT200T15003-Channel: 1 Temperature :34.47\r\n"); printf("SCT200T15003-Channel: 2 Temperature :34.43\r\n"); printf("SCT200T15003-Channel: 3 Temperature :30.40\r\n"); printf("SCT200T15003-Channel: 4 Temperature :25.90\r\n"); printf("SCT200T15003-Channel: 1 FREQUENCY:%f\r\n",GetFreq(1)); printf("SCT200T15003-Channel: 2 FREQUENCY:%f\r\n",GetFreq(2)); printf("SCT200T15003-Channel: 3 FREQUENCY:%f\r\n",GetFreq(3)); printf("SCT200T15003-Channel: 4 FREQUENCY:%f\r\n",GetFreq(4)); printf("%s",bbb); UploadFlag = 0; SW_12V(0);//电源 SW_5V(0);//正负电源,用于检测回波 OSTimeDlyHMSM(0,0,0,500,OS_OPT_TIME_DLY,&err); ConfigPINToListen(); PWR_EnterSTOPMode(PWR_Regulator_ON,PWR_STOPEntry_WFI); SetClock();//配置各级CPU时钟 BoardGPIOConfig();//IO口 SW_12V(1);//电源 SW_5V(1);//正负电源,用于检测回波 OSTimeDlyHMSM(0,0,0,500,OS_OPT_TIME_DLY,&err); UsartConfig();//串口设置配置 Nvic_Config(); } } }
void board_stopmode() { DBGMCU_Config(DBGMCU_STOP, ENABLE); // Enable PWR and BKP clock RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE); // Desable the SRAM and FLITF clock in Stop mode RCC_AHBPeriphClockCmd(RCC_AHBPeriph_SRAM | RCC_AHBPeriph_FLITF, DISABLE); PWR_EnterSTOPMode(PWR_Regulator_ON,PWR_STOPEntry_WFI); }
// MCU STOP mode void deepsleep(void) { // Enable PWR clock RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); // Enter Stop Mode PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI); // After wake-up from STOP reconfigure the PLL SetSysClock(); }
/******************************************************************************* * Function Name : Enter_LowPowerMode. * Description : Power-off system clocks and power while entering suspend mode. * Input : None. * Output : None. * Return : None. *******************************************************************************/ void Enter_LowPowerMode(void) { /* Set the device state to suspend */ bDeviceState = SUSPENDED; /* Clear EXTI Line18 pending bit */ EXTI_ClearITPendingBit(GPIO_KEY_EXTI_Line); /* Request to enter STOP mode with regulator in low power mode */ PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI); }
static mp_obj_t py_stop(void) { PWR_EnterSTANDBYMode(); //PWR_FlashPowerDownCmd(ENABLE); don't know what the logic is with this /* Enter Stop Mode */ PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI); /* Configures system clock after wake-up from STOP: enable HSE, PLL and select * PLL as system clock source (HSE and PLL are disabled in STOP mode) */ SYSCLKConfig_STOP(); //PWR_FlashPowerDownCmd(DISABLE); return mp_const_none; }
void node_stop(uint8_t *aInCfg) { // enter stop enter_node_stop(); #ifdef AUTOMATION // set up pin based on msg setup_pin(aInCfg); #else // ifndef AUTOMATION // unused pins GPIO_config_all_unused(); #endif // AUTOMATION PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI); // now wake up leave_node_stop(); }
/** * @brief Start Bit Method to Wake Up USART from Stop mode Test. * @param None * @retval None */ static void WakeUp_StartBitMethod(void) { /* Configure the wake up Method = Start bit */ USART_StopModeWakeUpSourceConfig(USART1, USART_WakeUpSource_StartBit); /* Enable USART1 */ USART_Cmd(USART1, ENABLE); /* Before entering the USART in STOP mode the REACK flag must be checked to ensure the USART RX is ready */ while(USART_GetFlagStatus(USART1, USART_FLAG_REACK) == RESET) {} /* Enable USART STOP mode by setting the UESM bit in the CR1 register.*/ USART_STOPModeCmd(USART1, ENABLE); /* Enable the wake up from stop Interrupt */ USART_ITConfig(USART1, USART_IT_WU, ENABLE); /* Enable PWR APB clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); /* Enter USART in STOP mode with regulator in low power mode */ PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI); /* Waiting Wake Up interrupt */ while(InterruptCounter == 0x00) {} /* Disable USART peripheral in STOP mode */ USART_STOPModeCmd(USART1, DISABLE); while(USART_GetFlagStatus(USART1, USART_FLAG_RXNE) == RESET) {} DataReceived = USART_ReceiveData(USART1); /* Clear the TE bit (if a transmission is on going or a data is in the TDR, it will be sent before efectivelly disabling the transmission) */ USART_DirectionModeCmd(USART1, USART_Mode_Tx, DISABLE); /* Check the Transfer Complete Flag */ while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET) {} /* USART Disable */ USART_Cmd(USART1, DISABLE); }
void board_sleep() { #if 0 uint16_t sleepTime = radiotimer_getPeriod() - radiotimer_getCapturedTime(); DBGMCU_Config(DBGMCU_STOP, ENABLE); // Enable PWR and BKP clock RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE); // Desable the SRAM and FLITF clock in Stop mode RCC_AHBPeriphClockCmd(RCC_AHBPeriph_SRAM | RCC_AHBPeriph_FLITF, DISABLE); PWR_EnterSTOPMode(PWR_Regulator_ON,PWR_STOPEntry_WFI); if(sleepTime > 0) opentimers_sleepTimeCompesation(sleepTime*2); #endif }
/** * @brief Main program * @param None * @retval None */ int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32f2xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f2xx.c file */ /* Configure the SysTick to generate an interrupt each 250 ms */ SysTick_Configuration(); /* Initialize LEDs and Key Button mounted on STM322xG-EVAL board */ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); STM_EVAL_LEDInit(LED4); /* Key button (EXTI_Line15) will be used to wakeup ths system from STOP mode */ STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_EXTI); /* RTC configuration */ RTC_Config(); while (1) { /* Insert 5 second delay */ Delay(20); /* Turn OFF LED2 */ STM_EVAL_LEDOff(LED2); /* Enable Wakeup Counter */ RTC_WakeUpCmd(ENABLE); /* Enter Stop Mode */ PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI); /* Disable Wakeup Counter */ RTC_WakeUpCmd(DISABLE); /* Configures system clock after wake-up from STOP: enable HSE, PLL and select PLL as system clock source (HSE and PLL are disabled in STOP mode) */ SYSCLKConfig_STOP(); } }
/** * @brief Prepare the system to enter STOP mode. * @param None * @retval None */ static void STOPEntry(void) { GPIO_InitTypeDef GPIO_InitStructure; /* Enable GPIOs clock */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOB | RCC_AHBPeriph_GPIOC | RCC_AHBPeriph_GPIOD | RCC_AHBPeriph_GPIOF, ENABLE); /* Configure all GPIO port pins in Analog mode */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_Init(GPIOC, &GPIO_InitStructure); GPIO_Init(GPIOD, &GPIO_InitStructure); GPIO_Init(GPIOF, &GPIO_InitStructure); /* Request to enter STOP mode with regulator in low power */ PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI); }
/** * @brief Enters MCU in STOP mode. The wake-up from STOP mode is performed by * an RTC Alarm. * @param None * @retval None */ void LowPower_EnterSTOPMode_RTCAlarm(void) { /* Clear the LCD */ /* Set the LCD Back Color */ // LCD_SetBackColor(LCD_COLOR_BLUE); /* Set the LCD Text Color */ /* External Interrupt Disable */ //Demo_IntExtOnOffCmd(DISABLE); if (RTC_ReadBackupRegister(RTC_BKP_DR0) != 0x5AA5) { /* External Interrupt Enable */ //Demo_IntExtOnOffCmd(ENABLE); return; } Calendar_AlarmPreAdjust_A(); /* Save the GPIO pins current configuration then put all GPIO pins in Analog Input mode */ LowPower_SaveGPIOConfig(); /* Request to enter STOP mode with regulator in low power */ PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI); /* Restore the GPIO Configurations*/ LowPower_RestoreGPIOConfig(); /* Configures system clock after wake-up from STOP: enable HSE, PLL and select PLL as system clock source (HSE and PLL are disabled in STOP mode) */ LowPower_SYSCLKConfig_STOP(); /* External Interrupt Enable */ //Demo_IntExtOnOffCmd(ENABLE); }
/////////////////////////////////////////////////////////////////////////////////////////////////////////// //用户任务1 void task1(void) { OS_ERR err; while(1) { OSTimeDlyHMSM(0,0,5,0,OS_OPT_TIME_DLY,&err); if(UploadFlag == 0) { SW_12V(0);//电源 SW_5V(0);//正负电源,用于检测回波 OSTimeDlyHMSM(0,0,0,200,OS_OPT_TIME_DLY,&err); ConfigPINToListen(); PWR_EnterSTOPMode(PWR_Regulator_ON,PWR_STOPEntry_WFI); SetClock();//配置各级CPU时钟 BoardGPIOConfig();//IO口 SW_12V(1);//电源 SW_5V(1);//正负电源,用于检测回波 OSTimeDlyHMSM(0,0,0,200,OS_OPT_TIME_DLY,&err); UsartConfig();//串口设置配置 Nvic_Config(); } } }
void RtcEnterLowPowerStopMode( void ) { if( ( LowPowerDisableDuringTask == false ) && ( RtcTimerEventAllowsLowPower == true ) ) { // Disable IRQ while the MCU is being deinitialized to prevent race issues __disable_irq( ); BoardDeInitMcu( ); __enable_irq( ); /* Disable the Power Voltage Detector */ PWR_PVDCmd( DISABLE ); /* Set MCU in ULP (Ultra Low Power) */ PWR_UltraLowPowerCmd( ENABLE ); /*Disable fast wakeUp*/ PWR_FastWakeUpCmd( DISABLE ); /* Enter Stop Mode */ PWR_EnterSTOPMode( PWR_Regulator_LowPower, PWR_STOPEntry_WFI ); } }
//============================================================================== // Sleep 設定 (EUP) //============================================================================== void F_Sleep_Init(void) { F_AllLCDRam(0); F_Display(); F_1625CS_1(0); F_1625WR(0); F_1625DATA(0); F_BackLight(0); F_IncControlUp(0); F_IncControlDown(0); F_EUP_EEPROM_GPIO(); // EUP //M_ERP_SetHigh; M_ERP_SetLow; EXTI_Config(); F_ERP_KBSet(); /* Request to enter STOP mode with regulator in low power mode */ PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI); EXTI_DeInit(); IWDG_Config(0); }
/** * @brief Enters MCU in STOP mode. The wake-up from STOP mode is performed by * an external interrupt. * @param None * @retval None */ void LowPower_EnterSTOPMode_EXTI(void) { NVIC_InitTypeDef NVIC_InitStructure; EXTI_InitTypeDef EXTI_InitStructure; GPIO_InitTypeDef GPIO_InitStructure; /* Clear the STOPModeStatus variable */ LowPower_Reset_STOPModeStatus(); /* Clear the LCD */ /* Set the LCD Back Color */ /* Set the LCD Text Color */ /* External Interrupt Disable */ //Demo_IntExtOnOffCmd(DISABLE); /* Clear the RTC Alarm flag */ RTC_ClearFlag(RTC_FLAG_ALRAF); /* Save the GPIO pins current configuration then put all GPIO pins in Analog Input mode ...*/ LowPower_SaveGPIOConfig(); /* Enable the debug when the MCU enter in stop mode */ DBGMCU_Config(DBGMCU_STOP, ENABLE); /* Configure Button pin as input */ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_InitStructure.GPIO_Pin = KEY_BUTTON_PIN; GPIO_Init(KEY_BUTTON_GPIO_PORT, &GPIO_InitStructure); /* Connect Button EXTI Line to Button GPIO Pin */ SYSCFG_EXTILineConfig(KEY_BUTTON_EXTI_PORT_SOURCE, KEY_BUTTON_EXTI_PIN_SOURCE); /* Configure the EXTI Line 8 */ EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Line = EXTI_Line8; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); /* Enable the EXTI9_5 Interrupt */ //NVIC_InitStructure.NVIC_IRQChannel = EXTI4_15_IRQn; //NVIC_InitStructure.NVIC_IRQChannelPriority = 3; //NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //NVIC_Init(&NVIC_InitStructure); /* Request to enter STOP mode with regulator in low power */ PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI); /* Restore the GPIO Configurations*/ LowPower_RestoreGPIOConfig(); /* At this stage the system has resumed from STOP mode ************************/ EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Line = EXTI_Line8; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; EXTI_InitStructure.EXTI_LineCmd = DISABLE; EXTI_Init(&EXTI_InitStructure); /* Enable the EXTI9_5 Interrupt */ //NVIC_InitStructure.NVIC_IRQChannel = EXTI4_15_IRQn; //NVIC_InitStructure.NVIC_IRQChannelPriority = 3; //NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //NVIC_Init(&NVIC_InitStructure); /* Configures system clock after wake-up from STOP: enable HSE, PLL and select PLL as system clock source (HSE and PLL are disabled in STOP mode) */ LowPower_SYSCLKConfig_STOP(); if (STOPModeStatus != RESET) { } else { } /* External Interrupt Enable */ //Demo_IntExtOnOffCmd(ENABLE); }
/** * @brief Main program. * @param None * @retval None */ int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32f0xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f0xx.c file */ /* Configure Clocks */ RCC_Config(); /* Initialize LEDs, Key Button and LCD available on STM320518-EVAL board *****************************************************/ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); /* Initialize the LCD */ STM320518_LCD_Init(); /* Display message on LCD ***********************************************/ /* Clear the LCD */ LCD_Clear(White); /* Set the LCD Back Color */ LCD_SetBackColor(Blue); /* Set the LCD Text Color */ LCD_SetTextColor(Yellow); LCD_DisplayStringLine(Line0, MESSAGE1); LCD_DisplayStringLine(Line1, MESSAGE2); /* Set the LCD Back Color */ LCD_SetBackColor(White); /* Set the LCD Text Color */ LCD_SetTextColor(Blue); /* Configure the Push buttons in Polling mode */ STM_EVAL_PBInit(BUTTON_KEY, Mode_GPIO); /* if STM32 device is set as Master */ #ifdef I2C_MASTER /* Configure and enable the systick timer to generate an interrupt each 1 ms */ SysTick_Config((SystemCoreClock / 1000)); /* Deinitialize I2Cx Device */ CPAL_I2C_DeInit(&MASTERSTRUCTURE); /* Initialize CPAL I2C structure parameters values */ CPAL_I2C_StructInit(&MASTERSTRUCTURE); #ifdef CPAL_I2C_DMA_PROGMODEL MASTERSTRUCTURE.wCPAL_Options = CPAL_OPT_NO_MEM_ADDR | CPAL_OPT_DMATX_TCIT; MASTERSTRUCTURE.CPAL_ProgModel = CPAL_PROGMODEL_DMA; #elif defined (CPAL_I2C_IT_PROGMODEL) MASTERSTRUCTURE.wCPAL_Options = CPAL_OPT_NO_MEM_ADDR; MASTERSTRUCTURE.CPAL_ProgModel = CPAL_PROGMODEL_INTERRUPT; #else #error "Please select one of the programming model (in main.h)" #endif /* Set I2C Speed */ MASTERSTRUCTURE.pCPAL_I2C_Struct->I2C_Timing = MASTER_I2C_TIMING; /* Select Master Mode */ MASTERSTRUCTURE.CPAL_Mode = CPAL_MODE_MASTER; /* Initialize I2Cx Device*/ CPAL_I2C_Init(&MASTERSTRUCTURE); /* Infinite loop */ while(1) { /* Initialize Transfer parameters */ MASTERSTRUCTURE.pCPAL_TransferTx = &sTxStructure; sTxStructure.wNumData = BufferSize; sTxStructure.pbBuffer = (uint8_t*)BufferTX; sTxStructure.wAddr1 = OWNADDRESS; /* Update LCD Display */ LCD_SetBackColor(White); LCD_SetTextColor(Blue); LCD_DisplayStringLine(Line8, MEASSAGE_EMPTY); LCD_DisplayStringLine(Line5, MESSAGE4); LCD_DisplayStringLine(Line6, MESSAGE5); /* wait until Key button is pushed */ while(STM_EVAL_PBGetState(BUTTON_KEY)); /* Update LCD Display */ LCD_DisplayStringLine(Line5, MEASSAGE_EMPTY); LCD_DisplayStringLine(Line6, MEASSAGE_EMPTY); /* Write operation */ CPAL_I2C_Write(&MASTERSTRUCTURE); /* Wait until communication finishes */ while ((MASTERSTRUCTURE.CPAL_State != CPAL_STATE_READY) && (MASTERSTRUCTURE.CPAL_State != CPAL_STATE_ERROR)); if (TransferStatus == PASSED) { /* Update LCD Display */ LCD_SetBackColor(Red); LCD_SetTextColor(White); LCD_DisplayStringLine(Line8, MESSAGE6); } else { TransferStatus = PASSED; } Delay(1000); } #endif /* I2C_MASTER */ /* if STM32 device is set as Slave */ #ifdef I2C_SLAVE /* GPIOA Periph clock enable */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); /* Output System Clock on MCO pin (PA.08) */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOA, &GPIO_InitStructure); RCC_MCOConfig(RCC_MCOSource_SYSCLK); /* Deinitialize I2Cx Device */ CPAL_I2C_DeInit(&SLAVESTRUCTURE); /* Initialize CPAL I2C structure parameters values */ CPAL_I2C_StructInit(&SLAVESTRUCTURE); #ifdef CPAL_I2C_DMA_PROGMODEL SLAVESTRUCTURE.wCPAL_Options = CPAL_OPT_I2C_NACK_ADD | CPAL_OPT_I2C_WAKEUP_STOP | CPAL_OPT_DMARX_TCIT; SLAVESTRUCTURE.CPAL_ProgModel = CPAL_PROGMODEL_DMA; #elif defined (CPAL_I2C_IT_PROGMODEL) SLAVESTRUCTURE.wCPAL_Options = CPAL_OPT_I2C_NACK_ADD | CPAL_OPT_I2C_WAKEUP_STOP; SLAVESTRUCTURE.CPAL_ProgModel = CPAL_PROGMODEL_INTERRUPT; #else #error "Please select one of the programming model (in main.h)" #endif /* Configure Own address 1 */ SLAVESTRUCTURE.pCPAL_I2C_Struct->I2C_OwnAddress1 = OWNADDRESS; /* Set I2C Speed */ SLAVESTRUCTURE.pCPAL_I2C_Struct->I2C_Timing = SLAVE_I2C_TIMING; /* Select Slave Mode */ SLAVESTRUCTURE.CPAL_Mode = CPAL_MODE_SLAVE; /* Initialize I2Cx Device*/ CPAL_I2C_Init(&SLAVESTRUCTURE); /* Infinite loop */ while(1) { /* Reset BufferRX value */ Reset_bBuffer(BufferRX, (uint16_t)BufferSize); /* Initialize Transfer parameters */ SLAVESTRUCTURE.pCPAL_TransferRx = &sRxStructure; sRxStructure.wNumData = BufferSize; sRxStructure.pbBuffer = (uint8_t*)BufferRX; /* Update LCD Display */ LCD_SetBackColor(White); LCD_SetTextColor(Blue); LCD_DisplayStringLine(Line8, MEASSAGE_EMPTY); LCD_DisplayStringLine(Line9, MEASSAGE_EMPTY); LCD_DisplayStringLine(Line5, MESSAGE7); Delay(1000); /* Update LCD Display */ LCD_DisplayStringLine(Line5, MEASSAGE_EMPTY); LCD_DisplayStringLine(Line6, MESSAGE8); /* Read operation */ CPAL_I2C_Read(&SLAVESTRUCTURE); /* Enter Stop Mode and wait for interrupt to wake up */ PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI); /* Wait until communication finishes */ while ((SLAVESTRUCTURE.CPAL_State != CPAL_STATE_READY) && (SLAVESTRUCTURE.CPAL_State != CPAL_STATE_ERROR)); /* Configure SystemClock*/ RestoreConfiguration(); /* Configure and enable the systick timer to generate an interrupt each 1 ms */ SysTick_Config((SystemCoreClock / 1000)); /* Update LCD Display */ LCD_DisplayStringLine(Line6, MEASSAGE_EMPTY); LCD_SetBackColor(Red); LCD_SetTextColor(White); LCD_DisplayStringLine(Line8, MESSAGE9); /* If are received correctly */ if (Compare_bBuffer((uint8_t*)BufferTX, BufferRX, BufferSize) == PASSED ) { /* Update LCD Display */ LCD_DisplayStringLine(Line9, MESSAGE6); } else { /* Update LCD Display */ LCD_DisplayStringLine(Line9, MESSAGE10); } Delay(1500); } #endif /* I2C_SLAVE */ }
/** * @brief This function configures the system to enter Stop mode with RTC * clocked by LSE or LSI for current consumption measurement purpose. * STOP Mode with RTC clocked by LSE/LSI * ===================================== * - RTC Clocked by LSE or LSI * - Regulator in LP mode * - HSI, HSE OFF and LSI OFF if not used as RTC Clock source * - No IWDG * - FLASH in deep power down mode * - Automatic Wakeup using RTC clocked by LSE/LSI (~20s) * @param None * @retval None */ void StopMode_Measure(void) { __IO uint32_t index = 0; GPIO_InitTypeDef GPIO_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; EXTI_InitTypeDef EXTI_InitStructure; /* Allow access to RTC */ PWR_BackupAccessCmd(ENABLE); #if defined (RTC_CLOCK_SOURCE_LSI) /* LSI used as RTC source clock*/ /* The RTC Clock may varies due to LSI frequency dispersion. */ /* Enable the LSI OSC */ RCC_LSICmd(ENABLE); /* Wait till LSI is ready */ while(RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET) { } /* Select the RTC Clock Source */ RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI); #elif defined (RTC_CLOCK_SOURCE_LSE) /* LSE used as RTC source clock */ /* Enable the LSE OSC */ RCC_LSEConfig(RCC_LSE_ON); /* Wait till LSE is ready */ while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET) { } /* Select the RTC Clock Source */ RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE); #else #error Please select the RTC Clock source inside the main.c file #endif /* RTC_CLOCK_SOURCE_LSI */ /* Enable the RTC Clock */ RCC_RTCCLKCmd(ENABLE); /* Wait for RTC APB registers synchronisation */ RTC_WaitForSynchro(); /* Configure all GPIO as analog to reduce current consumption on non used IOs */ /* Enable GPIOs clock */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_GPIOE | RCC_AHB1Periph_GPIOF | RCC_AHB1Periph_GPIOG | RCC_AHB1Periph_GPIOH | RCC_AHB1Periph_GPIOI, ENABLE); GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; 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(GPIOF, &GPIO_InitStructure); GPIO_Init(GPIOG, &GPIO_InitStructure); GPIO_Init(GPIOH, &GPIO_InitStructure); GPIO_Init(GPIOI, &GPIO_InitStructure); GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_Init(GPIOB, &GPIO_InitStructure); /* Disable GPIOs clock */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_GPIOE | RCC_AHB1Periph_GPIOF | RCC_AHB1Periph_GPIOG | RCC_AHB1Periph_GPIOH | RCC_AHB1Periph_GPIOI, DISABLE); /* EXTI configuration *******************************************************/ EXTI_ClearITPendingBit(EXTI_Line22); EXTI_InitStructure.EXTI_Line = EXTI_Line22; EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); /* Enable the RTC Wakeup Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = RTC_WKUP_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); /* RTC Wakeup Interrupt Generation: Clock Source: RTCCLK_Div16, Wakeup Time Base: ~20s RTC Clock Source LSE 32.768KHz or LSI ~32KHz Wakeup Time Base = (16 / (LSE or LSI)) * WakeUpCounter */ RTC_WakeUpClockConfig(RTC_WakeUpClock_RTCCLK_Div16); RTC_SetWakeUpCounter(0xA000-1); /* Enable the Wakeup Interrupt */ RTC_ITConfig(RTC_IT_WUT, ENABLE); /* Enable Wakeup Counter */ RTC_WakeUpCmd(ENABLE); /* FLASH Deep Power Down Mode enabled */ PWR_FlashPowerDownCmd(ENABLE); /* Enter Stop Mode */ PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI); /* Initialize LED1 on 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 Main program * @param None * @retval None */ int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup files (startup_stm32f410xx.s) before to branch to application main. */ /* LPTIM GPIO & NVIC & EXTI Configuration */ LPTIM_Config(); /* LED2 Green (PA5) GPIO Configuration */ LED_Config(); /* OutPut SysCLK divided by 5 on MCO2 (PC9) */ MCO2_Config(); /* ### - 1 - Re-target the LSI to Clock the LPTIM Clock Source #############*/ /* Select the LSI clock as LPTIM peripheral clock */ RCC_LSICmd(ENABLE); /* Wait until LSI is ready */ while(RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET) {} /* Disable PLL */ RCC_PLLCmd(DISABLE); /* Select LSI as LPTIM Clock Source */ RCC_LPTIM1ClockSourceConfig(RCC_LPTIM1CLKSOURCE_LSI); /* Check if LSI is selected for LPTIM clock source */ if((RCC->DCKCFGR2 & RCC_LPTIM1CLKSOURCE_LSI) != RCC_LPTIM1CLKSOURCE_LSI) { while(1); } /* ### - 2 - Initialize the LPTIM peripheral ############################## */ /* * Instance = LPTIM1 * Clock Source = APB or LowPowerOSCillator (in this example LSI is * already selected from the RCC stage) * Counter source = External Clock (connect Input at PB5) 1kHz * Clock prescaler = 1 (No division) * Counter Trigger = Software trigger * Output Polarity = High * Update mode = Immediate (Registers are immediately updated after any * write access) */ /* Deinitialze LPTIM peripheral */ LPTIM_DeInit(LPTIM1); /* Initialize the LPTIM peripheral */ LPTIM_InitStructure.LPTIM_ClockSource = LPTIM_ClockSource_APBClock_LPosc; LPTIM_InitStructure.LPTIM_OutputPolarity = LPTIM_OutputPolarity_High; LPTIM_InitStructure.LPTIM_Prescaler = LPTIM_Prescaler_DIV1; LPTIM_InitStructure.LPTIM_Waveform = LPTIM_Waveform_PWM_OnePulse; LPTIM_Init(LPTIM1, &LPTIM_InitStructure); LPTIM_ConfigUpdate(LPTIM1, LPTIM_Update_Immediate); /* Select External Clock as LPTIM clock source counter */ LPTIM_SelectClockSource(LPTIM1,LPTIM_ClockSource_ULPTIM); /* ### - 3 - Counter Mode in Interrupt mode configuration ##################*/ /* Select software start Trigger */ LPTIM_SelectSoftwareStart(LPTIM1); /* Enable Counter Mode */ LPTIM_SelectCounterMode(LPTIM1, ENABLE); /* Enables AutoReload Interrupts */ LPTIM_ITConfig(LPTIM1, LPTIM_IT_ARROK, ENABLE); LPTIM_ITConfig(LPTIM1, LPTIM_IT_ARRM, ENABLE); /* Enable LPTIMER */ LPTIM_Cmd(LPTIM1, ENABLE); /* Set Autoreload Value */ LPTIM_SetAutoreloadValue(LPTIM1, 1000); /* Period 1s for 1kHz Input */ /* Starts the LPTIMER in continuous mode */ LPTIM_SelectOperatingMode(LPTIM1, LPTIM_Mode_Continuous); /* Enter Stop Mode */ PWR_EnterSTOPMode(PWR_LowPowerRegulator_ON, PWR_STOPEntry_WFI); /* Infinite Loop */ while (1) { } }
void board_sleep() { #ifdef DEBUG_RUN_MODE // nothing need to do #endif #ifdef DEBUG_SLEEP_MODE DBGMCU_Config(DBGMCU_SLEEP, ENABLE); // Enable PWR and BKP clock RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE); // Desable the SRAM and FLITF clock in sleep mode RCC_AHBPeriphClockCmd(RCC_AHBPeriph_SRAM | RCC_AHBPeriph_FLITF, DISABLE); // enter sleep mode __WFI(); #endif #ifdef DEBUG_STOP_MODE uint16_t sleepTime = radiotimer_getPeriod() - radiotimer_getCapturedTime(); DBGMCU_Config(DBGMCU_STOP, ENABLE); // Enable PWR and BKP clock RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE); // Desable the SRAM and FLITF clock in Stop mode RCC_AHBPeriphClockCmd(RCC_AHBPeriph_SRAM | RCC_AHBPeriph_FLITF, DISABLE); // enter stop mode PWR_EnterSTOPMode(PWR_Regulator_ON,PWR_STOPEntry_WFI); if(sleepTime > 0) opentimers_sleepTimeCompesation(sleepTime); #endif }