<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Retain RTC during soft reset</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/11413/retain-rtc-during-soft-reset</link><description>I&amp;#39;m working on a battery powered system which needs to keep track of an absolute time stamp. So I need the RTC module and some kind of energy saving mode. As the RTC is not running in System Off I use the System On sleep mode when Idle. 
 To decrease</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 24 May 2017 12:22:15 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/11413/retain-rtc-during-soft-reset" /><item><title>RE: Retain RTC during soft reset</title><link>https://devzone.nordicsemi.com/thread/43037?ContentTypeID=1</link><pubDate>Wed, 24 May 2017 12:22:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a595ab53-98a3-45c6-af5a-c349adc2089b</guid><dc:creator>butch</dc:creator><description>&lt;p&gt;Do you need all the RAM while cpu is active?  One alternative is to leave blocks 0,1,2 disabled (power off) and modify your linker script to say there is only 8k of RAM (block3).  Then the stack would be at the top of block 3 and your variables at the bottom.  All would be valid after coming out of sleep and you wouldn&amp;#39;t need to simulate a reset.  I could be wrong?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Retain RTC during soft reset</title><link>https://devzone.nordicsemi.com/thread/43036?ContentTypeID=1</link><pubDate>Thu, 21 Jan 2016 13:39:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3815a7ab-f46b-4b0c-9925-91d20ba351e0</guid><dc:creator>John</dc:creator><description>&lt;p&gt;Note that the &amp;quot;noinit&amp;quot; sections for the non IAR examples require modification to the linker control files.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Retain RTC during soft reset</title><link>https://devzone.nordicsemi.com/thread/43035?ContentTypeID=1</link><pubDate>Thu, 21 Jan 2016 13:38:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0f5032c7-27fc-42fa-aa85-4789c20152b0</guid><dc:creator>John</dc:creator><description>&lt;p&gt;Good point on the GPREGRET size. I missed that as well. Another way of allocating a variable to a specific location is below. Blatantly stolen from Nordics bootloader example:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;    #if defined ( __CC_ARM )
