2018-06-13 01:42 AM
STM32CubeMx 4.26.0 RTC Reset always during INIT
The generated Code
void
MX_RTC_Init
(
void
)
{
RTC_TimeTypeDef
sTime
;
RTC_DateTypeDef
sDate
;
/**Initialize RTC Only
*/
hrtc.
Instance
=
RTC;
hrtc.
Init
.
HourFormat
=
RTC_HOURFORMAT_24;
hrtc.
Init
.
AsynchPrediv
=
127
;
hrtc.
Init
.
SynchPrediv
=
255
;
hrtc.
Init
.
OutPut
=
RTC_OUTPUT_DISABLE;
hrtc.
Init
.
OutPutPolarity
=
RTC_OUTPUT_POLARITY_HIGH;
hrtc.
Init
.
OutPutType
=
RTC_OUTPUT_TYPE_OPENDRAIN;
if
(
HAL_RTC_Init
(
&
hrtc)
!=
HAL_OK)
{
_Error_Handler
(__FILE__, __LINE__);
}
/* USER CODE BEGIN RTC_Init 2 */
/* USER CODE END RTC_Init 2 */
/**Initialize RTC and set the Time and Date
*/
sTime
.
Hours
=
0
;
sTime
.
Minutes
=
0
;
sTime
.
Seconds
=
0
;
sTime
.
DayLightSaving
=
RTC_DAYLIGHTSAVING_NONE;
sTime
.
StoreOperation
=
RTC_STOREOPERATION_RESET;
if
(
HAL_RTC_SetTime
(
&
hrtc,
&
sTime
, RTC_FORMAT_BIN)
!=
HAL_OK)
{
_Error_Handler
(__FILE__, __LINE__);
}
/* USER CODE BEGIN RTC_Init 3 */
/* USER CODE END RTC_Init 3 */
sDate
.
WeekDay
=
RTC_WEEKDAY_MONDAY;
sDate
.
Month
=
RTC_MONTH_JANUARY;
sDate
.
Date
=
1
;
sDate
.
Year
=
0
;
if
(
HAL_RTC_SetDate
(
&
hrtc,
&
sDate
, RTC_FORMAT_BIN)
!=
HAL_OK)
{
_Error_Handler
(__FILE__, __LINE__);
}
/* USER CODE BEGIN RTC_Init 4 */
/* USER CODE END RTC_Init 4 */
}
But Older versions generated code (which was correct)
void
MX_RTC_Init
(
void
)
{
RTC_TimeTypeDef
sTime
;
RTC_DateTypeDef
sDate
;
/**Initialize RTC Only
*/
hrtc.
Instance
=
RTC;
if
(
HAL_RTCEx_BKUPRead
(
&
hrtc, RTC_BKP_DR0)
!=
0x32F2
){
hrtc.
Init
.
HourFormat
=
RTC_HOURFORMAT_24;
hrtc.
Init
.
AsynchPrediv
=
127
;
hrtc.
Init
.
SynchPrediv
=
255
;
hrtc.
Init
.
OutPut
=
RTC_OUTPUT_DISABLE;
hrtc.
Init
.
OutPutPolarity
=
RTC_OUTPUT_POLARITY_HIGH;
hrtc.
Init
.
OutPutType
=
RTC_OUTPUT_TYPE_OPENDRAIN;
if
(
HAL_RTC_Init
(
&
hrtc)
!=
HAL_OK)
{
_Error_Handler
(__FILE__, __LINE__);
}
/**Initialize RTC and set the Time and Date
*/
sTime
.
Hours
=
0
;
sTime
.
Minutes
=
0
;
sTime
.
Seconds
=
0
;
sTime
.
DayLightSaving
=
RTC_DAYLIGHTSAVING_NONE;
sTime
.
StoreOperation
=
RTC_STOREOPERATION_RESET;
if
(
HAL_RTC_SetTime
(
&
hrtc,
&
sTime
, RTC_FORMAT_BIN)
!=
HAL_OK)
{
_Error_Handler
(__FILE__, __LINE__);
}
sDate
.
WeekDay
=
RTC_WEEKDAY_MONDAY;
sDate
.
Month
=
RTC_MONTH_JANUARY;
sDate
.
Date
=
1
;
sDate
.
Year
=
0
;
if
(
HAL_RTC_SetDate
(
&
hrtc,
&
sDate
, RTC_FORMAT_BIN)
!=
HAL_OK)
{
_Error_Handler
(__FILE__, __LINE__);
}
HAL_RTCEx_BKUPWrite
(
&
hrtc,RTC_BKP_DR0,
0x32F2
);
}
}
these two lines are missed which always makes the RTC reset
if
(
HAL_RTCEx_BKUPRead
(
&
hrtc, RTC_BKP_DR0)
!=
0x32F2
){
HAL_RTCEx_BKUPWrite
(
&
hrtc,RTC_BKP_DR0,
0x32F2
);
Solved! Go to Solution.
2018-06-19 09:05 AM
Hi
V.Varadharajan
,Thanks for your feedback,
In fact, the idea is to let the user insert his own code using habitual USER TAGs when he doesn't want to re-initialize RTC peripheral.
As you can see, in CubeMX 4.26 version, we have added USER TAGs in the MX_RTC_Init(void) where user can add his own code.
static void MX_RTC_Init(void)
{
/* USER CODE BEGIN RTC_Init 0 */
/* USER CODE END RTC_Init 0 */
RTC_TimeTypeDef sTime;
RTC_DateTypeDef sDate;
/* USER CODE BEGIN RTC_Init 1 */
/* USER CODE END RTC_Init 1 */
/**Initialize RTC Only
*/
hrtc.Instance = RTC;
hrtc.Init.HourFormat = RTC_HOURFORMAT_24;
hrtc.Init.AsynchPrediv = 127;
hrtc.Init.SynchPrediv = 255;
hrtc.Init.OutPut = RTC_OUTPUT_DISABLE;
hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
if (HAL_RTC_Init(&hrtc) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
/* USER CODE BEGIN RTC_Init 2 */
/* USER CODE END RTC_Init 2 */
/**Initialize RTC and set the Time and Date
*/
sTime.Hours = 0x0;
sTime.Minutes = 0x0;
sTime.Seconds = 0x0;
sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
sTime.StoreOperation = RTC_STOREOPERATION_RESET;
if (HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BCD) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
/* USER CODE BEGIN RTC_Init 3 */
/* USER CODE END RTC_Init 3 */
sDate.WeekDay = RTC_WEEKDAY_MONDAY;
sDate.Month = RTC_MONTH_JANUARY;
sDate.Date = 0x1;
sDate.Year = 0x0;
if (HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BCD) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
/* USER CODE BEGIN RTC_Init 4 */
/* USER CODE END RTC_Init 4 */
}
Also, in addition to the backup register, there are others solutions to remain the RTC initialization. It depends on user application. For example, you may also use RTC & PWR flags to determine whether RTC is already initialized or a HW/SW reset has been occurred. So, we can not force user to use backup register solution to remain
RTC initialization.
Hoping it helps you, please do not hesitate to contact me for further details.
Best Regards,
Mohamed.
2018-06-13 02:01 AM
Hi
V.Varadharajan
,Thanks for your feedback. This is now reported internally for further check.
Could you please precise which STM32 MCU and which Cube firmware you're using.
We will update you ASAP.
Khouloud.
2018-06-13 04:49 AM
Dear Sir
I'm using NUCLEO-446ZE Board
2018-06-13 04:50 AM
The Cube Firmware version STM32Cube_FW_F4_V1.21.0
2018-06-13 05:14 AM
Thanks for the details. This will help us when reviewing the reported point.
Khouloud.
2018-06-19 09:05 AM
Hi
V.Varadharajan
,Thanks for your feedback,
In fact, the idea is to let the user insert his own code using habitual USER TAGs when he doesn't want to re-initialize RTC peripheral.
As you can see, in CubeMX 4.26 version, we have added USER TAGs in the MX_RTC_Init(void) where user can add his own code.
static void MX_RTC_Init(void)
{
/* USER CODE BEGIN RTC_Init 0 */
/* USER CODE END RTC_Init 0 */
RTC_TimeTypeDef sTime;
RTC_DateTypeDef sDate;
/* USER CODE BEGIN RTC_Init 1 */
/* USER CODE END RTC_Init 1 */
/**Initialize RTC Only
*/
hrtc.Instance = RTC;
hrtc.Init.HourFormat = RTC_HOURFORMAT_24;
hrtc.Init.AsynchPrediv = 127;
hrtc.Init.SynchPrediv = 255;
hrtc.Init.OutPut = RTC_OUTPUT_DISABLE;
hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
if (HAL_RTC_Init(&hrtc) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
/* USER CODE BEGIN RTC_Init 2 */
/* USER CODE END RTC_Init 2 */
/**Initialize RTC and set the Time and Date
*/
sTime.Hours = 0x0;
sTime.Minutes = 0x0;
sTime.Seconds = 0x0;
sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
sTime.StoreOperation = RTC_STOREOPERATION_RESET;
if (HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BCD) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
/* USER CODE BEGIN RTC_Init 3 */
/* USER CODE END RTC_Init 3 */
sDate.WeekDay = RTC_WEEKDAY_MONDAY;
sDate.Month = RTC_MONTH_JANUARY;
sDate.Date = 0x1;
sDate.Year = 0x0;
if (HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BCD) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
/* USER CODE BEGIN RTC_Init 4 */
/* USER CODE END RTC_Init 4 */
}
Also, in addition to the backup register, there are others solutions to remain the RTC initialization. It depends on user application. For example, you may also use RTC & PWR flags to determine whether RTC is already initialized or a HW/SW reset has been occurred. So, we can not force user to use backup register solution to remain
RTC initialization.
Hoping it helps you, please do not hesitate to contact me for further details.
Best Regards,
Mohamed.
2018-09-20 09:43 AM
But in CubeMX 4.27.0 version void MX_RTC_Init(void) does not contain USER TAGs.
2018-09-20 09:57 AM
Hi,
MX_RTC_Init(void) does contain USER tag with version 4.27.0.
static void MX_RTC_Init(void)
{
/* USER CODE BEGIN RTC_Init 0 */
/* USER CODE END RTC_Init 0 */
/* USER CODE BEGIN RTC_Init 1 */
/* USER CODE END RTC_Init 1 */
/**Initialize RTC Only
*/
hrtc.Instance = RTC;
hrtc.Init.HourFormat = RTC_HOURFORMAT_24;
hrtc.Init.AsynchPrediv = 127;
hrtc.Init.SynchPrediv = 255;
hrtc.Init.OutPut = RTC_OUTPUT_DISABLE;
hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
if (HAL_RTC_Init(&hrtc) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
}
2018-09-22 04:49 AM
STM32CubeMX 4.27.0, STM32F205RETx, STM32F2 MCU Package v. 1.7.0
File Src\rtc.c Lines 49-91
/* RTC init function */
void MX_RTC_Init(void)
{
RTC_TimeTypeDef sTime;
RTC_DateTypeDef sDate;
/**Initialize RTC Only
*/
hrtc.Instance = RTC;
hrtc.Init.HourFormat = RTC_HOURFORMAT_24;
hrtc.Init.AsynchPrediv = 127;
hrtc.Init.SynchPrediv = 255;
hrtc.Init.OutPut = RTC_OUTPUT_DISABLE;
hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
if (HAL_RTC_Init(&hrtc) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
/**Initialize RTC and set the Time and Date
*/
sTime.Hours = 0;
sTime.Minutes = 0;
sTime.Seconds = 0;
sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
sTime.StoreOperation = RTC_STOREOPERATION_RESET;
if (HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BIN) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
sDate.WeekDay = RTC_WEEKDAY_MONDAY;
sDate.Month = RTC_MONTH_JANUARY;
sDate.Date = 1;
sDate.Year = 0;
if (HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BIN) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
}
2018-10-15 06:41 AM
Same problem here for STM32F107. ST please add USER tags in the next release !