AnsweredAssumed Answered

STM32F427 write to RTC Backup locations doesn't work

Question asked by rhodes.keith on Apr 20, 2015
Latest reply on Apr 21, 2015 by Clive One
I'm using the V1.4 version of the STMCube HAL driver to update the RTC backup registers. I can properly read and write to the Date & Time functions of the RTC.

However, when writing to the RTC Backup registers, the data doesn't appear to be saved.

In the following example, the data read back after it is written is always 0.

int testWriteRTC(void)
{
     unsigned int dataValue;

     RTC_HandleTypeDef g_RtcHandle;


     RCC_OscInitTypeDef        RCC_OscInitStruct;
     RCC_PeriphCLKInitTypeDef  PeriphClkInitStruct;


     /*##-1- Configue LSE as RTC clock soucre ###################################*/
     RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE;
     RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
     RCC_OscInitStruct.LSEState = RCC_LSE_ON;
     RCC_OscInitStruct.LSIState = RCC_LSI_OFF;
     if(HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
     {
          return(false);
     }

     PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC;
     PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
     if(HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
     {
          return(false);
     }

     /*##-2- Enable RTC peripheral Clocks #######################################*/
     /* Enable RTC Clock */
     __HAL_RCC_RTC_ENABLE();

#define RTC_ASYNCH_PREDIV          0x1f
#define RTC_SYNCH_PREDIV          0x3ff

     /*##-1- Configure the RTC peripheral #######################################*/
     g_RtcHandle.Instance = RTC;

     /* Configure RTC prescaler and RTC data registers */
     /* RTC configured as follow:
     - Hour Format    = Format 24
     - Asynch Prediv  = Value according to source clock
     - Synch Prediv   = Value according to source clock
     - OutPut         = Output Disable
     - OutPutPolarity = High Polarity
     - OutPutType     = Open Drain */
     g_RtcHandle.Init.HourFormat = RTC_HOURFORMAT_24;
     g_RtcHandle.Init.AsynchPrediv = RTC_ASYNCH_PREDIV;
     g_RtcHandle.Init.SynchPrediv = RTC_SYNCH_PREDIV;
     g_RtcHandle.Init.OutPut = RTC_OUTPUT_DISABLE;
     g_RtcHandle.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
     g_RtcHandle.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;

     if(HAL_RTC_Init(&g_RtcHandle) != HAL_OK)
     {
          return(false);
     }

     /* Clear Reset Flag */
     __HAL_RCC_CLEAR_RESET_FLAGS();

     /* This fails to update the memory location */
     HAL_RTCEx_BKUPWrite(&g_RtcHandle, 0x00, 0x123456);

     // Read data value back (and notice unchanged)
     DataValue = HAL_RTCEx_BKUPRead(&g_RtcHandle, 0x00);

     // ASSERT fails as DataValue is always 0
     ASSERT(DataValue == 0x123456);

     return(DataValue == 0x123456);
}

I found no errata or information on this write failing. Any help is appreciated.

Outcomes