static dfu_ble_peer_data_t m_peer_data __attribute__((section(&amp;quot;NoInit&amp;quot;), zero_init));            /**&amp;lt; This variable should be placed in a non initialized RAM section in order to be valid upon soft reset from application into bootloader. */
static uint16_t            m_peer_data_crc __attribute__((section(&amp;quot;NoInit&amp;quot;), zero_init));        /**&amp;lt; CRC variable to ensure the integrity of the peer data provided. */
#elif defined ( __GNUC__ )
__attribute__((section(&amp;quot;.noinit&amp;quot;))) static dfu_ble_peer_data_t m_peer_data;                      /**&amp;lt; This variable should be placed in a non initialized RAM section in order to be valid upon soft reset from application into bootloader. */
__attribute__((section(&amp;quot;.noinit&amp;quot;))) static uint16_t            m_peer_data_crc;                  /**&amp;lt; CRC variable to ensure the integrity of the peer data provided. */
#elif defined ( __ICCARM__ )
__no_init static dfu_ble_peer_data_t m_peer_data     @ 0x20003F80;                               /**&amp;lt; This variable should be placed in a non initialized RAM section in order to be valid upon soft reset from application into bootloader. */
__no_init static uint16_t            m_peer_data_crc @ 0x20003F80 + sizeof(dfu_ble_peer_data_t); /**&amp;lt; CRC variable to ensure the integrity of the peer data provided. */
#endif
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Retain RTC during soft reset</title><link>https://devzone.nordicsemi.com/thread/43034?ContentTypeID=1</link><pubDate>Thu, 21 Jan 2016 13:23:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d967f845-b551-4f41-bb55-2473137360e0</guid><dc:creator>Martijn</dc:creator><description>&lt;p&gt;&lt;code&gt;uint32_t* backupCounter = (uint32_t*)0x20003000UL; //or whatever ram address you want to use *backupCounter = NRF_RTC0-&amp;gt;COUNTER;&lt;/code&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Retain RTC during soft reset</title><link>https://devzone.nordicsemi.com/thread/43033?ContentTypeID=1</link><pubDate>Thu, 21 Jan 2016 13:18:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1faefdf2-8d47-48c1-9e8a-5e63036dd180</guid><dc:creator>braucadr</dc:creator><description>&lt;p&gt;You&amp;#39;re right, I was a bit too fast with my answer :-) My counter never reached the 8-Bit limit, so I didn&amp;#39;t notice.&lt;/p&gt;
&lt;p&gt;Concerning restoring the COUNTER value: I was assuming that GPREGRET was 32-Bit, so my idea was to  add the current RTC COUNTER value to GPREGRET before resetting. RTC would then start from zero, but to get the time I would just take the current COUNTER value plus the summed up GPREGRET value.&lt;/p&gt;
&lt;p&gt;Now that I realized that this approach doesn&amp;#39;t work, I want to use a variable in the powered-on RAM. But how to make sure a variable is placed in a certain location in RAM?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Retain RTC during soft reset</title><link>https://devzone.nordicsemi.com/thread/43032?ContentTypeID=1</link><pubDate>Thu, 21 Jan 2016 12:54:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:990a02b5-caf2-4544-aa9c-6016b09854b5</guid><dc:creator>Martijn</dc:creator><description>&lt;p&gt;but how? the GPREGRET is a 1 byte register and you can&amp;#39;t backup the COUNTER register with it. and you can&amp;#39;t restore the COUNTER value. I don&amp;#39;t get it.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Retain RTC during soft reset</title><link>https://devzone.nordicsemi.com/thread/43031?ContentTypeID=1</link><pubDate>Thu, 21 Jan 2016 07:16:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b4479a62-516c-42ba-83a6-bbc3c89fa02a</guid><dc:creator>braucadr</dc:creator><description>&lt;p&gt;Thanks for your help guys. I went for the approach with GPREGRET&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Retain RTC during soft reset</title><link>https://devzone.nordicsemi.com/thread/43030?ContentTypeID=1</link><pubDate>Thu, 21 Jan 2016 00:15:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ea904fce-140a-468f-8680-1d2b8432b605</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;stack pointer initialised, yes and no. A &amp;#39;real&amp;#39; reset takes the stack pointer from 0x00000000 and sets it before it does anything else so in that way, no it&amp;#39;s not reset by what you&amp;#39;re doing. However just about every startup assembler file I&amp;#39;ve seen ever also quite early on sets the SP to something valid explicitly. If you&amp;#39;re getting all the way into main() then it&amp;#39;s very unlikely the SP hasn&amp;#39;t been set 2 or 3 times and is valid. So you probably have a different error.&lt;/p&gt;
&lt;p&gt;Not sure that faking reset is the best way to go, it&amp;#39;s hard to cover all the bases and get the chip in the same state it was in before. As John DeWitt suggests below, how about using a retained register and properly resetting. Also, if you just write it to a location in powered-on RAM, does that work, RAM isn&amp;#39;t cleared by reset AFAIK.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Retain RTC during soft reset</title><link>https://devzone.nordicsemi.com/thread/43038?ContentTypeID=1</link><pubDate>Wed, 20 Jan 2016 16:34:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4c57baf7-9535-4c37-880a-465f0f09b479</guid><dc:creator>John</dc:creator><description>&lt;p&gt;Why not stash the RTC in the POWER-&amp;gt;GPREGRET register which is designed to survive reset prior to resetting? As long as you don&amp;#39;t need to be hyper accurate the time to reset and return to running state shouldn&amp;#39;t affect your absolute time that much.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Retain RTC during soft reset</title><link>https://devzone.nordicsemi.com/thread/43028?ContentTypeID=1</link><pubDate>Wed, 20 Jan 2016 14:59:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8130661b-a4ae-4a48-a84a-254df20d5cd3</guid><dc:creator>braucadr</dc:creator><description>&lt;p&gt;Ok, got it. I call the MBR Reset Handler with&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;typedef void resetHandler_t(void);
resetHandler_t* mbrResetHandler = (resetHandler_t*)*(uint32_t*)0x04;
mbrResetHandler();
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It seems to work as it runs thru the application Reset Handler after a while. But again, the first call of &lt;code&gt;sd_nvic_critical_region_enter(0)&lt;/code&gt; fails, this time with a hard fault error.&lt;/p&gt;
&lt;p&gt;I&amp;#39;m still confused with the stack pointer. Is it properly initialized without an actual reset?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Retain RTC during soft reset</title><link>https://devzone.nordicsemi.com/thread/43027?ContentTypeID=1</link><pubDate>Wed, 20 Jan 2016 11:11:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8b9819b4-97d2-49da-9c2a-6a557e72c035</guid><dc:creator>Martijn</dc:creator><description>&lt;p&gt;The cortex-m0 core only uses the vector table placed at address 0x0. but there a multiple vector tables when you use a softdevice. The MBR has a vector table @ address 0x0. The softdevice has a vector table right after the MBR and the application has  a vector table right after the softdevice. The MBR simply looks through the vector tables of the softdevice and application and jumps to the correct address.&lt;/p&gt;
&lt;p&gt;When you call Reset_Handler() in you application you jump the Reset_Handler in you application space and skip the MBR version and softdevice version.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Retain RTC during soft reset</title><link>https://devzone.nordicsemi.com/thread/43026?ContentTypeID=1</link><pubDate>Wed, 20 Jan 2016 10:35:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d878cd65-fb95-456a-8503-cc603983285c</guid><dc:creator>braucadr</dc:creator><description>&lt;p&gt;In startup_nrf51x.c I have:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;void * g_pfnVectors[0x30] __attribute__ ((section (&amp;quot;.isr_vector&amp;quot;))) = 
{
	&amp;amp;_estack,
	&amp;amp;Reset_Handler,
	&amp;amp;NMI_Handler,
	&amp;amp;HardFault_Handler,
	NULL,
	NULL,
	...,
...
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Doesn&amp;#39;t this mean that &lt;em&gt;reset_handler address of the MBR(located at address 0x4)&lt;/em&gt; is exactly what I call with Reset_Handler()?
I think the isr_vector is placed at address 0x00 with alignment 0x04 as described in the &lt;a href="http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0497a/BABIFJFG.html"&gt;Cortex M0 Manual&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t see the Stack being initialized. Do I maybe also have to reset the SP manually as it is normally done by the reset?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Retain RTC during soft reset</title><link>https://devzone.nordicsemi.com/thread/43025?ContentTypeID=1</link><pubDate>Wed, 20 Jan 2016 08:47:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a46cc8af-4d44-46e8-b755-713100e56592</guid><dc:creator>Martijn</dc:creator><description>&lt;p&gt;Ah, you call the reset handler of you application, which calls the reset handler of the application  and resets the ram content of the application.&lt;/p&gt;
&lt;p&gt;But it skips the reset_handler of the mbr and softdevice, so the softdevice ram content is still corrupted. I don&amp;#39;t know whether this is possible, but maybe you can set the Reset_Handler pending via NVIC? or maybe you can get the reset_handler address of the MBR(located at address 0x4) and call that so the full chain of MBR -&amp;gt; softdevice -&amp;gt; application reset handlers is called without a reset.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Retain RTC during soft reset</title><link>https://devzone.nordicsemi.com/thread/43024?ContentTypeID=1</link><pubDate>Wed, 20 Jan 2016 08:40:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6289a0fd-c49f-4167-80c8-a99d3ec69e28</guid><dc:creator>braucadr</dc:creator><description>&lt;p&gt;Hi Martijn, thanks for your comment. I replaced NVIC_SystemReset() with Reset_Handler() and it basically works. But the first call of sd_nvic_critical_region_enter(0) after the &amp;quot;reset&amp;quot; crashes with the SIGTRAP signal. Could it be that the SVC_Handler is somehow corrupted after the Reset_Handler() call?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Retain RTC during soft reset</title><link>https://devzone.nordicsemi.com/thread/43029?ContentTypeID=1</link><pubDate>Tue, 19 Jan 2016 20:49:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8fc73e26-63d6-4b1b-87a6-163d0423a0cc</guid><dc:creator>Martijn</dc:creator><description>&lt;p&gt;I think you don&amp;#39;t need a reset, but you need the behavior of the reset handler.
I think you can just call it right after you enabled the ram again. This will reinitialise the ram content, but keep the rtc running.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>