cancel
Showing results for 
Search instead for 
Did you mean: 

How can I exit from standby mode using wakeup pin ?

DUrbano
Associate III
Posted on October 08, 2014 at 17:48

Hi,

I'm using an stm32f401 mcu, mounted above Discovery platform, trying to understand how can I correctly use the standby low power mode; for this reason, I use the PA0 wake up to exit from this low power mode, but it doesn't work. The PA0, for my project, is setted as external interrupt, but when I use the standby mode, I configure it using the HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1) function that sets the EWUP bit in power control/status register, but when the mcu enter in standby mode and I push the button linked with PA0 pin, the mcu instead of restart code after the enter standby mode instruction, it resets. This is my code (only the code to enter/exit of standby mode):

if
(f_EnterStdbyMode)
{
blink(3);
/* Set PDDS in power control register */
PWR->CR |= (uint32_t) 0x00000002;
/* Clear flaf wake up */
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU); 
while
((PWR->CSR & (uint32_t) 0x00000001)!=0);
//attesa che il WUF si azzeri (via HW) 
/* Enable PA0 wake-up functionalities */
HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1);
HAL_PWR_EnterSTANDBYMode();
//<- qui il codice si ferma 
HAL_GPIO_TogglePin(debugPin.port, debugPin.pin);
//<- qui il codice riprende la sua esecuzione
HAL_GPIO_TogglePin(debugPin.port, debugPin.pin);
/* Disable PA0 wake-up functionalities */
HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN1); 
f_EnterStdbyMode = 
false
;
blink(3);
}

Please, can anyone tell me what's going on ? Regards
8 REPLIES 8
Posted on October 08, 2014 at 19:13

STANDBY exits via a RESET, you catch it in main() or wherever when you check the reset cause.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
DUrbano
Associate III
Posted on October 09, 2014 at 09:41

Sorry but I'm a little bit confused; I read on reference manual:

''The microcontroller exits Standby mode when an external Reset (NRST pin), an IWDG

Reset, a rising edge on WKUP pin, an RTC alarm, a tamper event, or a time stamp event is detected''

and in fact I use a wake up pin to exit from standby mode, but I don't know if it's possible to see it as a reset. Please could you explain me ?

chen
Associate II
Posted on October 09, 2014 at 10:00

Hi

'Standby mode' basically powers down the processor (that is how it achieves the lowest power). So to wake up, you pretty much have to re-boot the whole thing.

Yes, you can wake from standby with ''an IWDG Reset, a rising edge on WKUP pin, an RTC alarm, a tamper event, or a time stamp''

BUT you still have to go through the process of booting the processor again.

So clive1 is correct - you have to catch the wake in your main loop or wherever when you check the reset cause.

DUrbano
Associate III
Posted on October 09, 2014 at 10:11

Could you give me an example of catching the reset cause ?

chen
Associate II
Posted on October 09, 2014 at 10:33

Hi

(Bear in mind this code is taken from my project for a STM32F405)

    // determine reason for reset (for reboots)

    uint32_t lastRstState = RCC->CSR;

    // code to detect a warm reboot (software reset)

    if ( RCC_CSR_SFTRSTF & lastRstState )

    // watchdog reset

    else if( ( RCC_CSR_WDGRSTF | RCC_CSR_WWDGRSTF ) & lastRstState )

Please refer to the reference manual for the meaning of all of the bits in the RCC->CSR register

DUrbano
Associate III
Posted on October 09, 2014 at 11:10

Thanks a lot, I'll try immediatly this solution...only one question: why check the LPWRRSTF: Low-power reset flag of RCC control/status register, instead of SBF flag of power control/status register ? The last one remain unchanged after the exit of stand by mode

DUrbano
Associate III
Posted on October 09, 2014 at 11:48

I tried both the flags but when the mcu resets, nothing happens, as I expected in my code:

int
main(
void
)
{
/* USER CODE BEGIN 1 */
uint32_t time; 
char
str[15];
/* USER CODE END 1 */
/* MCU Configuration----------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* Configure the system clock */
SystemClock_Config();
/* System interrupt init*/
/* Sets the priority grouping field */
HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_0);
HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_USART2_UART_Init();
/* Check che l'avvio del sistema non sia stato causato da una precedente uscita
dalla modalità low-power standby */
if
(__HAL_PWR_GET_FLAG(PWR_FLAG_SB))
{
blink(3);
/* Clear flag */
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_SB); 
}
if
(__HAL_RCC_GET_FLAG(RCC_FLAG_LPWRRST)) 
{
blink(3);
HAL_Delay(800);
blink(3);
/* Clear flag */
__HAL_RCC_CLEAR_RESET_FLAGS();
}

chen
Associate II
Posted on October 09, 2014 at 12:14

''why check the LPWRRSTF: Low-power reset flag of RCC control/status register, instead of SBF flag of power control/status register ?''

No reason not to. It is up to you to work out the best way to determine if the processor has :

Booted up from power on

Re-booted due to reset (hardfault or software foreced)

Wake from Standby.

from the reset status bit and any other status registers