[STM32U585] Hardfault with program counter "0" after waking up from STOP3 mode
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 sheet. 2.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?
