cancel
Showing results for 
Search instead for 
Did you mean: 

Selecting RTC Internal wakeup line

ccuebler
Associate II

Hi everyone!

I have an u585 related question:
Can I configure RTC internal wakeup line other than PWR_WAKEUP_PIN7_HIGH_3 ?
In all u5xx examples used this line, but We have an external wakeup source on  PB.15.
I can't change it in CubeMX and I can't find any reference to change the RTC wakeup line, and if I use PWR_WAKEUP_PIN_HIGH_3, the RTC isn't weak up the CPU anymore.

On the stm32u5xx_hal_pwr.h defined more than one pin as RTC wakeup:

#define PWR_WAKEUP_PIN6_LOW_3 (PWR_WUCR1_WUPEN6 | PWR_WAKEUP6_POLARITY_LOW | PWR_WAKEUP6_SOURCE_SELECTION_3) /*!< RTC  : Wakeup pin 6 (low polarity) */
#define PWR_WAKEUP_PIN7_LOW_3 (PWR_WUCR1_WUPEN7 | PWR_WAKEUP7_POLARITY_LOW | PWR_WAKEUP7_SOURCE_SELECTION_3) /*!< RTC  : Wakeup pin 7 (low polarity) */
#define PWR_WAKEUP_PIN8_LOW_3 (PWR_WUCR1_WUPEN8 | PWR_WAKEUP8_POLARITY_LOW | PWR_WAKEUP8_SOURCE_SELECTION_3) /*!< RTC  : Wakeup pin 8 (low polarity) */



Another question:
We are using standby mode, but sometimes the processor does not go into standby, but into unknown stop mode.
We noticed this by not doing a reset after wakeup.
Is there any condition to make the CPU go to stop mode instead of standby mode even though HAL_PWR_EnterSTANDBYMode() is called?

Thank you!

5 REPLIES 5
AlexisL
ST Employee

Hi @ccuebler,

Concerning you first question, as indicated in the Table 97 of RM0456 (or bellow), You cannot use both B15 and (RTC_ALRA, RTC_ALRB, RTC_WUT, or RTC_TS) as Wakeup source for WKUP7.

AlexisL_0-1713185395491.png

Attention : WKUP7 can only use RTC wakeup line if:

  • TZ = 0
  • TZ = 1 and RTC is non-secured

 

About your second point, I have several ones in order to clarify your application and understand the MCU behavior:

  • Do you clear your pending IRQs before going into Standby mode?
  • Did you add a while(1) loop after entering in Standby Mode in order to catch it if not entering?
  • Can you check the register PWR_SR?

 

Best regards,

Alexis LOUIS

ST Embedded Software Engineer

Hi @AlexisL !

Thank you for reply.

The wakeup problem: 
So if the RTC is secured, it use the WKUP6 instead of WKUP7. I get it.

The second :
No, we didn't clear the Pending IRQs. I will modify my code.

My standby part of code has an branch, because we decide which mode to use (stop or standy) depending on the battery SOC, so if the MCU can not go to standby or stop, we see it in the log:

 

	Debug("================= ENTER SEEP/STANDBY for %d sec ==========================\n", sec);
    // Clear WDT... 
    HAL_IWDG_Refresh(&hiwdg);
    HAL_SuspendTick();

	if (battery.soc < 70) {
		HAL_PWR_EnterSTANDBYMode(); 
	}
	else {
		HAL_PWREx_EnterSTOP2Mode(PWR_SLEEPENTRY_WFI);
	}
    HAL_IWDG_Refresh(&hiwdg);

    // After sleep 
    HAL_Init();
    SystemClock_Config();
    HAL_ResumeTick();

    Debug("================= WAKEUP! ==========================\n");

 

In the PWR->SR was nothing, all the bits are cleared, but In the RCC_CSR the PINRSTF and the OBLRSTF was set.
And now after an OTA routine, we seen same behavior.

 

/*************************************
 * @brief Apply option bytes 
 *************************************/
