cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H573 with Secure Manager, non-secure app can't switch LSE as RTC clock

Christian Keydel
Associate II

This works fine in an app without SM but when I run this from a non-secure app together with SM, the last step fails. This is the code:

  // Enable access to RTC and backup domain
  HAL_PWR_EnableBkUpAccess();

  if (__HAL_RCC_GET_FLAG(RCC_FLAG_LSERDY) == RESET)
  {
    // Reset the backup domain (equivalent to LL_RCC_ForceBackupDomainReset)
    __HAL_RCC_BACKUPRESET_FORCE();
    __HAL_RCC_BACKUPRESET_RELEASE();

    // Ensure LSE is OFF and NOT in bypass mode
    CLEAR_BIT(RCC->BDCR, RCC_BDCR_LSEON | RCC_BDCR_LSEBYP);

    // Set drive strength for startup (must be done while LSE is OFF)
    __HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_MEDIUMHIGH);

    // Enable LSE
    __HAL_RCC_LSE_CONFIG(RCC_LSE_ON);

    // Wait until LSE is ready, with timeout
    if (SYSTIMER_WaitFlag(&RCC->BDCR, RCC_BDCR_LSERDY, true, 20000000))
    {
    }
    else
    {
      // Disable LSE
      __HAL_RCC_LSE_CONFIG(RCC_LSE_OFF);
      // LSE activation error, handle as appropriate
      status = HAL_TIMEOUT;
    }

    // Select LSE as RTC clock source
    __HAL_RCC_RTC_CONFIG(RCC_RTCCLKSOURCE_LSE);
  }

When entering this code, the BDCR register in RCC is 0 so completely clear, nothing is enabled. I noticed that when I repeat the process, the __HAL_RCC_BACKUPRESET_FORCE() (i.e. setting of the VSWRST bit) doesn't have any effect but that's not the issue. I can enable LSEON and LSERDY is being set so the LSE is working but the last step, setting RTCSEL to 1 to select the LSE as RTC clock is not working at all no matter what I try. RTC_SECCFGR is 0x0808 so LSESEC is 0 and RCC_PRIVCFGR is 0x0.
I am stumped, this has worked perfectly fine without SM. I couldn't find any configuration options for SM that relate to this.

0 REPLIES 0