@@ -25,27 +25,60 @@ void hal_sleep(void)
25
25
SMC_SetPowerModeWait (SMC );
26
26
}
27
27
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
+
28
59
void hal_deepsleep (void )
29
60
{
30
61
#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 )
32
63
mcg_mode_t mode = CLOCK_GetMode ();
33
- #endif
34
- #endif
64
+ #endif // FSL_FEATURE_MCG_HAS_PLL
65
+ #endif // FSL_FEATURE_SOC_MCG_COUNT
35
66
36
67
SMC_SetPowerModeProtection (SMC , kSMC_AllowPowerModeAll );
37
68
69
+ PreEnterStopModes ();
38
70
SMC_SetPowerModeVlps (SMC );
71
+ PostExitStopModes ();
39
72
40
73
#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 )
41
75
/*
42
76
* If enter stop modes when MCG in PEE mode, then after wakeup, the MCG is in PBE mode,
43
77
* need to enter PEE mode manually.
44
78
*/
45
- #if defined(kMCG_ModePEE )
46
79
if (mode == kMCG_ModePEE ) {
47
80
BOARD_BootClockRUN ();
48
81
}
49
- #endif
50
- #endif
82
+ #endif // FSL_FEATURE_MCG_HAS_PLL
83
+ #endif // FSL_FEATURE_SOC_MCG_COUNT
51
84
}
0 commit comments