Sysprogs forums › Forums › VisualGDB › RTC Problem
- This topic has 3 replies, 2 voices, and was last updated 10 years, 3 months ago by malcolmrook.
-
AuthorPosts
-
September 1, 2014 at 11:16 #900malcolmrookParticipant
I have a STM32F405RG with external 16MHz crystal which is also used, divided by 16 as the RTC clock source.
The problem is that the RTC appears to stop after it is read. I have reduced the code down to a minimum to investigate this problem. If put a breakpoint on the first read then wait a known length of time the clock reads OK and the elapsed time is correct. Subsequent reads show the same time.
The code is shown below. Any ideas what is happening?
RTC_TimeTypeDef sTime;
RTC_DateTypeDef sDate;
RTC_HandleTypeDef hrtc;#ifdef __cplusplus
extern “C”
#endif
void SysTick_Handler(void)
{
HAL_IncTick();
}int main(void)
{
HAL_Init();
init_clocks();
init_Gpio();
HAL_RTC_GetTime(&hrtc, &sTime, FORMAT_BCD);
while (1)
{
HAL_GPIO_TogglePin(EVENT_PORT, EVENT_LED_PIN);
HAL_Delay(500);
HAL_RTC_GetTime(&hrtc, &sTime, FORMAT_BCD);
}
}void init_clocks(void)
{
RCC_ClkInitTypeDef RCC_ClkInitStruct;
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;
RCC_OscInitTypeDef RCC_OscInitStruct;PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC;
PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_HSE_DIV16;
HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);__HAL_RCC_RTC_ENABLE();
__PWR_CLK_ENABLE();
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLM = 16;
RCC_OscInitStruct.PLL.PLLN = 320;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
RCC_OscInitStruct.PLL.PLLQ = 4;
HAL_RCC_OscConfig(&RCC_OscInitStruct);RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5);hrtc.Instance = RTC;
hrtc.Init.HourFormat = RTC_HOURFORMAT_24;
hrtc.Init.AsynchPrediv = 124;
hrtc.Init.SynchPrediv = 7999;
hrtc.Init.OutPut = RTC_OUTPUT_DISABLE;
hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
HAL_RTC_Init(&hrtc);sTime.Hours = 1;
sTime.Minutes = 1;
sTime.Seconds = 1;
sTime.SubSeconds = 0;
sTime.TimeFormat = RTC_HOURFORMAT_24;
sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
sTime.StoreOperation = RTC_STOREOPERATION_RESET;
HAL_RTC_SetTime(&hrtc, &sTime, FORMAT_BCD);sDate.WeekDay = RTC_WEEKDAY_MONDAY;
sDate.Month = RTC_MONTH_JANUARY;
sDate.Date = 1;
sDate.Year = 0;
HAL_RTC_SetDate(&hrtc, &sDate, FORMAT_BCD);
}void init_Gpio(void)
{
GPIO_InitTypeDef GPIO_InitStruct;__GPIOB_CLK_ENABLE();
GPIO_InitStruct.Pin = EVENT_LED_PIN | EVENT1_LED_PIN;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
}September 1, 2014 at 12:29 #3368malcolmrookParticipantHi
Re post on RTC problem. This appears to be a bug.PROBLEM:
RTC appears to stop after reading time. First read OK then subsequent reads only show the first read time.To reproduce
Version: VisualGDB 4.2
MCU: STM32F405RG
CLK: HSE 16MHz crystal PLL to 160MHz
RTC: HSE DIV16Workround:
Read date as well. GetDate after GetTime.
September 2, 2014 at 03:07 #3369supportKeymasterHi,
This looks like a hardware bug or the STM32 driver bug. Have you tried contacting the ST support regarding it?
September 5, 2014 at 09:36 #3370malcolmrookParticipantI found a workaround which is to read the date as well as the time. All is OK then.
ST have responded to the problem and declared it not to be a bug but a feature!
It is always necessary to read the date after reading time. My response to them is that the GetTime and GetDate calls should be replaced by a single GetDateTime call. -
AuthorPosts
- You must be logged in to reply to this topic.