17
17
#include "cmsis.h"
18
18
#include "fsl_smc.h"
19
19
#include "fsl_clock_config.h"
20
+ #include "pinmap.h"
21
+ #include "fsl_port.h"
22
+ #include "PeripheralPins.h"
23
+
24
+ extern void serial_wait_tx_complete (uint32_t uart_index );
20
25
21
26
void hal_sleep (void )
22
27
{
@@ -25,59 +30,48 @@ void hal_sleep(void)
25
30
SMC_SetPowerModeWait (SMC );
26
31
}
27
32
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
-
59
33
void hal_deepsleep (void )
60
34
{
35
+ uint32_t pin_func ;
61
36
#if (defined(FSL_FEATURE_SOC_MCG_COUNT ) && FSL_FEATURE_SOC_MCG_COUNT )
62
37
#if (defined(FSL_FEATURE_MCG_HAS_PLL ) && FSL_FEATURE_MCG_HAS_PLL )
63
- mcg_mode_t mode = CLOCK_GetMode ();
38
+ smc_power_state_t original_power_state ;
39
+
40
+ original_power_state = SMC_GetPowerModeState (SMC );
64
41
#endif // FSL_FEATURE_MCG_HAS_PLL
65
42
#endif // FSL_FEATURE_SOC_MCG_COUNT
66
43
67
44
SMC_SetPowerModeProtection (SMC , kSMC_AllowPowerModeAll );
68
45
69
- PreEnterStopModes ();
46
+ /* Wait till debug UART is done transmitting */
47
+ serial_wait_tx_complete (STDIO_UART );
48
+
49
+ /*
50
+ * Set pin for current leakage.
51
+ * Debug console RX pin: Set to pinmux to disable.
52
+ * Debug console TX pin: Don't need to change.
53
+ */
54
+ pin_function (STDIO_UART_RX , (int )kPORT_PinDisabledOrAnalog );
55
+
56
+ SMC_PreEnterStopModes ();
70
57
SMC_SetPowerModeVlps (SMC );
71
- PostExitStopModes ();
58
+ SMC_PostExitStopModes ();
59
+
60
+ pin_func = pinmap_find_function (STDIO_UART_RX , PinMap_UART_RX );
61
+ pin_function (STDIO_UART_RX , pin_func );
72
62
73
63
#if (defined(FSL_FEATURE_SOC_MCG_COUNT ) && FSL_FEATURE_SOC_MCG_COUNT )
74
64
#if (defined(FSL_FEATURE_MCG_HAS_PLL ) && FSL_FEATURE_MCG_HAS_PLL )
75
65
/*
76
66
* If enter stop modes when MCG in PEE mode, then after wakeup, the MCG is in PBE mode,
77
67
* need to enter PEE mode manually.
78
68
*/
79
- if (mode == kMCG_ModePEE ) {
80
- BOARD_BootClockRUN ();
69
+ if (original_power_state == kSMC_PowerStateRun ) {
70
+ /* Wait for PLL lock. */
71
+ while (!(kMCG_Pll0LockFlag & CLOCK_GetStatusFlags ()))
72
+ {
73
+ }
74
+ CLOCK_SetPeeMode ();
81
75
}
82
76
#endif // FSL_FEATURE_MCG_HAS_PLL
83
77
#endif // FSL_FEATURE_SOC_MCG_COUNT
0 commit comments