cancel
Showing results for 
Search instead for 
Did you mean: 

Using CubeMX RTC HAL to wakeup from stop mode

messingmm
Associate
Posted on October 14, 2015 at 00:22

Hello,

I am trying to get my STM32l053 to wake up from stop mode using the RTC wake up timer (using CubeMX). I've done some testing and found that stop mode works, and I can wake it back up using a button (the user button on the eval board). I've also found that the alarm goes off when configured in the main using:

HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, 0, RTC_WAKEUPCLOCK_RTCCLK_DIV16);

So, I thought that if I get rid of that function in the main and use it right before entering stop mode, it should wake up immediately, but it doesn't. Here's what I did:

HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, 0, RTC_WAKEUPCLOCK_RTCCLK_DIV16);
/* Enter Stop Mode */
HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);

I played around with different values for the wake up counter, but nothing works. Zero also seems to be the only one that works when configured in main. I've consulted the reference manual, tried to talk to the registers directly, but that also didn't work. The function I'm using seem to follow what the manual says though. Finally, here is my clock initialization function, the problem might be there?

/** System Clock Configuration
*/
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct;
RCC_ClkInitTypeDef RCC_ClkInitStruct;
RCC_PeriphCLKInitTypeDef PeriphClkInit;
__PWR_CLK_ENABLE();
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_LSI;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSICalibrationValue = 16;
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLLMUL_3;
RCC_OscInitStruct.PLL.PLLDIV = RCC_PLLDIV_2;
HAL_RCC_OscConfig(&RCC_OscInitStruct);
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1);
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART2|RCC_PERIPHCLK_I2C1
|RCC_PERIPHCLK_RTC;
PeriphClkInit.Usart2ClockSelection = RCC_USART2CLKSOURCE_PCLK1;
PeriphClkInit.I2c1ClockSelection = RCC_I2C1CLKSOURCE_PCLK1;
PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSI;
HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit);
HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
/* SysTick_IRQn interrupt configuration */
HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
}

Any advice is appreciated, I am also grateful for any patience you can spare (new to stm32/low level programming). Thanks! Marvin #wakeup
4 REPLIES 4
messingmm
Associate
Posted on October 19, 2015 at 23:27

No one knows? Hows everyone else waking up from sleep modes? Any advice is appreciated. Thanks in advance.

chrisPyres66
Associate III

Use a value in place of 0 in HAL_RTCex_SetWakeUpTimer_IT

Mohamed Aymen HZAMI
ST Employee

Hello,

you can download the STM32Cube firmware for the STM32L0 family located on the ST site.

In the firmware you will find examples of the RTC.

You can try this path: STM32Cube_FW_L0_V1.11.0 \ Projects \ STM32L073Z-EVAL \ Examples \ RTC

Best Regards,

Mohamed Aymen.

Rrabb.1
Associate

hello,

In the function,    HAL_RTCEx_SetWakeUpTimer_IT

try to comment

//__HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_EVENT();

and add

   __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_IT();

Then you have EXTI line 0 activated with register 20 for wake timer.