Skip to content

Commit 5c28715

Browse files
authored
Merge pull request #3742 from jeromecoutant/PR_SLEEP
STM32 : minor update in sleep HAL file
2 parents 067f5a0 + 053072c commit 5c28715

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

targets/TARGET_STM/sleep.c

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,28 +27,33 @@
2727
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2828
*******************************************************************************
2929
*/
30-
#include "sleep_api.h"
31-
#include "rtc_api_hal.h"
32-
3330
#if DEVICE_SLEEP
3431

3532
#include "cmsis.h"
33+
#include "us_ticker_api.h"
34+
#include "sleep_api.h"
35+
#include "rtc_api_hal.h"
36+
#include "hal_tick.h"
3637

38+
extern void HAL_SuspendTick(void);
39+
extern void HAL_ResumeTick(void);
3740

3841
void hal_sleep(void)
3942
{
40-
// Stop HAL systick
43+
// Stop HAL tick to avoid to exit sleep in 1ms
4144
HAL_SuspendTick();
4245
// Request to enter SLEEP mode
4346
HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);
44-
// Restart HAL systick
47+
48+
// Restart HAL tick
4549
HAL_ResumeTick();
4650
}
4751

4852
void hal_deepsleep(void)
4953
{
50-
// Stop HAL systick
54+
// Stop HAL tick
5155
HAL_SuspendTick();
56+
uint32_t EnterTimeUS = us_ticker_read();
5257

5358
// Request to enter STOP mode with regulator in low power mode
5459
#if TARGET_STM32L4
@@ -74,12 +79,16 @@ void hal_deepsleep(void)
7479
HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);
7580
#endif /* TARGET_STM32L4 */
7681

77-
// Restart HAL systick
82+
// Restart HAL tick
7883
HAL_ResumeTick();
7984

8085
// After wake-up from STOP reconfigure the PLL
8186
SetSysClock();
8287

88+
TIM_HandleTypeDef TimMasterHandle;
89+
TimMasterHandle.Instance = TIM_MST;
90+
__HAL_TIM_SET_COUNTER(&TimMasterHandle, EnterTimeUS);
91+
8392
#if DEVICE_LOWPOWERTIMER
8493
rtc_synchronize();
8594
#endif

0 commit comments

Comments
 (0)