about wake up from vlls1 by rtc

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

about wake up from vlls1 by rtc

1,490 Views
will_peng
Contributor I

Hi everybody ,

My MCU is MKL03.I wonder if the mkl03 can waked up by RTC SECONDS INTERRUPT from vlls1?

0 Kudos
Reply
4 Replies

972 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi p ww 

Short answer is yes, but you should make sure the clock can work under VLLS1

Regards

Daniel

0 Kudos
Reply

972 Views
will_peng
Contributor I

Thanks!

But when the MKL03 enter VLLS1.it cannot be wake up. Please help me !

/*******************************************************************************
 * Variables for BOARD_BootClockRUN configuration
 ******************************************************************************/
const mcglite_config_t mcgliteConfig_BOARD_BootClockRUN =
    {
        .outSrc = kMCGLITE_ClkSrcLirc,            /* MCGOUTCLK source is LIRC */
        .irclkEnableMode = kMCGLITE_IrclkEnable,  /* MCGIRCLK enabled, MCGIRCLK disabled in STOP mode */
        .ircs = kMCGLITE_Lirc2M,                  /* Slow internal reference (LIRC) 2 MHz clock selected */
        .fcrdiv = kMCGLITE_LircDivBy1,            /* Low-frequency Internal Reference Clock Divider: divided by 1 */
        .lircDiv2 = kMCGLITE_LircDivBy1,          /* Second Low-frequency Internal Reference Clock Divider: divided by 1 */
        .hircEnableInNotHircMode = false,         /* HIRC source is not enabled */
    };
const sim_clock_config_t simConfig_BOARD_BootClockRUN =
    {
        .er32kSrc = SIM_OSC32KSEL_OSC32KCLK_CLK,  /* OSC32KSEL select: OSC32KCLK clock */
        .clkdiv1 = 0x10000U,                      /* SIM_CLKDIV1 - OUTDIV1: /1, OUTDIV4: /2 */
    };
const osc_config_t oscConfig_BOARD_BootClockRUN =
    {
        .freq = 32768U,                           /* Oscillator frequency: 32768Hz */
        .capLoad = (kOSC_Cap4P | kOSC_Cap8P),     /* Oscillator capacity load: 12pF */
        .workMode = kOSC_ModeOscLowPower,         /* Oscillator low power */
        .oscerConfig =
            {
                .enableMode = OSC_ER_CLK_DISABLE, /* Disable external reference clock */
            }
    };
/*******************************************************************************
 * Code for BOARD_BootClockRUN configuration
 ******************************************************************************/
void BOARD_BootClockRUN(void)
{
    /* Set the system clock dividers in SIM to safe value. */
    CLOCK_SetSimSafeDivs();
    /* Enable RTC oscillator. */
    //CLOCK_CONFIG_EnableRtcOsc(RTC_OSC_CAP_LOAD_12PF);
    /* Initializes OSC0 according to board configuration. */
    //CLOCK_InitOsc0(&oscConfig_BOARD_BootClockRUN);
    //CLOCK_SetXtal0Freq(oscConfig_BOARD_BootClockRUN.freq);
    /* Set MCG to LIRC2M mode. */
    CLOCK_SetMcgliteConfig(&mcgliteConfig_BOARD_BootClockRUN);
    /* Set the clock configuration in SIM module. */
    //CLOCK_SetSimConfig(&simConfig_BOARD_BootClockRUN);
//    /* Configure RTC clock. */
//    CLOCK_CONFIG_SetRtcClock();
    /* Set SystemCoreClock variable. */
    SystemCoreClock = BOARD_BOOTCLOCKRUN_CORE_CLOCK;
}
void BOARD_PorClockRUN(void)
{
    /* Set the system clock dividers in SIM to safe value. */
    CLOCK_SetSimSafeDivs();
    /* Enable RTC oscillator. */
    CLOCK_CONFIG_EnableRtcOsc(RTC_OSC_CAP_LOAD_12PF);
    /* Initializes OSC0 according to board configuration. */
    CLOCK_InitOsc0(&oscConfig_BOARD_BootClockRUN);
    CLOCK_SetXtal0Freq(oscConfig_BOARD_BootClockRUN.freq);
    /* Set MCG to LIRC2M mode. */
    CLOCK_SetMcgliteConfig(&mcgliteConfig_BOARD_BootClockRUN);
    /* Set the clock configuration in SIM module. */
    CLOCK_SetSimConfig(&simConfig_BOARD_BootClockRUN);
    /* Configure RTC clock. */
    CLOCK_CONFIG_SetRtcClock();
    /* Set SystemCoreClock variable. */
    SystemCoreClock = BOARD_BOOTCLOCKRUN_CORE_CLOCK;
 CLOCK_SetRtcClkOutClock(0);
}
//rtc.c
void app_rtc_init(void)
{
 rtc_config_t config;
 rtc_datetime_t date;
 RTC_GetDefaultConfig(&config);
 config.wakeupSelect = 0;
 config.supervisorAccess = 1;
 config.updateMode = 1;
 RTC_Init(RTC, &config);
 RTC_StopTimer(RTC);
 /* Set a start date time and start RT */
 date.year = 2017U;
 date.month = 9U;
 date.day = 8U;
 date.hour = 10U;
 date.minute = 39;
 date.second = 0;
 /* Set RTC time to default */
 RTC_SetDatetime(RTC, &date);
 RTC_StartTimer(RTC);
}
uint32_t app_rtc_get_second(void)
{
 CLOCK_EnableClock(kCLOCK_Rtc0);
 return RTC->TSR;
}
void app_rtc_clear_alarm(void)
{
 CLOCK_EnableClock(kCLOCK_Rtc0);
 RTC_ClearStatusFlags(RTC, kRTC_AlarmInterruptEnable);
}
void app_rtc_set_alarm(uint16_t second)
{
 uint32_t currSeconds;
 //CLOCK_EnableClock(kCLOCK_Rtc0);
 currSeconds = RTC->TSR;
 RTC->TAR = currSeconds + second;
 /* Enable RTC alarm interrupt */
 RTC_EnableInterrupts(RTC, kRTC_AlarmInterruptEnable); 
 //EnableIRQ(RTC_IRQn);
}
void app_rtc_enable_second_alarm(void)
{
 CLOCK_EnableClock(kCLOCK_Rtc0);
 RTC_DisableInterrupts(RTC, RTC_IER_TIIE_MASK); 
 RTC_DisableInterrupts(RTC, RTC_IER_TOIE_MASK); 
 RTC_DisableInterrupts(RTC, RTC_IER_TAIE_MASK); 
 RTC_EnableInterrupts(RTC, kRTC_SecondsInterruptEnable); 
}
void app_rtc_disable_second_alarm(void)
{
 RTC_DisableInterrupts(RTC, kRTC_SecondsInterruptEnable); 
}
//main.c
void RTC_IRQHandler(void)
{
    if (RTC_GetStatusFlags(RTC) & kRTC_AlarmFlag)
    {
  RTC_ClearStatusFlags(RTC, kRTC_AlarmFlag);
  Ht1621_Bus_Init();
  run_para->lcd_second++;
  run_para->lcd_second = run_para->lcd_second % 10;
  Display_Small_No1(run_para->lcd_second);
  app_rtc_set_alarm(2);
  /* Clear alarm flag */
   }
}
void RTC_Seconds_IRQHandler(void)
{
  Ht1621_Bus_Init();
  run_para->lcd_second++;
  run_para->lcd_second = run_para->lcd_second % 10;
  Display_Small_No1(run_para->lcd_second);
}
/*!
 * @brief LLWU interrupt handler.
 */
