<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: iMXRT1021 Keep RTC counter when device reboot in i.MX RT Crossover MCUs</title>
    <link>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/iMXRT1021-Keep-RTC-counter-when-device-reboot/m-p/1322540#M15841</link>
    <description>&lt;P&gt;Dear&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/60336"&gt;@kerryzhou&lt;/a&gt;&amp;nbsp;,&lt;BR /&gt;&lt;BR /&gt;Ok let me check my code, but can IMXRT hardware support stored RTC counter when device reset by software?&lt;BR /&gt;In some case, because the fault or exception, we can't save RTC counter to flash.&lt;BR /&gt;I would like RTC keep value, like other MCU (STM32...), RTC backup register, RTC counter still keep the old value before reset&lt;/P&gt;</description>
    <pubDate>Thu, 12 Aug 2021 09:20:32 GMT</pubDate>
    <dc:creator>huy_tv</dc:creator>
    <dc:date>2021-08-12T09:20:32Z</dc:date>
    <item>
      <title>iMXRT1021 Keep RTC counter when device reboot</title>
      <link>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/iMXRT1021-Keep-RTC-counter-when-device-reboot/m-p/1321841#M15812</link>
      <description>&lt;P&gt;Dear all,&lt;BR /&gt;&lt;BR /&gt;I tried to store RTC counter each time device reset (software reset only).&lt;BR /&gt;But everytime device boot again from software reset, RTC counter always count from 1970 (monitor by debug breakpoint)&lt;BR /&gt;&lt;BR /&gt;This is my code to write and read RTC time. Could you please review it and give me your suggestion?&lt;BR /&gt;Thank you.&lt;/P&gt;&lt;P&gt;1. RTC initialize&lt;/P&gt;&lt;LI-CODE lang="c"&gt;void rtc_intialize(void)
{
    snvs_hp_rtc_datetime_t rtcDate;
    snvs_hp_rtc_config_t snvsRtcConfig;

    SNVS_HP_RTC_GetDatetime(SNVS, &amp;amp;rtcDate);
    /* Init SNVS */
    /*
     * snvsConfig-&amp;gt;rtccalenable = false;
     * snvsConfig-&amp;gt;rtccalvalue = 0U;
     * snvsConfig-&amp;gt;srtccalenable = false;
     * snvsConfig-&amp;gt;srtccalvalue = 0U;
     * snvsConfig-&amp;gt;PIFreq = 0U;
     */
    SNVS_HP_RTC_GetDefaultConfig(&amp;amp;snvsRtcConfig);
    SNVS_HP_RTC_Init(SNVS, &amp;amp;snvsRtcConfig);

    if (rtcDate.year &amp;lt; 2000 || rtcDate.year &amp;gt; 2049)
    {
    	/* Set a start date time and start RT */
       rtcDate.year   = 2000U;
       rtcDate.month  = 0;
       rtcDate.day    = 0;
       rtcDate.hour   = 0;
       rtcDate.minute = 0;
       rtcDate.second = 0;

       /* Set RTC time to default time and date and start the RTC */
       SNVS_HP_RTC_SetDatetime(SNVS, &amp;amp;rtcDate);
    }
    SNVS_HP_RTC_StartTimer(SNVS);
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;2. RTC set&lt;/P&gt;&lt;LI-CODE lang="c"&gt;bool rtc_set_time(rtc_date_time_t *time)
{
    snvs_hp_rtc_datetime_t rtc_date;
	/* Set a start date time and start RT */
    rtc_date.year   = time-&amp;gt;year+2000;
    rtc_date.month  = time-&amp;gt;month;
    rtc_date.day    = time-&amp;gt;day;
    rtc_date.hour   = time-&amp;gt;hour;
    rtc_date.minute = time-&amp;gt;minute;
    rtc_date.second = time-&amp;gt;second;

	/* Set RTC time to default time and date and start the RTC */
	if (kStatus_Success != SNVS_HP_RTC_SetDatetime(SNVS, &amp;amp;rtc_date))
	{
		return false;
	}

	return true;
}&lt;/LI-CODE&gt;&lt;P&gt;3. RTC read&lt;/P&gt;&lt;LI-CODE lang="c"&gt;{
	snvs_hp_rtc_datetime_t date_time;
	SNVS_HP_RTC_GetDatetime(SNVS, &amp;amp;date_time);

	time-&amp;gt;year = date_time.year;
	time-&amp;gt;month = date_time.month;
	time-&amp;gt;day = date_time.day;
	time-&amp;gt;hour = date_time.hour + 7;		// gsm + 7
	time-&amp;gt;minute = date_time.minute;
	time-&amp;gt;second = date_time.second;
	get_weekday(time);
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Aug 2021 10:22:21 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/iMXRT1021-Keep-RTC-counter-when-device-reboot/m-p/1321841#M15812</guid>
      <dc:creator>huy_tv</dc:creator>
      <dc:date>2021-08-11T10:22:21Z</dc:date>
    </item>
    <item>
      <title>Re: iMXRT1021 Keep RTC counter when device reboot</title>
      <link>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/iMXRT1021-Keep-RTC-counter-when-device-reboot/m-p/1322404#M15829</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/189707"&gt;@huy_tv&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;Do you want to reset also use RTC counter before it do the software reset?&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;If yes, I think you can save the RTC counter in some flash or specific area, then after you reset, you can copy the previous counter data and write back to your RTC related register again.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Otherwise, after reset, your code will use your own defined default counter data, and counter based on that data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Wish it helps you!&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;/P&gt;
&lt;P&gt;Kerry&lt;/P&gt;</description>
      <pubDate>Thu, 12 Aug 2021 06:25:10 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/iMXRT1021-Keep-RTC-counter-when-device-reboot/m-p/1322404#M15829</guid>
      <dc:creator>kerryzhou</dc:creator>
      <dc:date>2021-08-12T06:25:10Z</dc:date>
    </item>
    <item>
      <title>Re: iMXRT1021 Keep RTC counter when device reboot</title>
      <link>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/iMXRT1021-Keep-RTC-counter-when-device-reboot/m-p/1322540#M15841</link>
      <description>&lt;P&gt;Dear&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/60336"&gt;@kerryzhou&lt;/a&gt;&amp;nbsp;,&lt;BR /&gt;&lt;BR /&gt;Ok let me check my code, but can IMXRT hardware support stored RTC counter when device reset by software?&lt;BR /&gt;In some case, because the fault or exception, we can't save RTC counter to flash.&lt;BR /&gt;I would like RTC keep value, like other MCU (STM32...), RTC backup register, RTC counter still keep the old value before reset&lt;/P&gt;</description>
      <pubDate>Thu, 12 Aug 2021 09:20:32 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/iMXRT1021-Keep-RTC-counter-when-device-reboot/m-p/1322540#M15841</guid>
      <dc:creator>huy_tv</dc:creator>
      <dc:date>2021-08-12T09:20:32Z</dc:date>
    </item>
    <item>
      <title>Re: iMXRT1021 Keep RTC counter when device reboot</title>
      <link>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/iMXRT1021-Keep-RTC-counter-when-device-reboot/m-p/1323097#M15861</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/189707"&gt;@huy_tv&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp; You can check the SNVS_LPGPR register, that register will contains the data when you reset it, you can save your data in that register.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Wish it helps you!&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;/P&gt;
&lt;P&gt;kerry&lt;/P&gt;</description>
      <pubDate>Fri, 13 Aug 2021 08:09:34 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/iMXRT1021-Keep-RTC-counter-when-device-reboot/m-p/1323097#M15861</guid>
      <dc:creator>kerryzhou</dc:creator>
      <dc:date>2021-08-13T08:09:34Z</dc:date>
    </item>
    <item>
      <title>Re: iMXRT1021 Keep RTC counter when device reboot</title>
      <link>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/iMXRT1021-Keep-RTC-counter-when-device-reboot/m-p/1506852#M21096</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/189707"&gt;@huy_tv&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Did you find the solution for this?&lt;/P&gt;&lt;P&gt;I have the same problem (with a RT1062). Every time I reset or power up the board, the year starts from 1970.&lt;BR /&gt;&lt;BR /&gt;My RTC init code is basically the same as yours&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;void RTC_init(void)
{
	snvs_hp_rtc_config_t snvsRtcConfig;
	snvs_hp_rtc_datetime_t rtcDate;

	SNVS_HP_RTC_GetDefaultConfig(&amp;amp;snvsRtcConfig);
	SNVS_HP_RTC_Init(SNVS, &amp;amp;snvsRtcConfig);
	SNVS_HP_RTC_StartTimer(SNVS);
	SNVS_HP_RTC_GetDatetime(SNVS, &amp;amp;rtcDate);

	print_log(LOG_WARN, "RTC:\tStart OK\n");

	if(rtcDate.year == 1970)
	{
		rtcDate.year = 2022;
		rtcDate.month = 8;
		rtcDate.day = 2;
		rtcDate.hour = 16;
		rtcDate.minute = 0;
		rtcDate.second = 0;

		SNVS_HP_RTC_SetDatetime(SNVS, &amp;amp;rtcDate);

		print_log(LOG_ERROR, "RTC:\tReset Time\n");
	}
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Aug 2022 13:48:27 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/iMXRT1021-Keep-RTC-counter-when-device-reboot/m-p/1506852#M21096</guid>
      <dc:creator>microcris</dc:creator>
      <dc:date>2022-08-16T13:48:27Z</dc:date>
    </item>
    <item>
      <title>Re: iMXRT1021 Keep RTC counter when device reboot</title>
      <link>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/iMXRT1021-Keep-RTC-counter-when-device-reboot/m-p/1507127#M21106</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/141639"&gt;@microcris&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp; If you have any issues, please create your own question post, then we can help you in your own question post directly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; You can test it based on the newest SDK 2.12.0, thanks.&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;/P&gt;
&lt;P&gt;kerry&lt;/P&gt;</description>
      <pubDate>Wed, 17 Aug 2022 02:12:00 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/iMXRT1021-Keep-RTC-counter-when-device-reboot/m-p/1507127#M21106</guid>
      <dc:creator>kerryzhou</dc:creator>
      <dc:date>2022-08-17T02:12:00Z</dc:date>
    </item>
  </channel>
</rss>

