cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L4 not staying in STANDBY

Ricardo Hassan
Associate III
Posted on July 02, 2018 at 19:13

Hi,

    I am working with an STM32L4.  I'm trying to put it into STANDBY mode, and wake it up using a WKUP pin.  The issue is that the first time I go to standby after POR, the system wakes up immediately, though I'm sure none of the wakeup pins have had an edge transition.  If I go back to STANDBY after that, the system stays in STANDBY.  Can anyone explain this behavior?  For what it's worth, I am not using a watchdog, I'm turning off the GPIO clocks before going to STANDBY, and I am clearing the standby and WUF flags on every reset.  I am including my code for clearing the flags and going to STANDBY.

Thanks,

Ricardo

/* Code for clearing flags, run on every reset */

void SystemStartup(void) {

uint8_t reason = 0;

/* Check if the system was resumed from Standby mode */

if (__HAL_PWR_GET_FLAG(PWR_FLAG_SB) != RESET) {

/* Clear Standby flag */

__HAL_PWR_CLEAR_FLAG(PWR_FLAG_SB);

reason |= 0x80;

}

/* Check and Clear the Wakeup flag */

if (__HAL_PWR_GET_FLAG(PWR_FLAG_WUF1) != RESET) {

__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUF1);

reason |= 0x01;

}

if (__HAL_PWR_GET_FLAG(PWR_FLAG_WUF2) != RESET) {

__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUF2);

reason |= 0x02;

}

if (__HAL_PWR_GET_FLAG(PWR_FLAG_WUF3) != RESET) {

__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUF3);

reason |= 0x04;

}

if (__HAL_PWR_GET_FLAG(PWR_FLAG_WUF5) != RESET) {

__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUF5);

reason |= 0x80;

}

}

/* code for going to STANDBY mode */

void PowerManager::EnterSleepState(void) {

// Wakeup when Qi Charger stops charging - Note CHG♯ is active low

HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1_HIGH);

// Wakeup when device is latched

HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN2_HIGH);

// Wakeup when a BLE packet is received

HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN3_HIGH);

// Wakeup when the user taps the device (accelerometer interrupt)

HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN5_HIGH);

sysSerial.Print('Going down\r\n');

// Disable GPIO clocks

__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_GPIOF_CLK_DISABLE();

__HAL_RCC_GPIOG_CLK_DISABLE();

__HAL_RCC_GPIOH_CLK_DISABLE();

__HAL_RCC_GPIOI_CLK_DISABLE();

// Enter STANDBY mode -

HAL_PWR_EnterSTANDBYMode();

// The rest of this function should never be executed, as the MCU will reset upon wakeup

__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_GPIOF_CLK_ENABLE();

__HAL_RCC_GPIOG_CLK_ENABLE();

__HAL_RCC_GPIOH_CLK_ENABLE();

__HAL_RCC_GPIOI_CLK_ENABLE();

sysSerial.Print('Getting up\r\n');

// reconfigure the system clock

SystemClock_Config();

// reenable I/O

HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN1_HIGH);

HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN2_HIGH);

HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN3_HIGH);

HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN5_HIGH);

}

#standby-mode
1 REPLY 1
Tadao Tomiyama
Associate III

Hi,

This is a guesswork, internal wakeup?

Did you checked WUFI bit in PWR_SR1 register?

If it was set, ​try to clear EIWUL bit (in PWR_CR3).

To do it via HAL, call HAL_PWREx_DisableInternalWakeUpLine() .