RTC Problem

Sysprogs forums Forums VisualGDB RTC Problem

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #900
    malcolmrook
    Participant

    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);
    }

    #3368
    malcolmrook
    Participant

    Hi
    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 DIV16

    Workround:

    Read date as well. GetDate after GetTime.

    #3369
    support
    Keymaster

    Hi,

    This looks like a hardware bug or the STM32 driver bug. Have you tried contacting the ST support regarding it?

    #3370
    malcolmrook
    Participant

    I 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.

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.