cancel
Showing results for 
Search instead for 
Did you mean: 

RTC subsecond alarm wake from STOP

NHui.1
Associate

I am building an application that requires maximum power efficiency. We have decided to use an STM32L031K6 MCU. Our application requires waking up at specific times to power on other external devices. Because the system sleep times can range from hundreds of ms to several hours using batteries in remote locations, it would be ideal to wake up as late as possible to optimize power usage.

We are using the internal RTC clocked with the LSE at 32.768 kHz. I am currently able to demonstrate setting a subsecond alarm and having the interrupt trigger at the correct subsecond increment using the polling:

HAL_RTC_PollForAlarmAEvent(&hrtc, HAL_MAX_DELAY)

However, if I use low-power STOP, the MCU seems to wake up at the top of the second instead of at the subsecond alarm. I am setting up for sleep as follows:

	GPIO_InitTypeDef GPIO_InitStructure = { 0 };
 
	HAL_UART_DeInit(&huart2);
	HAL_UART_DeInit(&hlpuart1);
	
	HAL_PWREx_EnableUltraLowPower();
	HAL_PWREx_EnableFastWakeUp();
	
	HAL_SuspendTick();
	
	__HAL_RCC_GPIOA_CLK_ENABLE();
	__HAL_RCC_GPIOB_CLK_ENABLE();
	__HAL_RCC_GPIOC_CLK_ENABLE();
	__HAL_RCC_GPIOH_CLK_ENABLE();
	/* Configure all GPIO port pins in Analog Input mode (floating input trigger OFF) */
	/* Note: Debug using ST-Link is not possible during the execution of this   */
	/*       example because communication between ST-link and the device       */
	/*       under test is done through UART. All GPIO pins are disabled (set   */
	/*       to analog input mode) including  UART I/O pins.           */
	GPIO_InitStructure.Pin = GPIO_PIN_All;
	GPIO_InitStructure.Mode = GPIO_MODE_ANALOG;
	GPIO_InitStructure.Pull = GPIO_NOPULL;
	HAL_GPIO_Init(GPIOA, &GPIO_InitStructure);
	HAL_GPIO_Init(GPIOB, &GPIO_InitStructure);
	HAL_GPIO_Init(GPIOC, &GPIO_InitStructure);
	HAL_GPIO_Init(GPIOH, &GPIO_InitStructure);
	/* Disable GPIOs clock */
	__HAL_RCC_GPIOA_CLK_DISABLE();
	__HAL_RCC_GPIOB_CLK_DISABLE();
	__HAL_RCC_GPIOC_CLK_DISABLE();
	__HAL_RCC_GPIOH_CLK_DISABLE();
	
	HAL_DBGMCU_EnableDBGStopMode();
	HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);
	
	HAL_ResumeTick();
	
	SystemClock_Config();
	MX_GPIO_Init();
	MX_DMA_Init();
	MX_LPUART1_UART_Init();
	MX_USART2_UART_Init();
	MX_RTC_Init();
	HAL_RTC_WaitForSynchro(&hrtc);

What I see is that subsequent reads of the RTC calendar indicate that we are indeed continuing at the top of the second.

Is there something I need to configure differently with the RTC alarm to get subsecond resolution in STOP mode?

1 REPLY 1

Don't read RTC, but toggle a pin and observe using oscilloscope/LA.

If in doubt, read it and check/post relevant RTC registers content just before sleep and just after sleep. Follow any procedure outlined in RM to ensure the shadow registers being refreshed properly before reading them.

JW