cancel
Showing results for 
Search instead for 
Did you mean: 

STM32u5 does not enter stop mode 2 reliably / wakes up too early

Meixner
Associate II

I am trying to enter stop mode 2 and have it woken up by LPTIM1. Now my problem is that stop mode is not entered reliably (or it wakes up too early which I cannot differentiate). The probability stop mode is entered seems to depend on LPTIM1 configuration. I have checked the pending IRQs in NVIC after wake-up, but none is set when it does not enter stop mode. So I wonder why stop mode 2 was not entered or left too early.

This is what I am doing:

 

 

 

   uint32_t irqpend[16];

   if(timeout_sec>=0) {
      vfLPTimerAlloc(1);
      vfLPTimerSetDuration(1,LPTIMER_CLK_LSE,timeout_sec*1000,true,true);
   }

   /* Enter a critical section but don't use the taskENTER_CRITICAL()
    * method as that will mask interrupts that should exit sleep mode. */
   __asm volatile ( "cpsid i" ::: "memory" );
   __asm volatile ( "dsb" );
   __asm volatile ( "isb" );

   if(timeout_sec>=0) {
      __HAL_RCC_LPTIM1_CLKAM_ENABLE(); // enable autonomous mode
      vfLPTimerEnable(1,0);
   }

   HAL_PWREx_EnterSTOP2Mode(PWR_STOPENTRY_WFI);

   if(timeout_sec>=0) vfLPTimerDisable(1);

   SECURE_SystemClock_Config(); // call secure side of TrustZone to restore clock settings

   for(int z=0;z<16;z++) irqpend[z]=NVIC->ISPR[z];

   /* Re-enable interrupts to allow the interrupt that brought the MCU
    * out of sleep mode to execute immediately.  See comments above
    * the cpsid instruction above. */
   __asm volatile ( "cpsie i" ::: "memory" );
   __asm volatile ( "dsb" );
   __asm volatile ( "isb" );

   if(timeout_sec>=0) vfLPTimerFree(1);
   for(int z=0;z<16;z++) fprintf(stderr,"ISPR[%d]=%08X\n",z,irqpend[z]);

 

 

 

The device has TrustZone enabled.

Shouldn't one of the IRQs be pending when HAL_PWREx_EnterSTOP2Mode() returns? I see an IRQ set when stop mode worked, but none when it did not work.
Why does it work sometimes and sometimes not?
And why does the probability depend on LPTIM1 configuration when there is no IRQ triggered? The higher the timeout, the higher is the probability that it does not work.

And the most important question: How can this be fixed?

0 REPLIES 0