cancel
Showing results for 
Search instead for 
Did you mean: 

L4 TAMP registers resetting

_EFrie
Associate III

 

 

 

Any suggestions as to why power down, then reconnect debugger (JLINK pro) is clearing the TAMP registers to 0?

Device is STM32L4P5

The clock source seems to be present, it doesn't enter the if statement 

 

 

if (LL_RCC_GetRTCClockSource() != LL_RCC_RTC_CLKSOURCE_LSE) {

 

 

Here is my present MX_RTC_Init

 

 

 

static void MX_RTC_Init(void) {

  /* USER CODE BEGIN RTC_Init 0 */

  /* USER CODE END RTC_Init 0 */

  LL_RTC_InitTypeDef RTC_InitStruct = { 0 };
  LL_RTC_TimeTypeDef RTC_TimeStruct = { 0 };
  LL_RTC_DateTypeDef RTC_DateStruct = { 0 };

  if (LL_RCC_GetRTCClockSource() != LL_RCC_RTC_CLKSOURCE_LSE) {
    FlagStatus pwrclkchanged = RESET;
    /* Update LSE configuration in Backup Domain control register */
    /* Requires to enable write access to Backup Domain if necessary */
    if (LL_APB1_GRP1_IsEnabledClock(LL_APB1_GRP1_PERIPH_PWR) != 1U) {
      /* Enables the PWR Clock and Enables access to the backup domain */
      LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_PWR);
      pwrclkchanged = SET;
    }
    if (LL_PWR_IsEnabledBkUpAccess() != 1U) {
      /* Enable write access to Backup domain */
      LL_PWR_EnableBkUpAccess();
      while (LL_PWR_IsEnabledBkUpAccess() == 0U) {
      }
    }
    LL_RCC_ForceBackupDomainReset();
    LL_RCC_ReleaseBackupDomainReset();
    LL_RCC_LSE_SetDriveCapability(LL_RCC_LSEDRIVE_HIGH);
    LL_RCC_LSE_Enable();

    /* Wait till LSE is ready */
    while (LL_RCC_LSE_IsReady() != 1) {
    }
    LL_RCC_SetRTCClockSource(LL_RCC_RTC_CLKSOURCE_LSE);
    /* Restore clock configuration if changed */
    if (pwrclkchanged == SET) {
      LL_APB1_GRP1_DisableClock(LL_APB1_GRP1_PERIPH_PWR);
    }
  }

  /* Peripheral clock enable */
  LL_RCC_EnableRTC();
  LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_RTCAPB);

  /* USER CODE BEGIN RTC_Init 1 */

/* USER CODE END RTC_Init 1 */
/** Initialize RTC and set the Time and Date
 */

  RTC_InitStruct.HourFormat = LL_RTC_HOURFORMAT_24HOUR;
  /* Settings notes */
  /* 32768 / (31 + 1) == 1024 .. 0x3FF + 1 == 1024 */
#if RTCC_HIRES
  RTC_InitStruct.AsynchPrescaler = 0;
  RTC_InitStruct.SynchPrescaler = 0x7FFF;
#else
  /* 1024 sec */
  RTC_InitStruct.AsynchPrescaler = 31;
  RTC_InitStruct.SynchPrescaler = 0x3FF;
  /* 256 sec */
  // RTC_InitStruct.AsynchPrescaler = 127;
  // RTC_InitStruct.SynchPrescaler = 0xFF;
#endif
  // LL_RTC_Init(RTC, &RTC_InitStruct);

  if (TAMP->BKP31R != 0x32F2) {
    LL_RTC_Init(RTC, &RTC_InitStruct);
    /* Set global flag to indicate time is not set */
    rtccBackupWasDead = 1;
    RTC_TimeStruct.Hours = 0;
    RTC_TimeStruct.Minutes = 0;
    RTC_TimeStruct.Seconds = 0;
    LL_RTC_TIME_Init(RTC, LL_RTC_FORMAT_BIN, &RTC_TimeStruct);
    RTC_DateStruct.WeekDay = LL_RTC_WEEKDAY_MONDAY;
    RTC_DateStruct.Month = LL_RTC_MONTH_JANUARY;
    RTC_DateStruct.Year = 20;
    LL_RTC_DATE_Init(RTC, LL_RTC_FORMAT_BIN, &RTC_DateStruct);
    TAMP->BKP31R = 0x32F2;
  }
#if 0
  /** Initialize RTC and set the Time and Date
   */
    RTC_TimeStruct.Hours = 19;
    RTC_TimeStruct.Minutes = 28;
    RTC_TimeStruct.Seconds = 0;
    LL_RTC_TIME_Init(RTC, LL_RTC_FORMAT_BIN, &RTC_TimeStruct);
    RTC_DateStruct.WeekDay = LL_RTC_WEEKDAY_MONDAY;
    RTC_DateStruct.Month = LL_RTC_MONTH_AUGUST;
    RTC_DateStruct.Day = 2;
    RTC_DateStruct.Year = 22;
    LL_RTC_DATE_Init(RTC, LL_RTC_FORMAT_BIN, &RTC_DateStruct);
    LL_RTC_BAK_SetRegister(RTC, LL_RTC_BKP_DR0, 0x32F2);
#endif
  /* USER CODE BEGIN RTC_Init 2 */
  LL_RTC_DisableWriteProtection(RTC);
  LL_RTC_EnableShadowRegBypass(RTC);
  LL_RTC_EnableWriteProtection(RTC);
  /* USER CODE END RTC_Init 2 */
}

 

 

 

0 REPLIES 0