Hi community. I struggled a few good days with this. I did not find an exactly related topic, so I thought about posting my experience. Maybe someone will save a couple of days after reading this.
I use STM32F302 (Cortex-M4F) with STM32 HAL and FreeRTOS 10.2.1. I use STOP mode to save power only after certain events. For this purpose I have a custom sleeping function, inspired by port.c vPortSuppressTicksAndSleep().
When returning from STOP mode I call STM32CubeIDE autogenerated SystemClock_Config() to restore system clocks etc. This calls HAL_RCC_ClockConfig() and further HAL_InitTick(TICK_INT_PRIORITY) inside the lib, which sets Systick priority to HAL’s default, which is 0.
This allows Systick interrupts running inside FreeRTOS critical sections, corrupting pxCurrentTCB->xStateListItem->pxContainer.
Browsing through the topics in the forums helped me get ideas where to look. I humbly tip my hat to those who have struggled with this before me.