cancel
Showing results for 
Search instead for 
Did you mean: 

Using RTC_WAKEUPCLOCK_CK_SPRE_16BITS as wakeuptimer

HSpre.1
Associate III

Good Day.

I want to put my stm32wb device to sleep standby mode. and wakeup using RTC after specific time.

I am following the PWR_STANDBY_RTC example which works.

I would like to sleep for up to 12 hours and would like to use RTC_WAKEUPCLOCK_CK_SPRE_16BITS and not RTC_WAKEUPCLOCK_RTCCLK_DIV16 since the latter only allows up to 33 seconds.

I am sucessfuly using RTC_WAKEUPCLOCK_RTCCLK_DIV16 but I am puzzled by value.

for example if I set up counter to:

 HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, 60, RTC_WAKEUPCLOCK_CK_SPRE_16BITS);

it wakes up roughly 16 minutes later.

I have tried various values but it seems a rough value is i must divide my second by 16 to get more or less correct time.

For example

HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, 60/16, RTC_WAKEUPCLOCK_CK_SPRE_16BITS);

Gives me roughtly 60 second wakeup time.

Help would be greatly appreciated.

I m using external 32khz clock and bluetooth functionality works great.

1 ACCEPTED SOLUTION

Accepted Solutions
Scott Löhr
Senior II

It would seem that you have (mis-) configured the RTC Asynchronous and/or Synchronous Prescaler(s) such that the ck_spre is only 1 pulse every 16 seconds.

For a 12 hours sleep, why wouldn't you be using STOP2 instead of Standby?

View solution in original post

5 REPLIES 5
Scott Löhr
Senior II

It would seem that you have (mis-) configured the RTC Asynchronous and/or Synchronous Prescaler(s) such that the ck_spre is only 1 pulse every 16 seconds.

For a 12 hours sleep, why wouldn't you be using STOP2 instead of Standby?

HSpre.1
Associate III

Thank you very much for your help.

The device can be changed updating a characteristic in GATT profile. The device would vary between 5 minutes and 12 hours depending on specific use in field.

I have opted for Standby and not STOP2 because I want to preserve GPIO on certain pins for external hardware.

I have found the problem with prescalaers.

IT is a setting i did not understand/ set under STM32_WPAN which sets up these prescalers in app_conf.h

In the CUBE setup under

Middleware

STM32_WPAN

Configuration

There is a application parameter called CFG_RTCCLK_DIVIDER_CONF

This was set to 0 which which caused

CFG_RTC_ASYNCH_PRESCALER = 16

CFG_RTC_SYNCH_PRESCALER = 32767

I know changed this value to 2

Which changed the setup to

CFG_RTC_ASYNCH_PRESCALER = 2

CFG_RTC_SYNCH_PRESCALER = 16383

below new code for reference if anyone else possibly comes upon this. CFG_RTCCLK_DIVIDER_CONF is set in CUBE

#define CFG_RTCCLK_DIVIDER_CONF 2

#if (CFG_RTCCLK_DIVIDER_CONF == 0)

/**

 * Custom configuration

 * It does not support 1Hz calendar

 * It divides the RTC CLK by 16

 */

#define CFG_RTCCLK_DIV (16)

#define CFG_RTC_WUCKSEL_DIVIDER (0)

#define CFG_RTC_ASYNCH_PRESCALER (CFG_RTCCLK_DIV - 1)

#define CFG_RTC_SYNCH_PRESCALER (0x7FFF)

#else

#if (CFG_RTCCLK_DIVIDER_CONF == 2)

/**

 * It divides the RTC CLK by 2

 */

#define CFG_RTC_WUCKSEL_DIVIDER (3)

#endif

#if (CFG_RTCCLK_DIVIDER_CONF == 4)

/**

 * It divides the RTC CLK by 4

 */

#define CFG_RTC_WUCKSEL_DIVIDER (2)

#endif

#if (CFG_RTCCLK_DIVIDER_CONF == 😎

/**

 * It divides the RTC CLK by 8

 */

#define CFG_RTC_WUCKSEL_DIVIDER (1)

#endif

#if (CFG_RTCCLK_DIVIDER_CONF == 16)

/**

 * It divides the RTC CLK by 16

 */

#define CFG_RTC_WUCKSEL_DIVIDER (0)

#endif

#define CFG_RTCCLK_DIV       CFG_RTCCLK_DIVIDER_CONF

#define CFG_RTC_ASYNCH_PRESCALER  (CFG_RTCCLK_DIV - 1)

#define CFG_RTC_SYNCH_PRESCALER   (DIVR( LSE_VALUE, (CFG_RTC_ASYNCH_PRESCALER+1) ) - 1 )

#endif

HSpre.1
Associate III

error in my post above. Default setting was

This was set to 0 which which caused

 CFG_RTCCLK_DIVIDER_CONF == 0

CFG_RTC_ASYNCH_PRESCALER = 15

CFG_RTC_SYNCH_PRESCALER = 32767

Scott Löhr
Senior II

@HSpre.1​ - Glad to see a resolution to the RTC tick.

WRT your choice for Standby instead of STOP2 for power savings, I see that Standby is actually lower power, but it looks like you have to be sure to configure to keep SRAM2a alive, otherwise it looks like you have to reconfigure everything with CPU2 after every wakeup before using BLE.

For my specific use case I have no need for sram2 or to keep any data. I have a few "config" bytes I have to save for which I use internal flash.

These config bytes will possibly see a change 2 or 3 times in the device lifetime. One of which is the device "sleep time in seconds" value.

Otherwise a complete reset for every wakeup is no issue for my use apart from 1 output pin I need to keep as pull down always except for specific usecase where I have an external circuit I need to reset.

My use case is quite simple

powerup / or wakeup from wakeup_pin_3 or RTC

check sleep time set in config

check option byte for sample time etc.

do sampling

Do math

switch on BLE and advertise

load characteristic GATT values with math data

handle any config byte updates to GATT characteristic values

wait at max 60 seconds for someone to "see me" and connect to me and get values

go to standby for time set.