static void prvOptionByteApply( void ){
    HAL_IWDG_Refresh(&hiwdg);

    Debug( "Option Byte Launch in progress.\n" );

    ( void ) HAL_FLASH_Unlock();
    ( void ) HAL_FLASH_OB_Unlock();
    /* Generate System Reset to load the new option byte values ***************/
    /* On successful option bytes loading the system should reset and control should not return from this function. */
    ( void ) HAL_FLASH_OB_Launch();
}

 

After the OB_Launch, the MCU was reseting, and run from the second bank. But after the STOP2, on wakeup time, the MCU was restarted, and the OBLRSTF was set. And repeated again after STOP2.

Only the full FLASH erase was solve that problem.

I use the OTA code from https://github.com/FreeRTOS/iot-reference-stm32u5/blob/main/Projects/b_u585i_iot02a_ntz/Src/ota_pal/ota_pal_stm32u5_ntz.c
The major difference, I need to clear all flash error flags before erase or program the FLASH, like this:

 

        __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS);
        if( HAL_FLASHEx_Erase( &pEraseInit, &pageError ) != HAL_OK )
        {
            getFlashError();
            ERROR( "Failed to erase the flash bank, errorCode = %u, pageError = %u.\n", HAL_FLASH_GetError(), pageError );
            xResult = false;
        }

 

Otherwise we alwasy get a HAL_FLASH_ERROR_PGS error.


Best regards
Krisztian

AlexisL
ST Employee

Hi @ccuebler,

Thank you for the additional data you provided.

  1. The empty PWR->SR register indicates that you are not entering StopX neither Standby mode. Pending IRQs will make your code to go straight without entering Standby or StopX. In case of a Standby Mode request with pending IRQs, no reset will occurs.
  2. Having the OBLRSTF set after a bank swap is the expected behavior.
  3. OBLaunch sequence is correct.

 

Concerning the HAL_FLASH_ERROR_PGS, you can find page 295 of RM0456 that a PGS Error is triggered when "An error like INCERR, WRPERR, PGSERR, STRBERR, OPTCHANGEERR, OBKERR or OBKWERR have not been cleared before requesting a new write or erase operation, OBK operation or options change." (chapter 7.9.4), so the behavior your observed is the expected one.

 

I hope those explanations will help you to solve your issue.

Best regards,

Alexis LOUIS
ST Embedded Software Engineer

Hi @AlexisL,

Thank you, I will testing with cleared pending IRQs.

According to RM045, I clear that bit after reset, using __HAL_RCC_CLEAR_RESET_FLAGS,
but after the MCU wakes up from STOP, it set again, and the MCU reseting on wakeup time instead of countinues the code.

int main( void ){ 
   /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  uint32_t resetf = RCC->CSR;   //RESET Flags
  uint32_t standbyf = PWR->SR;  //Standby flags
  uint32_t wakeupf  = PWR->WUSR;// Wakeup flags
  standbyFlag = ( 
                  __HAL_PWR_GET_FLAG(PWR_FLAG_SBF) == SET ||       // Standby Flag
                  __HAL_PWR_GET_FLAG(PWR_WAKEUP_FLAG6) == SET ||   // TOF Interrupt wakeup
                  __HAL_PWR_GET_FLAG(PWR_WAKEUP_FLAG7) == SET ||   // TOF Interrupt wakeup
                  __HAL_PWR_GET_FLAG(PWR_WAKEUP_FLAG8) == SET      // RTC Interrupt wakeup
                );
  TOFInterrupt = __HAL_PWR_GET_FLAG(PWR_WAKEUP_FLAG7) == SET;

  //Clear reset flags  
  __HAL_RCC_CLEAR_RESET_FLAGS();

  // Clear standby flags
  __HAL_PWR_CLEAR_FLAG(PWR_FLAG_SBF);
  __HAL_PWR_CLEAR_FLAG(PWR_FLAG_STOPF);

  // Configure the system clock 
  SystemClock_Config();

 
3. Maybe the OTA code in the RTOS's reference was wrong. I revise it.

Best regards,
Krisztian

AlexisL
ST Employee

Hi @ccuebler,

I hope that our exchange helped you and that you've found a solution to your issue.

Best regards,


Alexis LOUIS
ST Embedded Software Engineer