/** * @brief Main program * @param None * @retval None */ int main(void) { /* STM32L0xx HAL library initialization: - Configure the Flash prefetch, Flash preread and Buffer caches - Systick timer is configured by default as source of time base, but user can eventually implement his proper time base source (a general purpose timer for example or other time source), keeping in mind that Time base duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and handled in milliseconds basis. - Low Level Initialization */ HAL_Init(); /* Configure LED3 */ BSP_LED_Init(LED3); /* Disable Prefetch Buffer */ __HAL_FLASH_PREFETCH_BUFFER_DISABLE(); /* Configure the system clock @ 32 KHz */ SystemClock_Config(); /* Configure the system Power */ SystemPower_Config(); while (1) { /* Configure Key Button*/ BSP_PB_Init(BUTTON_KEY,BUTTON_MODE_GPIO); /* Wait Until Key button pressed */ while(BSP_PB_GetState(BUTTON_KEY) == RESET) { } /* Wait Until Key button pressed */ while(BSP_PB_GetState(BUTTON_KEY) != RESET) { } /* Key button (EXTI_Line13) will be used to wakeup the system from SLEEP mode */ BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_EXTI); /* Enable the power down mode during Sleep mode */ __HAL_FLASH_SLEEP_POWERDOWN_ENABLE(); /*Suspend Tick increment to prevent wakeup by Systick interrupt. Otherwise the Systick interrupt will wake up the device within 1ms (HAL time base)*/ HAL_SuspendTick(); /* Enter Sleep Mode , wake up is done once Key push button is pressed */ HAL_PWR_EnterSLEEPMode(PWR_LOWPOWERREGULATOR_ON, PWR_SLEEPENTRY_WFI); /* Resume Tick interrupt if disabled prior to sleep mode entry*/ HAL_ResumeTick(); } }
/** * @brief This routine puts the MCU in sleep mode * @param None * @retval None */ void MCU_Enter_SleepMode(void) { /*Suspend Tick increment to prevent wakeup by Systick interrupt. Otherwise the Systick interrupt will wake up the device within 1ms (HAL time base)*/ HAL_SuspendTick(); HAL_PWR_EnterSLEEPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI); /* Infinite loop */ }
void goSleep(void) { setSensorDevPwr(DEV_PWR_OFF); setSysWakeUpLed(LED_OFF); setSysStsLed(LED_OFF); setTestPassLed(LED_OFF); setTestFailLed(LED_OFF); int adcVolBat = 0; do { HAL_SuspendTick(); HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFE); HAL_ResumeTick(); adcVolBat = readAdcChannel(ADC_CHANNEL_7); if (adcVolBat < (0x0400)) { setSysStsLed(LED_ON); HAL_Delay(10); setSysStsLed(LED_OFF); HAL_Delay(200); setSysStsLed(LED_ON); HAL_Delay(10); setSysStsLed(LED_OFF); } } while (adcVolBat < (0x0400)); }
void SleepMode(void) { GPIO_InitTypeDef GPIO_InitStruct; /* Disable all GPIOs to reduce power */ MX_GPIO_Deinit(); /* Configure User push-button as external interrupt generator */ __HAL_RCC_GPIOC_CLK_ENABLE(); GPIO_InitStruct.Pin = B1_Pin; GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(B1_GPIO_Port, &GPIO_InitStruct); HAL_UART_DeInit(&huart2); /* Suspend Tick increment to prevent wakeup by Systick interrupt. Otherwise the Systick interrupt will wake up the device within 1ms (HAL time base) */ HAL_SuspendTick(); __HAL_RCC_PWR_CLK_ENABLE(); /* Request to enter SLEEP mode */ HAL_PWR_EnterSLEEPMode(0, PWR_SLEEPENTRY_WFI); /* Resume Tick interrupt if disabled prior to sleep mode entry*/ HAL_ResumeTick(); /* Reinitialize GPIOs */ MX_GPIO_Init(); /* Reinitialize UART2 */ MX_USART2_UART_Init(); }
void sleep(void) { // Stop HAL systick HAL_SuspendTick(); // Request to enter SLEEP mode HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI); // Restart HAL systick HAL_ResumeTick(); }
/** * @brief Low power sleep mode * NOTE: This is Low power sleep mode with wakeup button(PA0) */ void BSP_Sleepmode_PB(void) { /* suspand systick */ HAL_SuspendTick(); HAL_PWR_EnterSLEEPMode(PWR_LOWPOWERREGULATOR_ON,PWR_SLEEPENTRY_WFI); /* Resume systick */ HAL_ResumeTick(); }
/** * @brief This function configures the system to enter Sleep mode for * current consumption measurement purpose. * Sleep Mode * ========== * - System Running at PLL (168MHz) * - Flash 5 wait state * - Instruction and Data caches ON * - Prefetch ON * - Code running from Internal FLASH * - All peripherals disabled. * - Wakeup using EXTI Line (Key Button) * @param None * @retval None */ void SleepMode_Measure(void) { GPIO_InitTypeDef GPIO_InitStruct; /* Configure all GPIO as analog to reduce current consumption on non used IOs */ /* Enable GPIOs clock */ __HAL_RCC_GPIOA_CLK_ENABLE(); __HAL_RCC_GPIOB_CLK_ENABLE(); __HAL_RCC_GPIOC_CLK_ENABLE(); __HAL_RCC_GPIOD_CLK_ENABLE(); __HAL_RCC_GPIOE_CLK_ENABLE(); __HAL_RCC_GPIOH_CLK_ENABLE(); GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Pin = GPIO_PIN_All; HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); HAL_GPIO_Init(GPIOE, &GPIO_InitStruct); HAL_GPIO_Init(GPIOH, &GPIO_InitStruct); HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); /* Disable GPIOs clock */ __HAL_RCC_GPIOA_CLK_DISABLE(); __HAL_RCC_GPIOB_CLK_DISABLE(); __HAL_RCC_GPIOC_CLK_DISABLE(); __HAL_RCC_GPIOD_CLK_DISABLE(); __HAL_RCC_GPIOE_CLK_DISABLE(); __HAL_RCC_GPIOH_CLK_DISABLE(); /* Configure Key Button */ BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_EXTI); /* Suspend Tick increment to prevent wakeup by Systick interrupt. Otherwise the Systick interrupt will wake up the device within 1ms (HAL time base) */ HAL_SuspendTick(); /* Request to enter SLEEP mode */ HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI); /* Resume Tick interrupt if disabled prior to sleep mode entry */ HAL_ResumeTick(); /* Initialize LED6 */ BSP_LED_Init(LED6); /* Turn LED6 On */ BSP_LED_On(LED6); /* Inserted Delay */ HAL_Delay(200); }
void mbed_enter_sleep(sleep_t *obj) { // This currently goes to Sleep Mode, because lp ticker implementation is not // available in the STOP mode obj->TimMasterHandle.Instance = TIM_MST; // Disable HAL tick interrupt __HAL_TIM_DISABLE_IT(&obj->TimMasterHandle, TIM_IT_CC2); // Request to enter SLEEP mode HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI); //controllare diversi sleep mode (SLEEP, STOP, SHUTDOWN) }
void sleep(void) { // Disable HAL tick interrupt TimMasterHandle.Instance = TIM5; __HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC2); // Request to enter SLEEP mode HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI); // Enable HAL tick interrupt __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); }
/** * @brief This function configures the system to enter Sleep mode for * current consumption measurement purpose. * Sleep Mode * ========== * - System Running at PLL (72 MHz) * - Flash 2 wait state * - Prefetch ON * - Code running from Internal FLASH * - All peripherals disabled. * - Wakeup using EXTI Line (User push-button PA.00 pin) * @param None * @retval None */ void SleepMode_Measure(void) { GPIO_InitTypeDef GPIO_InitStruct; /* Configure all GPIO as analog to reduce current consumption on non used IOs */ /* Enable GPIOs clock */ /* Warning : Reconfiguring all GPIO will close the connexion with the debugger */ __GPIOA_CLK_ENABLE(); __GPIOB_CLK_ENABLE(); __GPIOC_CLK_ENABLE(); __GPIOD_CLK_ENABLE(); __GPIOE_CLK_ENABLE(); __GPIOF_CLK_ENABLE(); GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Pin = GPIO_PIN_All; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); HAL_GPIO_Init(GPIOE, &GPIO_InitStruct); HAL_GPIO_Init(GPIOF, &GPIO_InitStruct); /* Disable GPIOs clock */ __GPIOA_CLK_DISABLE(); __GPIOB_CLK_DISABLE(); __GPIOC_CLK_DISABLE(); __GPIOD_CLK_DISABLE(); __GPIOE_CLK_DISABLE(); __GPIOF_CLK_DISABLE(); /* Configure User push-button as external interrupt generator */ BSP_PB_Init(BUTTON_USER, BUTTON_MODE_EXTI); /*Suspend Tick increment to prevent wakeup by Systick interrupt. Otherwise the Systick interrupt will wake up the device within 1ms (HAL time base)*/ HAL_SuspendTick(); /* Request to enter SLEEP mode */ HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI); /* Resume Tick interrupt if disabled prior to sleep mode entry*/ HAL_ResumeTick(); /* Initialize led */ BSP_LED_Init(LED3); }
/** * @brief Low power sleep mode * NOTE: This is Low power sleep mode, system can be wake up using any interrupt */ void BSP_SleepMode(void) { /* suspand systick */ HAL_SuspendTick(); /* * Enters Sleep mode * PWR_LOWPOWERREGULATOR_ON: SLEEP mode with low power regulator ON * PWR_SLEEPENTRY_WFI: enter SLEEP mode with WFI instruction */ HAL_PWR_EnterSLEEPMode(PWR_LOWPOWERREGULATOR_ON,PWR_SLEEPENTRY_WFI); /* Resume systick */ HAL_ResumeTick(); }
void SleepMode(void) { //SystemClock_Config_LOW(); /* Configure all GPIO as analog to reduce current consumption on non used IOs */ /* Enable GPIOs clock */ /* Warning : Reconfiguring all GPIO will close the connexion with the debugger */ /* __HAL_RCC_GPIOA_CLK_ENABLE(); __HAL_RCC_GPIOB_CLK_ENABLE(); __HAL_RCC_GPIOC_CLK_ENABLE(); __HAL_RCC_GPIOD_CLK_ENABLE(); __HAL_RCC_GPIOF_CLK_ENABLE(); GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Pin = GPIO_PIN_All; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); HAL_GPIO_Init(GPIOF, &GPIO_InitStruct); // Disable GPIOs clock __HAL_RCC_GPIOA_CLK_DISABLE(); __HAL_RCC_GPIOB_CLK_DISABLE(); __HAL_RCC_GPIOC_CLK_DISABLE(); __HAL_RCC_GPIOD_CLK_DISABLE(); __HAL_RCC_GPIOF_CLK_DISABLE(); */ /*Suspend Tick increment to prevent wakeup by Systick interrupt. Otherwise the Systick interrupt will wake up the device within 1ms (HAL time base)*/ HAL_SuspendTick(); /* Request to enter SLEEP mode */ HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI); /* Resume Tick interrupt if disabled prior to sleep mode entry*/ HAL_ResumeTick(); // SystemClock_Config_8MHz(); /* Inserted Delay */ HAL_Delay(200); }
/** * @brief Main program * @param None * @retval None */ int main(void) { /* STM32F3xx HAL library initialization: - Configure the Flash prefetch - Configure the Systick to generate an interrupt each 1 msec - Set NVIC Group Priority to 4 - Low Level Initialization */ HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /* Configure LED1 */ BSP_LED_Init(LED1); /* Disable Prefetch Buffer */ __HAL_FLASH_PREFETCH_BUFFER_DISABLE(); while (1) { /* Insert 5 seconds delay */ HAL_Delay(5000); /* Configure the system Power */ SystemPower_Config(); /* User push-button (line 15_10) will be used to wakeup the system from SLEEP mode */ BSP_PB_Init(BUTTON_USER, BUTTON_MODE_EXTI); /*Suspend Tick increment to prevent wakeup by Systick interrupt. Otherwise the Systick interrupt will wake up the device within 1ms (HAL time base)*/ HAL_SuspendTick(); /* Enter Sleep Mode , wake up is done once User push-button is pressed */ HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI); /* Resume Tick interrupt if disabled prior to SLEEP mode entry */ HAL_ResumeTick(); /* Re-configure LED1 */ BSP_LED_Init(LED1); } }
/** * @brief Pre Sleep Processing * @param ulExpectedIdleTime: Expected time in idle state * @retval None */ void PreSleepProcessing(uint32_t * ulExpectedIdleTime) { /* Called by the kernel before it places the MCU into a sleep mode because configPRE_SLEEP_PROCESSING() is #defined to PreSleepProcessing(). NOTE: Additional actions can be taken here to get the power consumption even lower. For example, peripherals can be turned off here, and then back on again in the post sleep processing function. For maximum power saving ensure all unused pins are in their lowest power state. */ /* (*ulExpectedIdleTime) is set to 0 to indicate that PreSleepProcessing contains its own wait for interrupt or wait for event instruction and so the kernel vPortSuppressTicksAndSleep function does not need to execute the wfi instruction */ *ulExpectedIdleTime = 0; /*Enter to sleep Mode using the HAL function HAL_PWR_EnterSLEEPMode with WFI instruction*/ HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI); }
/** * @brief Main program * @param None * @retval None */ int main(void) { /* STM32L0xx HAL library initialization: - Configure the Flash prefetch, Flash preread and Buffer caches - Systick timer is configured by default as source of time base, but user can eventually implement his proper time base source (a general purpose timer for example or other time source), keeping in mind that Time base duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and handled in milliseconds basis. - Low Level Initialization */ HAL_Init(); /* Configure LED3 */ BSP_LED_Init(LED3); /* Configure the system clock to 2 Mhz */ SystemClock_Config(); /* Configure and enable the DMA Stream for Memory to Memory transfer */ DMA_Config(); /* Suspend Tick increment to prevent wakeup by Systick interrupt. */ /* Otherwise the Systick interrupt will wake up the device within 1ms */ /* (HAL time base). */ HAL_SuspendTick(); /* Enter sleep mode and wait for DMA interrupt */ HAL_PWR_EnterSLEEPMode(PWR_LOWPOWERREGULATOR_ON, PWR_SLEEPENTRY_WFI); /* Resume Tick interrupt if disabled prior to SLEEP mode entry */ HAL_ResumeTick(); /* Infinite loop */ while (1) { } }
/** * @brief Main program. * @param None * @retval None */ int main(void) { /* STM32F3xx HAL library initialization: - Configure the Flash prefetch - Systick timer is configured by default as source of time base, but user can eventually implement his proper time base source (a general purpose timer for example or other time source), keeping in mind that Time base duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and handled in milliseconds basis. - Set NVIC Group Priority to 4 - Low Level Initialization */ HAL_Init(); /* Configure the system clock to 72 MHz */ SystemClock_Config(); /* Configure LEDs */ BSP_LED_Init(LED1); BSP_LED_Init(LED2); BSP_LED_Init(LED4); /*##-1- Configure the TSC peripheral #######################################*/ TscHandle.Instance = TSCx; TscHandle.Init.AcquisitionMode = TSC_ACQ_MODE_NORMAL; TscHandle.Init.CTPulseHighLength = TSC_CTPH_1CYCLE; TscHandle.Init.CTPulseLowLength = TSC_CTPL_1CYCLE; TscHandle.Init.IODefaultMode = TSC_IODEF_OUT_PP_LOW; TscHandle.Init.MaxCountInterrupt = ENABLE; TscHandle.Init.MaxCountValue = TSC_MCV_16383; TscHandle.Init.PulseGeneratorPrescaler = TSC_PG_PRESC_DIV64; TscHandle.Init.SpreadSpectrum = DISABLE; TscHandle.Init.SpreadSpectrumDeviation = 127; TscHandle.Init.SpreadSpectrumPrescaler = TSC_SS_PRESC_DIV1; TscHandle.Init.SynchroPinPolarity = TSC_SYNC_POL_FALL; TscHandle.Init.ChannelIOs = 0; /* Not needed yet. Will be set with HAL_TSC_IOConfig() */ TscHandle.Init.SamplingIOs = 0; /* Not needed yet. Will be set with HAL_TSC_IOConfig() */ TscHandle.Init.ShieldIOs = 0; /* Not needed yet. Will be set with HAL_TSC_IOConfig() */ if (HAL_TSC_Init(&TscHandle) != HAL_OK) { /* Initialization Error */ Error_Handler(); } /*##-2- Configure the touch-sensing IOs ####################################*/ IoConfig.ChannelIOs = TSC_GROUP8_IO2; /* Start with the first channel */ IoConfig.SamplingIOs = (TSC_GROUP8_IO1 | TSC_GROUP8_IO1 | TSC_GROUP6_IO1); IoConfig.ShieldIOs = TSC_GROUP6_IO2; if (HAL_TSC_IOConfig(&TscHandle, &IoConfig) != HAL_OK) { /* Initialization Error */ Error_Handler(); } /*##-3- Discharge the touch-sensing IOs ####################################*/ HAL_TSC_IODischarge(&TscHandle, ENABLE); HAL_Delay(1); /* 1 ms is more than enough to discharge all capacitors */ /*##-4- Start the acquisition process ######################################*/ if (HAL_TSC_Start_IT(&TscHandle) != HAL_OK) { /* Acquisition Error */ Error_Handler(); } /* Infinite loop */ while (1) { /*Suspend Tick increment to prevent wakeup by Systick interrupt. Otherwise the Systick interrupt will wake up the device within 1ms (HAL time base)*/ HAL_SuspendTick(); /* The acquisition process is now performed in the HAL_TSC_ConvCpltCallback() function */ HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI); /* Resume Tick interrupt if disabled prior to sleep mode entry*/ HAL_ResumeTick(); } }