void LLWU_IRQHandler(void)
{
 if(LLWU_GetExternalWakeupPinFlag(LLWU, LLWU_WAKEUP_PIN_IDX))
 {
  LLWU_ClearExternalWakeupPinFlag(LLWU, LLWU_WAKEUP_PIN_IDX);
 }
  Ht1621_Bus_Init();
  run_para->lcd_second++;
  run_para->lcd_second = run_para->lcd_second % 10;
  Display_Small_No1(run_para->lcd_second);
}
void PORTB_IRQHandler(void)
{
 if ((1U << WAKE_PIN) & PORT_GetPinsInterruptFlags(PORTB))
 {//WAKE
  PORT_ClearPinsInterruptFlags(PORTB, (1U << WAKE_PIN));
 }
}

int main(void) {
 extern void BOARD_PorClockRUN(void);
 
 SMC_SetPowerModeProtection(SMC, kSMC_AllowPowerModeAll); //CPUÔËÐÐÔÚËùÓеçÔ´¹¤×÷ģʽÏÂ
    if (kRCM_SourcePor & RCM_GetPreviousResetSources(RCM)) /* Wakeup POR */
    {
  //por reset
  //check flash crc or load default para
  BOARD_PorClockRUN();
  //MCG->C2 |= MCG_C2_EREFS0_MASK;
  app_rtc_init();
  app_rtc_enable_second_alarm();
  //app_rtc_set_alarm(1);
 }
 else
 {
  BOARD_InitBootClocks();
  CLOCK_EnableClock(kCLOCK_Rtc0);
  //RTC_StartTimer(RTC);
 }
 Ht1621_Init();
 Ht1621_clear();
 run_para->lcd_second++;
 run_para->lcd_second = run_para->lcd_second % 10;
 button_init();
 wake_init();
 NVIC_EnableIRQ(RTC_Seconds_IRQn);
 //NVIC_EnableIRQ(RTC_IRQn);
 NVIC_EnableIRQ(LLWU_IRQn);
 if (kRCM_SourceWakeup & RCM_GetPreviousResetSources(RCM)) /* Wakeup from VLLS. */
 {
 }
 enable_llwu_interrupt();
 power_mode_vlls1();  
 while(1) {
 }
}
0 Kudos
Reply

972 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi p ww

I would suggest you check the clock source for the RTC, it should be LPO or RTC_CLKIN, otherwise, it can not work in VLLSx mode.

Regards

Daniel

0 Kudos
Reply

972 Views
will_peng
Contributor I

Hi Daniel

Thank you!

https://community.nxp.com/thread/391256

I use OSC as the clock source. I fix the issue by delay 125ms after wakeup from VLL1.

0 Kudos
Reply