Skip to content

Commit 7201117

Browse files
committed
MCUXpresso: Fix deepsleep implementation for Kinetis parts
1. Fix the check to look for if MCG has a PLL 2. Do setup before and after deep sleep mode execution Signed-off-by: Mahesh Mahadevan <[email protected]>
1 parent e163a27 commit 7201117

File tree

1 file changed

+39
-6
lines changed
  • targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/api

1 file changed

+39
-6
lines changed

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/api/sleep.c

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,60 @@ void hal_sleep(void)
2525
SMC_SetPowerModeWait(SMC);
2626
}
2727

28+
static void PreEnterStopModes(void)
29+
{
30+
flash_prefetch_speculation_status_t speculationStatus =
31+
{
32+
kFLASH_prefetchSpeculationOptionDisable, /* Disable instruction speculation.*/
33+
kFLASH_prefetchSpeculationOptionDisable, /* Disable data speculation.*/
34+
};
35+
36+
__ISB();
37+
38+
/*
39+
* Before enter stop modes, the flash cache prefetch should be disabled.
40+
* Otherwise the prefetch might be interrupted by stop, then the data and
41+
* and instruction from flash are wrong.
42+
*/
43+
FLASH_PflashSetPrefetchSpeculation(&speculationStatus);
44+
}
45+
46+
static void PostExitStopModes(void)
47+
{
48+
flash_prefetch_speculation_status_t speculationStatus =
49+
{
50+
kFLASH_prefetchSpeculationOptionEnable, /* Enable instruction speculation.*/
51+
kFLASH_prefetchSpeculationOptionEnable, /* Enable data speculation.*/
52+
};
53+
54+
FLASH_PflashSetPrefetchSpeculation(&speculationStatus);
55+
56+
__ISB();
57+
}
58+
2859
void hal_deepsleep(void)
2960
{
3061
#if (defined(FSL_FEATURE_SOC_MCG_COUNT) && FSL_FEATURE_SOC_MCG_COUNT)
31-
#if defined(kMCG_ModePEE)
62+
#if (defined(FSL_FEATURE_MCG_HAS_PLL) && FSL_FEATURE_MCG_HAS_PLL)
3263
mcg_mode_t mode = CLOCK_GetMode();
33-
#endif
34-
#endif
64+
#endif // FSL_FEATURE_MCG_HAS_PLL
65+
#endif // FSL_FEATURE_SOC_MCG_COUNT
3566

3667
SMC_SetPowerModeProtection(SMC, kSMC_AllowPowerModeAll);
3768

69+
PreEnterStopModes();
3870
SMC_SetPowerModeVlps(SMC);
71+
PostExitStopModes();
3972

4073
#if (defined(FSL_FEATURE_SOC_MCG_COUNT) && FSL_FEATURE_SOC_MCG_COUNT)
74+
#if (defined(FSL_FEATURE_MCG_HAS_PLL) && FSL_FEATURE_MCG_HAS_PLL)
4175
/*
4276
* If enter stop modes when MCG in PEE mode, then after wakeup, the MCG is in PBE mode,
4377
* need to enter PEE mode manually.
4478
*/
45-
#if defined(kMCG_ModePEE)
4679
if (mode == kMCG_ModePEE) {
4780
BOARD_BootClockRUN();
4881
}
49-
#endif
50-
#endif
82+
#endif // FSL_FEATURE_MCG_HAS_PLL
83+
#endif // FSL_FEATURE_SOC_MCG_COUNT
5184
}

0 commit comments

Comments
 (0)