查看: 1390|回复: 5

[求助] RTC1050 利用RTC alarm中断不能唤醒芯片

[复制链接]

该用户从未签到

6

主题

18

帖子

0

注册会员

Rank: 2

积分
119
最后登录
2022-1-26
发表于 2021-4-13 15:11:16 | 显示全部楼层 |阅读模式

volatile bool busyWait;
#define EXAMPLE_SNVS_IRQHandler SNVS_HP_WRAPPER_IRQHandler
void EXAMPLE_SNVS_IRQHandler(void)       
{
//    if (SNVS_HP_RTC_GetStatusFlags(SNVS) & kSNVS_RTC_AlarmInterruptFlag)
//    {
        busyWait = false;
                SNVS_HP_RTC_DisableInterrupts(SNVS, kSNVS_RTC_AlarmInterrupt);
                SNVS_HP_RTC_StopTimer(SNVS);
               
        SNVS_HP_RTC_ClearStatusFlags(SNVS, kSNVS_RTC_AlarmInterruptFlag); //Clear alarm flag
            SNVS_HP_RTC_ClearStatusFlags(SNVS, kSNVS_RTC_PeriodicInterrupt); //Clear alarm flag
                LPM_DisableWakeupSource(SNVS_HP_WRAPPER_IRQn);
//    }

}
#define kCLOCK_SnvsHp0          kCLOCK_SnvsHp
#define EXAMPLE_SNVS_IRQn       SNVS_HP_WRAPPER_IRQn
#define EXAMPLE_SNVS_IRQHandler SNVS_HP_WRAPPER_IRQHandler

void rtc(void)
{
        uint32_t sec;
    uint8_t index;
    snvs_hp_rtc_datetime_t rtcDate;
    snvs_hp_rtc_config_t snvsRtcConfig;
       
        SNVS_HP_RTC_GetDefaultConfig(&snvsRtcConfig);
    SNVS_HP_RTC_Init(SNVS, &snvsRtcConfig);

    PRINTF("SNVS HP example:\r\n");

    /* Set a start date time and start RT */
    rtcDate.year   = 2014U;
    rtcDate.month  = 12U;
    rtcDate.day    = 25U;
    rtcDate.hour   = 19U;
    rtcDate.minute = 0;
    rtcDate.second = 0;

    /* Set RTC time to default time and date and start the RTC */
    SNVS_HP_RTC_SetDatetime(SNVS, &rtcDate);
    SNVS_HP_RTC_StartTimer(SNVS);

       

    PRINTF("Set up time to wake up an alarm.\r\n");
    /* This loop will set the SNVS alarm */

        busyWait = true;
        index    = 0;
        sec      = 0;

        /* Get date time */
        SNVS_HP_RTC_GetDatetime(SNVS, &rtcDate);

        /* print default time */
        PRINTF("Current datetime: %04d-%02d-%02d %02d:%02d:%02d\r\n", rtcDate.year, rtcDate.month, rtcDate.day,
           rtcDate.hour, rtcDate.minute, rtcDate.second);

        /* Get alarm time from user */
        PRINTF("Please input the number of second to wait for alarm and press enter \r\n");
        PRINTF("The second must be positive value\r\n");


        sec = 10;
        SNVS_HP_RTC_GetDatetime(SNVS, &rtcDate);
        if ((rtcDate.second + sec) < 60)
        {
                rtcDate.second += sec;
        }
        else
        {
                rtcDate.minute += (rtcDate.second + sec) / 60U;
                rtcDate.second = (rtcDate.second + sec) % 60U;
        }

        SNVS_HP_RTC_SetAlarm(SNVS, &rtcDate);

       
       
               
//        SNVS_HP_RTC_ClearStatusFlags(SNVS, kSNVS_RTC_AlarmInterruptFlag);
        /* Enable SNVS alarm interrupt */
    SNVS_HP_RTC_EnableInterrupts(SNVS, kSNVS_RTC_PeriodicInterrupt);
        /* Enable at the NVIC */
       
        NVIC_ClearPendingIRQ(EXAMPLE_SNVS_IRQn);
        NVIC_EnableIRQ(EXAMPLE_SNVS_IRQn);
        EnableIRQ(EXAMPLE_SNVS_IRQn);
        LPM_EnableWakeupSource(EXAMPLE_SNVS_IRQn);
       
       
        /* Get alarm time */
        SNVS_HP_RTC_GetAlarm(SNVS, &rtcDate);

        /* Print alarm time */
        PRINTF("Alarm will occur at: %04d-%02d-%02d %02d:%02d:%02d\r\n", rtcDate.year, rtcDate.month, rtcDate.day,
        rtcDate.hour, rtcDate.minute, rtcDate.second);       
        /* Wait until alarm occurs */
//        while (busyWait)
//        {
//        }

//        PRINTF("\r\n Alarm occurs !!!! ");       
               
}


