cancel
Showing results for 
Search instead for 
Did you mean: 

STWINBX1 loses RTC at poweroff?

Old_Geezer
Associate II

Hi

I have found that the STWINBX1 loses RTC at poweroff (or does CubeMX write code to reset RTC at poweron? there is a ticket on that) so that I have to battery-power it on, connect usb, update RTC and then disconnect while still on in order to log without "2001-01-01 00:01". 

Its LiPo battery is connected and above 90%

Is there a remedy?

1 ACCEPTED SOLUTION

Accepted Solutions

According to the schematics you attached, VBAT pin is hardwired to VDD_uC and not to a dedicated battery cell. So if you lose the power on VDD_uC you will lose the Time/date. So you need to keep VDD_uC powred on.

SofLit_0-1733326674670.png

 

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

View solution in original post

9 REPLIES 9
SofLit
ST Employee

Hello, 


@Old_Geezer wrote:

or does CubeMX write code to reset RTC at poweron?


Check if you don't configure the the time and date at each power on. Check out this example:

https://github.com/STMicroelectronics/STM32CubeL4/tree/master/Projects/STM32L476G-EVAL/Examples/RTC/RTC_Calendar

You need to configure the Time/Date one and save that status in the Buck up register and at each power on you check this status, if the time/date was configured you escape the time/date settings:

RTC_CalendarConfig() implementation:

 

static void RTC_CalendarConfig(void)
{
  RTC_DateTypeDef sdatestructure;
  RTC_TimeTypeDef stimestructure;

  /*##-1- Configure the Date #################################################*/
  /* Set Date: Tuesday February 18th 2014 */
  sdatestructure.Year = 0x14;
  sdatestructure.Month = RTC_MONTH_FEBRUARY;
  sdatestructure.Date = 0x18;
  sdatestructure.WeekDay = RTC_WEEKDAY_TUESDAY;
  
  if(HAL_RTC_SetDate(&RtcHandle,&sdatestructure,RTC_FORMAT_BCD) != HAL_OK)
  {
    /* Initialization Error */
    Error_Handler(); 
  } 
  
  /*##-2- Configure the Time #################################################*/
  /* Set Time: 02:00:00 */
  stimestructure.Hours = 0x02;
  stimestructure.Minutes = 0x00;
  stimestructure.Seconds = 0x00;
  stimestructure.TimeFormat = RTC_HOURFORMAT12_AM;
  stimestructure.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
  stimestructure.StoreOperation = RTC_STOREOPERATION_RESET;
  
  if(HAL_RTC_SetTime(&RtcHandle,&stimestructure,RTC_FORMAT_BCD) != HAL_OK)
  {
    /* Initialization Error */
    Error_Handler(); 
  }
  
  /*##-3- Writes a data in a RTC Backup data Register0 #######################*/
  HAL_RTCEx_BKUPWrite(&RtcHandle,RTC_BKP_DR0,0x32F2);  
}

 

-> it sets the value 0x32F2 in the BKP registers after configuring the calendar.

That will be checked later on at power up.

 

  /*##-2- Check if Data stored in BackUp register1: No Need to reconfigure RTC#*/
  /* Read the Back Up Register 1 Data */
  if (HAL_RTCEx_BKUPRead(&RtcHandle, RTC_BKP_DR1) != 0x32F2)
  {
    /* Configure RTC Calendar */
    RTC_CalendarConfig();
  }
  else
  {

 

 Hope that answers your question.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

Hope it does, bc it's running your DATALOG2v2.2.0 demo, downloaded and flashed "as is" :)

Sorry I don't have idea about this demo even about this STWINBX1 board but the concept is the same as long as this box is based on a STM32 MCU ;)

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

Sorry, but your example only results in the clock being set to 240218 00:00.

So either my implementation of your code is bad or the MCU has no RTC power.

Below is main() of my altered DATALOG2 demo.

  

int main(void)
{
  // System initialization
RTC_HandleTypeDef RtcHandle;
    RtcHandle.Instance = RTC;
  SysInit(FALSE);
  if (HAL_RTCEx_BKUPRead(&RtcHandle, RTC_BKP_DR1) != 0x32F2)
    {
      /* Configure RTC Calendar */
      RTC_CalendarConfig();
    }
    else
    {
    }
  tx_kernel_enter();
  while (1);
}

 

Hello,

The code I provided is taken from this example and nothing wrong in it: form https://github.com/STMicroelectronics/STM32CubeL4/tree/master/Projects/STM32L476G-EVAL/Examples/RTC/RTC_Calendar

You need to have VBAT pin powered on (to backup the time and the backup registers) while the board is powered off. This is the idea.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

Well, maybe you can find someone who can confirm whether VBAT is connected uninterrupted to battery on this board. I can't, not that proficient. In the user's manual are two links (in blue) to further details but those are dead:  

Old_Geezer_0-1733324607990.png

I was however able to google the schematic:

https://www.st.com/resource/en/schematic_pack/steval-stwinbox1-schematic.pdf

 

According to the schematics you attached, VBAT pin is hardwired to VDD_uC and not to a dedicated battery cell. So if you lose the power on VDD_uC you will lose the Time/date. So you need to keep VDD_uC powred on.

SofLit_0-1733326674670.png

 

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

Well, that board is a (likely multilayered) ST board, so either you or I will have to file a report if this is to be fixed in a future version.

 

I think connecting VBAT to VDD was an option of the design I think for simplification and this is something we can see in many ST boards like Disco board for example.

I've already escalated this remark a moment ago .. I don't know if it will be taken in consideration or not.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.