cancel
Showing results for 
Search instead for 
Did you mean: 

[STM32U585] Hardfault with program counter "0" after waking up from STOP3 mode

pa0grg
Associate III

Hello everyone,


I am experiencing a fairly impactful problem with STOP3 mode in a FreeRTOS application that runs in a STM32U585VIT6Q.

The system has this behavior: it wakes up, performs operations on SPI3, write some informations on internal FLASH, returns to STOP3 and reschedules the wakeup via RTC Alarm B in fairly narrow intervals (5 to 30 seconds).
The problem I am experiencing happens infrequently and is not easily intercepted in debug. In any case, I was able to verify (through _get_psp() in HardFault_Handler) that each time the problem occurs, the program counter is worth 0 and the link register points to the SystemClockConfig() function located immediately after the input function in Stop3.

I've read on your errata on STM32U585 and U575 some workaround which might be helpful in this case, such as disabling FLASH prefatch from stm32u5xx_hal_conf.h and disabling/enabling ICACHE just before/after entering/leaving STOP3 mode but it seems not be so good so far (ref: STM32U575xx and STM32U585xx device errata - Errata sheet2.2.11 and 2.2.26).


The low power mode is configured as follows:

 

HAL_PWREx_EnableSRAM2ContentStandbyRetention(PWR_SRAM2_FULL_STANDBY);
HAL_PWREx_EnablePullUpPullDownConfig();

HAL_PWREx_EnableGPIOPullUp(PWR_GPIO_A, PWR_GPIO_BIT_2);
HAL_PWREx_EnableGPIOPullDown(PWR_GPIO_E, PWR_GPIO_BIT_5);
HAL_PWREx_EnableGPIOPullDown(PWR_GPIO_E, PWR_GPIO_BIT_7);
HAL_PWREx_EnableGPIOPullUp(PWR_GPIO_A, PWR_GPIO_BIT_4);
HAL_PWREx_EnableGPIOPullUp(PWR_GPIO_D, PWR_GPIO_BIT_0);
HAL_PWREx_EnableGPIOPullDown(PWR_GPIO_A, PWR_GPIO_BIT_0);
HAL_PWREx_EnableGPIOPullDown(PWR_GPIO_B, PWR_GPIO_BIT_5);
HAL_PWREx_EnableGPIOPullDown(PWR_GPIO_D, PWR_GPIO_BIT_2);
HAL_PWREx_EnableGPIOPullDown(PWR_GPIO_E, PWR_GPIO_BIT_0);

HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN6_HIGH_2);
HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN7_HIGH_3);
HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN4_HIGH_0);

HAL_ICACHE_Disable();
HAL_NVIC_SetPriority(PWR_S3WU_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(PWR_S3WU_IRQn);

HAL_PWREx_EnterSTOP3Mode(PWR_STOPENTRY_WFI);

SystemClock_Config();
HAL_ICACHE_Enable();

 

Any suggestions?

4 REPLIES 4
Sarra.S
ST Employee

Hello @pa0grg

According to Arm® Cortex®-M33 Devices Generic User Guide revision:r0p2 section 3.12.17, if an interrupt is validated at IP level and not validated at the NVIC level, it becomes pending

In your case, there is an interrupt (Systick interrupt) that may be pending before executing WFI() 

Therefore, It is recommended to disable all the interrupts at the source level (expect those configured for the wake-up), try adding HAL_SuspendTick(); before entering STOP3 mode, then add HAL_Resume_tick() after waking up. 

This is ofc, a first path to try...

I may need your project to debug on my side. 

 

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Hello @Sarra.S,

I'm currently trying your fix and so far i'm not facing issues. Anyway, just to make it clear, i've added HAL_ResumeTick() just before 

SystemClock_Config();

and in HAL_PWREx_S3WUCallback as it follows:

void HAL_PWREx_S3WUCallback(uint32_t UINT32_WakeUpPin)
{
   HAL_ResumeTick();

   if ((UINT32_WakeUpPin & PWR_WAKEUP_PIN6) == PWR_WAKEUP_PIN6)
   {
      // do something
   }

   if ((UINT32_WakeUpPin & PWR_WAKEUP_PIN7) == PWR_WAKEUP_PIN7)
   {
      RTC_IRQHandler();
   }

   if ((UINT32_WakeUpPin & PWR_WAKEUP_PIN4) == PWR_WAKEUP_PIN4)
   {
      // do something
   }

   HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN6_HIGH_2);
   HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN7_HIGH_3);
   HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN4_HIGH_0);

   HAL_NVIC_ClearPendingIRQ(PWR_S3WU_IRQn);
   HAL_NVIC_SetPriority(PWR_S3WU_IRQn, 15, 15);

   HAL_NVIC_DisableIRQ(PWR_S3WU_IRQn);
}

 

Hello @Sarra.S ,

I was wondering if it would be correct to cal HAL_ResumeTick and re-init SystemClock_Config in 

HAL_PWREx_S3WUCallback

since it's the first call after wakeup, instead of the next source line code just after EnterSTOP3 call. 

Sarra.S
ST Employee

Hello @pa0grg

You have to resume Tick interrupt after entering stop3 as follows 

/*Suspend Tick increment to prevent wakeup by Systick interrupt. 
Otherwise the Systick interrupt will wake up the device within 1ms (HAL time base)*/
HAL_SuspendTick();

/* Enter stop3 Mode  

/* Resume Tick interrupt if disabled prior to SLEEP mode entry */
HAL_ResumeTick();

 

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.