/*!
* @brief main demo function.
*/
int main(void)



{
    uint8_t ch;
    uint32_t freq;
    bool needSetWakeup = 1; /* Need to set wakeup. */
       
    /* Init board hardware. */
    BOARD_ConfigMPU();
    BOARD_InitPins();
    BOARD_InitBootClocks();

    /* When wakeup from suspend, peripheral's doze & stop requests won't be cleared, need to clear them manually */
    IOMUXC_GPR->GPR4  = 0x00000000;
    IOMUXC_GPR->GPR7  = 0x00000000;
    IOMUXC_GPR->GPR8  = 0x00000000;
    IOMUXC_GPR->GPR12 = 0x00000000;

    /* Configure UART divider to default */
    CLOCK_SetMux(kCLOCK_UartMux, 1); /* Set UART source to OSC 24M */
    CLOCK_SetDiv(kCLOCK_UartDiv, 0); /* Set UART divider to 1 */

    BOARD_InitDebugConsole();

    /* Since SNVS_PMIC_STBY_REQ_GPIO5_IO02 will output a high-level signal under Stop Mode(Suspend Mode) and this pin is
     * connected to LCD power switch circuit. So it needs to be configured as a low-level output GPIO to reduce the
     * current. */
    BOARD_Init_PMIC_STBY_REQ();
    BOARD_InitBootPeripherals();

    PRINTF("\r\nCPU wakeup source 0x%x...\r\n", SRC->SRSR);

    PRINTF("\r\n***********************************************************\r\n");
    PRINTF("\tPower Mode Switch Demo for %s\r\n", CPU_NAME);
    PRINTF("***********************************************************\r\n");
    APP_PrintRunFrequency(0);
       
    LPM_Init();
    /* Set power mode to over run after power on */
    APP_SetRunMode(LPM_PowerModeOverRun);
    LPM_OverDriveRun();


    while (1)
    {
        freq = CLOCK_GetFreq(kCLOCK_CpuClk);

        PRINTF("\r\n########## Power Mode Switch Demo (build %s) ###########\n\r\n", __DATE__);
        PRINTF("    Core Clock = %dHz \r\n", freq);

        APP_ShowPowerMode(s_curRunMode);

        PRINTF("\r\nSelect the desired operation \n\r\n");
        PRINTF("Press  %c for enter: Over RUN       - System Over Run mode\r\n",
               (uint8_t)'A' + (uint8_t)LPM_PowerModeOverRun);
        PRINTF("Press  %c for enter: Full RUN       - System Full Run mode\r\n",
               (uint8_t)'A' + (uint8_t)LPM_PowerModeFullRun);
        PRINTF("Press  %c for enter: Low Speed RUN  - System Low Speed Run mode\r\n",
               (uint8_t)'A' + (uint8_t)LPM_PowerModeLowSpeedRun);
        PRINTF("Press  %c for enter: Low Power RUN  - System Low Power Run mode\r\n",
               (uint8_t)'A' + (uint8_t)LPM_PowerModeLowPowerRun);
        PRINTF("Press  %c for enter: System Idle    - System Wait mode\r\n",
               (uint8_t)'A' + (uint8_t)LPM_PowerModeSysIdle);
        PRINTF("Press  %c for enter: Low Power Idle - Low Power Idle mode\r\n",
               (uint8_t)'A' + (uint8_t)LPM_PowerModeLPIdle);
        PRINTF("Press  %c for enter: Suspend        - Suspend mode\r\n", (uint8_t)'A' + (uint8_t)LPM_PowerModeSuspend);
#if (HAS_WAKEUP_PIN)
        PRINTF("Press  %c for enter: SNVS           - Shutdown the system\r\n",
               (uint8_t)'A' + (uint8_t)LPM_PowerModeSNVS);
#endif
        PRINTF("\r\nWaiting for power mode select...\r\n\r\n");

        /* Wait for user response */
        ch = GETCHAR();

        if ((ch >= 'a') && (ch <= 'z'))
        {
            ch -= 'a' - 'A';
        }

        s_targetPowerMode = (lpm_power_mode_t)(ch - 'A');

        if (s_targetPowerMode <= LPM_PowerModeEnd)
        {
            /* If could not set the target power mode, loop continue. */
            if (!APP_CheckPowerMode(s_curRunMode, s_targetPowerMode))
            {
                continue;
            }
                       

            /* If target mode is run mode, don't need to set wakeup source. */
            if (s_targetPowerMode <= LPM_PowerModeLowPowerRun)
            {
                needSetWakeup = false;
            }
            else
            {
                needSetWakeup = true;
            }

            if (needSetWakeup)
            {
//                APP_GetWakeupConfig(s_targetPowerMode);
//                APP_SetWakeupConfig(s_targetPowerMode);
            }
                rtc();
          SDK_DelayAtLeastUs(100, SDK_DEVICE_MAXIMUM_CPU_CLOCK_FREQUENCY);
            APP_PowerPreSwitchHook(s_targetPowerMode);
            APP_PowerModeSwitch(s_targetPowerMode);
            APP_PowerPostSwitchHook(s_targetPowerMode);
                       
//                        while (busyWait)
//                        {
//                               
//                        }
                       
                        PRINTF("\r\n Alarm occurs !!!! ");
        }
        PRINTF("\r\nNext loop\r\n");
    }
}


