My first misunderstanding is how to get the MCU to trigger the PreSleepProcessing and PostSleepProcessing functions. Should it not be a case of simply suspending all my tasks with osThreadSuspendAll()?

If I bypass these functions and manually call the sleep functions I am successful calling HAL_PWR_EnterSLEEPMode(PWR_LOWPOWERREGULATOR_ON, PWR_SLEEPENTRY_WFI);

I would like to go one step further and go into STOP RTC mode. I have configured an RTC to wake up every 10s.

I am sending a command to a LoRa module to tell it to go to sleep. I am expecting an "OK" response when it times out so that I can do some processing. If I call HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI); when I wake up via the RTC I seem to have lost my connection to the module and have to reset it to communicate on it again. I have read that I must deinit the UART and renitialise again on wakeup but that does not seem to help.

Has anybody experienced similar and found a way around it? My code to enter STOP mode is below.