2024-12-03 07:27 AM
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?
2024-12-03 07:36 AM - edited 2024-12-03 07:37 AM
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:
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.
2024-12-03 07:54 AM
Hope it does, bc it's running your DATALOG2v2.2.0 demo, downloaded and flashed "as is" :)
2024-12-03 08:09 AM - edited 2024-12-03 08:21 AM
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 ;)