回复

使用道具 举报

该用户从未签到

6

主题

18

帖子

0

注册会员

Rank: 2

积分
119
最后登录
2022-1-26
 楼主| 发表于 2021-4-13 15:12:38 | 显示全部楼层
中断能够独立响应  进入lowpower模式后利用 ALARM中断不能够唤醒芯片,在线调试GPC能够有响应
回复 支持 反对

使用道具 举报

该用户从未签到

656

主题

6312

帖子

0

超级版主

Rank: 8Rank: 8

积分
19947
最后登录
2024-4-19
发表于 2021-4-13 18:13:27 | 显示全部楼层
lving 发表于 2021-4-13 15:12
中断能够独立响应  进入lowpower模式后利用 ALARM中断不能够唤醒芯片,在线调试GPC能够有响应 ...

楼主你好!
你RT1050的芯片具体型号,还有你的代码是SDK最新的版本吗?
然后我会帮你做检查。你的Low power 是哪个模式?
回复 支持 反对

使用道具 举报

该用户从未签到

6

主题

18

帖子

0

注册会员

Rank: 2

积分
119
最后登录
2022-1-26
 楼主| 发表于 2021-4-14 09:23:50 | 显示全部楼层
小恩GG 发表于 2021-4-13 18:13
楼主你好!
你RT1050的芯片具体型号,还有你的代码是SDK最新的版本吗?
然后我会帮你做检查。你的Low pow ...

芯片型号是MIMXRT1062DVL6A     SDK是2.8.6  谢谢  查看手册应该是要用SRTC唤醒?
回复 支持 反对

使用道具 举报

该用户从未签到

6

主题

18

帖子

0

注册会员

Rank: 2

积分
119
最后登录
2022-1-26
 楼主| 发表于 2021-4-14 12:11:05 | 显示全部楼层
问题已解决   注意唤醒源的设置 只能使用LP_SRTC唤醒  LPCR寄存器唤醒中断的设置
回复 支持 反对

使用道具 举报

该用户从未签到

656

主题

6312

帖子

0

超级版主

Rank: 8Rank: 8

积分
19947
最后登录
2024-4-19
发表于 2021-4-14 14:15:04 | 显示全部楼层
lving 发表于 2021-4-14 12:11
问题已解决   注意唤醒源的设置 只能使用LP_SRTC唤醒  LPCR寄存器唤醒中断的设置 ...

SDK版本有些低了,可以使用最新的SDK2.9.X。另外感谢楼主分享解决方案。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 注册/登录

本版积分规则

关闭

站长推荐上一条 /4 下一条

Archiver|手机版|小黑屋|恩智浦技术社区

GMT+8, 2024-4-20 16:25 , Processed in 0.119012 second(s), 23 queries , MemCache On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表