Thanks a lot @Andrew Neil , @waclawek.jan for the answers and hints. I'd start debug and noticed, the wrong initial value in RTC->CR Bit 6 (time format). Immediatelly after invoke HAL_RTC_Init(&hrtc).
static void MX_RTC_Init(void)
{
/* USER CODE BEGIN RTC_Init 0 */
/* USER CODE END RTC_Init 0 */
RTC_PrivilegeStateTypeDef privilegeState = {0}; // note all structures are initialised by 0
RTC_TimeTypeDef sTime = {0};
RTC_DateTypeDef sDate = {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.OutPutRemap = RTC_OUTPUT_REMAP_NONE;
hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
hrtc.Init.OutPutPullUp = RTC_OUTPUT_PULLUP_NONE;
hrtc.Init.BinMode = RTC_BINARY_NONE;
if (HAL_RTC_Init(&hrtc) != HAL_OK)
{
Error_Handler();
}
I tried understand what is wrong and even I compare behavior in firmware example RTC which work properly. The problem was enabled D-CACHE's. BUT... now after disable D-CACHE's I can't set the time:
__HAL_RTC_WRITEPROTECTION_DISABLE(&hrtc) ;
HAL_RTC_WaitForSynchro(&hrtc) ;
HAL_RTC_GetTime(&hrtc, &my_time, RTC_FORMAT_BIN) ;
HAL_RTC_GetDate(&hrtc, &my_date, RTC_FORMAT_BIN) ;
my_time.Minutes = 59;
my_time.Seconds = 56;
__HAL_RTC_WRITEPROTECTION_DISABLE(&hrtc) ; // or without this procedure it doesn't work
HAL_RTC_WaitForSynchro(&hrtc) ; // like above
if (HAL_RTC_SetTime(&hrtc, &my_time, RTC_FORMAT_BIN) != HAL_OK)
{
Error_Handler();
}
Do you have any idea what I'm doing wrong or what I should to do?