cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L053C8, problem with standby mode and wakeup pin

SKoh.14
Associate

I am using an STM32L0C8T6 MCU and STM32CubeMX to generate the hal driver for my first project. One of the features of the project, is to configure it to go into standby mode to conserve lowest power consumption if my program is idling for some amount of time, then use WKUP pin(PA0) which is wired to a button to trigger a rising edge to wake the MCU. The problem here is I couldn't get it neither the standby mode and wakeup pin to work.

I observed that the standby function work only by pressing and holding the push button down, the current measurement dropped from about 3.5mA to 0.5mA. But that wasn't the correct execution I wanted, the push button use is to wake the device. After the device went into standby mode, I pushed the button again, the wakeup pin still do not work.

I also noticed if I measured the voltage at PA0 after the program run pass the HAL_PWR_EnableWakeUpPin() and push button is pressed, the voltage went from 0 to 0.8 even thought the circuit suppose to pull PA0 to 3.3v.

int main(void)
{
 
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
 
/* Configure the system clock */
SystemClock_Config();
 
HAL_Delay(10000);
 
 
HAL_PWREx_EnableUltraLowPower();
/* Enable the fast wake up from Ultra low power mode */
HAL_PWREx_EnableFastWakeUp();
 
if(__HAL_PWR_GET_FLAG(PWR_FLAG_SB) != RESET)
{
/* Clear Standby flag */
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_SB);
}
 
/* Insert 5 seconds delay */
HAL_Delay(5000);
 
/*Disable all used wakeup sources: Pin1(PA.0)*/
HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN1);
 
/*Clear all related wakeup flags*/
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
 
/*Re-enable all used wakeup sources: Pin1(PA.0)*/
HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1);
 
 
HAL_PWR_EnterSTANDBYMode();
 
while(1)
{}
 
}
 
HAL_StatusTypeDef HAL_Init(void)
{
/* Configure Buffer cache, Flash prefetch, Flash preread */ 
#if (BUFFER_CACHE_DISABLE != 0)
__HAL_FLASH_BUFFER_CACHE_DISABLE();
#endif /* BUFFER_CACHE_DISABLE */
 
#if (PREREAD_ENABLE != 0)
__HAL_FLASH_PREREAD_BUFFER_ENABLE();
#endif /* PREREAD_ENABLE */
 
#if (PREFETCH_ENABLE != 0)
__HAL_FLASH_PREFETCH_BUFFER_ENABLE();
#endif /* PREFETCH_ENABLE */
 
/* Use systick as time base source and configure 1ms tick (default clock after Reset is MSI) */
 
HAL_InitTick(TICK_INT_PRIORITY);
 
/* Init the low level hardware */
HAL_MspInit();
 
/* Return function status */
return HAL_OK;
}
 
void SystemClock_Config(void)
{
 
RCC_ClkInitTypeDef RCC_ClkInitStruct;
//RCC_PeriphCLKInitTypeDef PeriphClkInit;
RCC_OscInitTypeDef RCC_OscInitStruct;
 
__PWR_CLK_ENABLE();
 
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2);
 
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_LSI
|RCC_OSCILLATORTYPE_HSI48;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSICalibrationValue = 16;
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
RCC_OscInitStruct.HSI48State = RCC_HSI48_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
HAL_RCC_OscConfig(&RCC_OscInitStruct);
 
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK|RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV16;
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1);
}
 
void HAL_PWREx_EnableUltraLowPower(void)
{
/* Enable the Ultra Low Power mode */
PWR->CR |= PWR_CR_ULP;
}
 
void HAL_PWREx_EnableFastWakeUp(void)
{
/* Enable the fast wake up */
PWR->CR |= PWR_CR_FWU;
}
 
void HAL_PWR_DisableWakeUpPin(uint32_t WakeUpPinx)
{
/* Check the parameter */
assert_param(IS_PWR_WAKEUP_PIN(WakeUpPinx));
/* Disable the EWUPx pin */
PWR->CSR &= ~WakeUpPinx;
}
 
void HAL_PWR_EnableWakeUpPin(uint32_t WakeUpPinx)
{
/* Check the parameter */
assert_param(IS_PWR_WAKEUP_PIN(WakeUpPinx));
/* Enable the EWUPx pin */
PWR->CSR |= WakeUpPinx;
}
 
void HAL_PWR_EnterSTANDBYMode(void)
{
/* Select Standby mode */
PWR->CR |= PWR_CR_PDDS;
 
/* Set SLEEPDEEP bit of Cortex System Control Register */
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
 
/* This option is used to ensure that store operations are completed */
#if defined ( __CC_ARM)
__force_stores();
#endif
/* Request Wait For Interrupt */
__WFI();
}

0 REPLIES 0