Skip to content

Commit df64e32

Browse files
committed
MCUXpresso: Update Kinetis Sleep implementation
1. Use the updated API's provided by the SMC driver 2. Wait till debug UART has finished transmitting data Signed-off-by: Mahesh Mahadevan <[email protected]>
1 parent bed2868 commit df64e32

File tree

2 files changed

+34
-36
lines changed
  • targets
    • TARGET_Freescale/TARGET_MCUXpresso_MCUS/api
    • TARGET_NXP/TARGET_MCUXpresso_MCUS/TARGET_IMX

2 files changed

+34
-36
lines changed

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/api/sleep.c

Lines changed: 30 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
#include "cmsis.h"
1818
#include "fsl_smc.h"
1919
#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);
2025

2126
void hal_sleep(void)
2227
{
@@ -25,59 +30,48 @@ void hal_sleep(void)
2530
SMC_SetPowerModeWait(SMC);
2631
}
2732

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-
5933
void hal_deepsleep(void)
6034
{
35+
uint32_t pin_func;
6136
#if (defined(FSL_FEATURE_SOC_MCG_COUNT) && FSL_FEATURE_SOC_MCG_COUNT)
6237
#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);
6441
#endif // FSL_FEATURE_MCG_HAS_PLL
6542
#endif // FSL_FEATURE_SOC_MCG_COUNT
6643

6744
SMC_SetPowerModeProtection(SMC, kSMC_AllowPowerModeAll);
6845

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();
7057
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);
7262

7363
#if (defined(FSL_FEATURE_SOC_MCG_COUNT) && FSL_FEATURE_SOC_MCG_COUNT)
7464
#if (defined(FSL_FEATURE_MCG_HAS_PLL) && FSL_FEATURE_MCG_HAS_PLL)
7565
/*
7666
* If enter stop modes when MCG in PEE mode, then after wakeup, the MCG is in PBE mode,
7767
* need to enter PEE mode manually.
7868
*/
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();
8175
}
8276
#endif // FSL_FEATURE_MCG_HAS_PLL
8377
#endif // FSL_FEATURE_SOC_MCG_COUNT

targets/TARGET_NXP/TARGET_MCUXpresso_MCUS/TARGET_IMX/sleep.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
extern void vPortPRE_SLEEP_PROCESSING(clock_mode_t powermode);
2121
extern void vPortPOST_SLEEP_PROCESSING(clock_mode_t powermode);
22+
extern void serial_wait_tx_complete(uint32_t uart_index);
2223

2324

2425
void hal_sleep(void)
@@ -36,6 +37,9 @@ void hal_deepsleep(void)
3637
{
3738
vPortPRE_SLEEP_PROCESSING(kCLOCK_ModeStop);
3839

40+
/* Wait till debug UART is done transmitting */
41+
serial_wait_tx_complete(STDIO_UART);
42+
3943
__DSB();
4044
__WFI();
4145
__ISB();

0 commit comments

Comments
 (0)