Here are a bunch of mistakes I have made that resulted in STM32 not sleeping or not waking.
IWDG_SW bit: cleared (0)IWDG_STOP bit: cleared (0: Independent watchdog counter is frozen in Stop mode)IWDG_STOP, then you must wake the MCU before IWDG expires, reload IWDG then go back to Stop modeHAL_PWR_EnableBkUpAccess() to set the DBP bit in the Power control register 1 (PWR_CR1) to enable access to the backup domain before setting RTC time, alarm or backup registersHAL_PWR_DisableBkUpAccess() is not called to prevent clearing the DBP bit inadvertently__HAL_RCC_LSEDRIVE_CONFIG(__RCC_LSEDRIVE__) is called before setting RTC clock source to LSE, to set an appropriate drive level (refer to AN2867 link below)