AnsweredAssumed Answered

Wake up from the sleep mode

Question asked by Leo Leo on Dec 7, 2016
Latest reply on Dec 8, 2016 by Nesrine M

Hi everyone, 

 

I'm working on a project and i'm a beginner on STM32F0. I have the discovery board. I have the code at the bottom of the page but i don't understand many parts of it... 

 

In this code i have the following question : 

What's the difference between this instruction BUTTON_MODE_GPIO and this instruction BUTTON_MODE_EXTI. There is someting with the interruptions... I don't really understand. When the button mode is exti, when i press the user button, I generate an interruption ? And when the button mode is GPIO what happens ? It's a bit difficult for me ... 

Normally, it works like that :

"After reset, the program waits for User button connected to the PA.00 to be  pressed to enter the selected low power mode. " In the below code, it's the SLEEP MODE.
"- When the RTC is used, the wakeup from low power mode is automatically
generated by the RTC (after 5s). " useffull for the STOP MODE 
"- In Sleep mode and Standby mode, press again the User button to exit the low power mode."

 

I think the BUTTON MODE EXTI is used to wake up the device from the sleep mode. But i don't know how it works... I attached two extract extracted from the datasheet of the STM32. It describes what is the sleep mode and how do we enter in and how can we go out from it.

 

 

I don't understand also these instructions : 

/* Enable PWR APB1 Clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);

/* Allow access to Backup */
PWR_BackupAccessCmd(ENABLE);

/* Reset RTC Domain */
RCC_BackupResetCmd(ENABLE);
RCC_BackupResetCmd(DISABLE);

 

I don't know what is a backup Register. I look for in the datasheet but i didn't find them ... and i don't know what is the RCC domain ... If someone can explain me what is it ? And what is the function of these instructions in the above lines of code ? 

Thank you very much for your help. It's very difficult for me. I hope that I will be better in few weeks... 

 

Have a nice day,

 

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 User Button */
STM_EVAL_PBInit(BUTTON_USER,BUTTON_MODE_GPIO);

/* Loop while User button is maintained pressed */
while(STM_EVAL_PBGetState(BUTTON_USER) != RESET)
{
}

/* Enable PWR APB1 Clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);

/* Allow access to Backup */
PWR_BackupAccessCmd(ENABLE);

/* Reset RTC Domain */
RCC_BackupResetCmd(ENABLE);
RCC_BackupResetCmd(DISABLE);

/* Loop while User button is maintained pressed */
while(STM_EVAL_PBGetState(BUTTON_USER) == RESET)
{
}
/* Loop while User button is maintained pressed */
while(STM_EVAL_PBGetState(BUTTON_USER) != RESET)
{
}

#if defined (SLEEP_MODE)
/* Sleep Mode Entry
- System Running at PLL (48MHz)
- Flash 3 wait state
- Prefetch and Cache enabled
- Code running from Internal FLASH
- All peripherals disabled.
- Wakeup using EXTI Line (User Button PA.00)
*/

SleepMode_Measure();

}

-------------------------------------------------------------------------------------------------------------------------------------------------------------

void SleepMode_Measure(void)
{
__IO uint32_t index = 0;
GPIO_InitTypeDef GPIO_InitStructure;
/* 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_GPIOF , ENABLE);

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
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(GPIOF, &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_GPIOF, DISABLE);
/* Configure User Button */
STM_EVAL_PBInit(BUTTON_USER, BUTTON_MODE_EXTI);
/* Request to enter SLEEP mode */
__WFI();
/* Initialize LED4 on STM32F0-Discovery board */
STM_EVAL_LEDInit(LED4);
/* Infinite loop */
while (1)
{
/* Toggle The LED4 */
STM_EVAL_LEDToggle(LED4);
/* Inserted Delay */
for(index = 0; index < 0x7FFFF; index++);
}
}

Outcomes