<?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>RAM state after power on reset</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/99256/ram-state-after-power-on-reset</link><description>Hello, I&amp;#39;m facing an issue with the behavior of the RAM state in the NRF52840 after a brownout reset. Context: I&amp;#39;ve implemented a simple bootloop detection where a boot counter is incremented at the very beginning of each boot and cleared to 0 once our</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 08 May 2023 07:33:26 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/99256/ram-state-after-power-on-reset" /><item><title>RE: RAM state after power on reset</title><link>https://devzone.nordicsemi.com/thread/424155?ContentTypeID=1</link><pubDate>Mon, 08 May 2023 07:33:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:23409bd8-66c6-4ec7-87a4-3a4ee265f160</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;No worries, good to know we are on the same page &lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f642.svg" title="Slight smile"&gt;&amp;#x1f642;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RAM state after power on reset</title><link>https://devzone.nordicsemi.com/thread/424015?ContentTypeID=1</link><pubDate>Fri, 05 May 2023 13:25:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ef08369d-f49f-40ae-97b1-fd73104107d6</guid><dc:creator>joel-sc</dc:creator><description>&lt;p&gt;Oops, I apologize for the confusion. I mixed up my words when posting.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RAM state after power on reset</title><link>https://devzone.nordicsemi.com/thread/423995?ContentTypeID=1</link><pubDate>Fri, 05 May 2023 12:39:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:97c9a4b9-ddc2-4f8d-8184-7d888546a47f</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi Joël&lt;/p&gt;
[quote user="joel-sc"]I&amp;#39;ll then consider my &amp;quot;noinit&amp;quot; region invalid if the reset cause is either cpu lock up or soft reset-[/quote]
&lt;p&gt;Maybe it&amp;#39;s too late on a Friday and my mind is drifting, but shouldn&amp;#39;t your region be invalid &lt;strong&gt;&lt;em&gt;unless&lt;/em&gt; &lt;/strong&gt;the reset cause is CPU lock up or soft reset?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;A good day and a great weekend to you too &lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f642.svg" title="Slight smile"&gt;&amp;#x1f642;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RAM state after power on reset</title><link>https://devzone.nordicsemi.com/thread/423897?ContentTypeID=1</link><pubDate>Fri, 05 May 2023 07:07:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:33d735ed-08d9-45b8-92e4-a9d56b0918c0</guid><dc:creator>joel-sc</dc:creator><description>&lt;p&gt;Hi Torbj&amp;oslash;rn&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thank you! I think you have answered my questions.&lt;/p&gt;
&lt;p&gt;&lt;span style="text-decoration:line-through;"&gt;I&amp;#39;ll then consider my &amp;quot;noinit&amp;quot; region invalid if the reset cause is either cpu lock up or soft reset-&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;EDIT: I&amp;#39;ll consider the noinit region only valid if the reset is coming from a soft reset or cpu lockup.&lt;/p&gt;
&lt;p&gt;I wish you a good day!&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Jo&amp;euml;l&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RAM state after power on reset</title><link>https://devzone.nordicsemi.com/thread/423703?ContentTypeID=1</link><pubDate>Thu, 04 May 2023 08:41:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ccccbfd7-8b55-4820-8545-f07d9b7e9f31</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi Joël&lt;/p&gt;
[quote user="joel-sc"]Okay but I&amp;#39;m wondering more about the RAM peripheral itself, like I assume that the RAM peripheral is not composed only by cells but also by logic gate, memory controller, adc maybe... I don&amp;#39;t know.[/quote]
&lt;p&gt;The various support circuitry will be in a know state after a reset, yes, such as the ABH bus and memory controllers. Just not the memory content itself. I am not a hardware designer, but I assume that designing a RAM that could be fully reset would increase either the cost or the power consumption, or both.&amp;nbsp;&lt;/p&gt;
[quote user="joel-sc"]Is there any specification regarding the power down an up sequence in term of voltage and timing ?[/quote]
&lt;p&gt;Not really. The power on reset functionality ensures that the device is not powered up until a stable supply is available.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;We do have some specifications regarding how the rise time of the supply affects the device startup time, which you can find &lt;a href="https://infocenter.nordicsemi.com/topic/ps_nrf52840/power.html?cp=5_0_0_4_2_7_2#unique_1752780615"&gt;here&lt;/a&gt;. Essentially a slow rise on VDD will increase the time the device is kept in reset by the power on reset circuitry.&amp;nbsp;&lt;/p&gt;
[quote user="joel-sc"]Can I assume that at the beginning of the reset handler, the whole CPU is in a sane and valid state, this is true _every_ time ?[/quote]
&lt;p&gt;Yes. This is the responsibility of the power on reset functionality, and the overall reset feature of the various peripherals and system blocks, to make sure that your device doesn&amp;#39;t start until it has a stable supply, and that all peripherals are reset to a known state when the CPU starts running.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RAM state after power on reset</title><link>https://devzone.nordicsemi.com/thread/423483?ContentTypeID=1</link><pubDate>Wed, 03 May 2023 09:41:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d958d8ea-43ee-4579-88b2-7a4bedf87489</guid><dc:creator>joel-sc</dc:creator><description>&lt;p&gt;Hello Ovrebekk&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
[quote userid="2116" url="~/f/nordic-q-a/99256/ram-state-after-power-on-reset/423453"]The RAM state is unspecified at boot unfortunately. This is why by default all used RAM will be explicitly zero initialized during boot (except for noinit RAM, or data RAM that must be assigned some value other than 0).&amp;nbsp;[/quote]
&lt;p&gt;Okay but I&amp;#39;m wondering more about the RAM peripheral itself, like I assume that the RAM peripheral is not composed only by cells but also by logic gate, memory controller, adc maybe... I don&amp;#39;t know.&lt;/p&gt;
&lt;p&gt;Anyway, maybe I could rephrase&amp;nbsp; and generalize my question:&lt;/p&gt;
&lt;p&gt;Is there any specification regarding the power down an up sequence in term of voltage and timing ?&lt;br /&gt;Can I assume that at the beginning of the reset handler, the whole CPU is in a sane and valid state, this is true _every_ time ?&lt;/p&gt;
[quote userid="2116" url="~/f/nordic-q-a/99256/ram-state-after-power-on-reset/423453"]Like you indicate I think you will need to use the &lt;a href="https://infocenter.nordicsemi.com/topic/ps_nrf52840/power.html?cp=5_0_0_4_2_6_10#register.RESETREAS"&gt;RESETREAS register&lt;/a&gt; to figure out what was the cause of the last reset, and set the boot counter accordingly. I am assuming the reset reason in the cause of a lockup would be either CPU lockup or soft reset[/quote]
&lt;p&gt;Thank you, I&amp;#39;m indeed already using this to know the reset reason at boot.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thank you very much for your time&lt;/p&gt;
&lt;p&gt;Jo&amp;euml;l&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RAM state after power on reset</title><link>https://devzone.nordicsemi.com/thread/423453?ContentTypeID=1</link><pubDate>Wed, 03 May 2023 07:54:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ae7bee7f-17ce-4691-b4f6-13445e080db6</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi Joël&lt;/p&gt;
&lt;p&gt;The RAM state is unspecified at boot unfortunately. This is why by default all used RAM will be explicitly zero initialized during boot (except for noinit RAM, or data RAM that must be assigned some value other than 0).&amp;nbsp;&lt;/p&gt;
&lt;p&gt;A reset doesn&amp;#39;t reset the RAM either, but the content might be corrupted because of power loss. The &lt;a href="https://www.nordicsemi.com/Products/Development-software/nRF5-SDK/Download?lang=en#infotabs"&gt;reset behavior table&lt;/a&gt; has a bit more information about this.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The only resets that should leave the RAM alone is CPU lockup reset and soft reset, as shown in the table.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Like you indicate I think you will need to use the &lt;a href="https://infocenter.nordicsemi.com/topic/ps_nrf52840/power.html?cp=5_0_0_4_2_6_10#register.RESETREAS"&gt;RESETREAS register&lt;/a&gt; to figure out what was the cause of the last reset, and set the boot counter accordingly. I am assuming the reset reason in the cause of a lockup would be either CPU lockup or soft reset.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Hopefully that answered all your questions?&amp;nbsp;&amp;nbsp;&lt;br /&gt;If not please let me know, and I will get back to you.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RAM state after power on reset</title><link>https://devzone.nordicsemi.com/thread/423296?ContentTypeID=1</link><pubDate>Tue, 02 May 2023 12:38:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cb3fb4db-0db9-40b6-a0e9-159747042fdc</guid><dc:creator>joel-sc</dc:creator><description>&lt;p&gt;Hi!&lt;/p&gt;
&lt;p&gt;Let me show you the pseudo code of the idea.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;
// NOINIT object won&amp;#39;t be reinitialized during the reset handler
#define NOINIT __attribute__((section(&amp;quot;.noinit&amp;quot;))) volatile

static NOINIT boot_counter = 0;
int main() {

 	boot_counter++; 
	if (boot_counter &amp;gt; 15) {
		// clear the boot counter
		boot_counter = 0;

		// prepare to enter into the dfu
		do_some_stuf();

		// jump into the bootloader and wait for dfu
		nrf_pwr_mgmt_shutdown(NRF_PWR_MGMT_SHUTDOWN_GOTO_DFU);
	}

	// bsp, peripheral, BLE initialization...
	fw_init();

	// From now the firmware is available by BLE, it is considered as safe and reachabl

	// clear the boot counter
	boot_counter = 0;

	// application running forever
	app_run();
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The idea is to protect the boot and initialization sequence until the boot counter is cleared. With this code, there are three ways to clear the boot counter:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;The boot counter has reached the maximum (15) and is cleared before going into the bootloader from the application.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;fw_init()&lt;/code&gt; has passed, and the device is available by BLE and considered reachable by BLE.&lt;/li&gt;
&lt;li&gt;Power off and on the device.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;During the design process, I assumed that sufficient power loss that causes a brownout reset would clear the content of the memory, and thus the boot counter would be 0 at boot. Now I am facing this issue I am not sure about this assumption anymore. My main problem is not the behavior of the anti-brick system, but the validity of the RAM state after a power up if there is a short power outage (a few milliseconds in my last measurement). The anti-brick system just exposed the issue. To fix this, I could simply clear the boot counter if the reset cause is coming from a brownout, but that is not my question.&lt;/p&gt;
&lt;p&gt;My questions are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;How is the RAM initialized after power on or reset (before going into the reset handler)?&lt;/li&gt;
&lt;li&gt;What is the state of the RAM after reset, and is it specified?&lt;/li&gt;
&lt;li&gt;What is the state of the RAM after power off and on, and is it specified?&lt;/li&gt;
&lt;li&gt;Is there any timing constraint for clearing the RAM content after power loss?&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Thank you for your time!&lt;/p&gt;
&lt;p&gt;Jo&amp;euml;l&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RAM state after power on reset</title><link>https://devzone.nordicsemi.com/thread/423251?ContentTypeID=1</link><pubDate>Tue, 02 May 2023 11:05:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8ba74332-d11c-4e69-a6bf-f6ace31917f3</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi Joël&lt;/p&gt;
&lt;p&gt;I am not quite sure I understand the problem.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If a power failure is causing a brownout reset, then it is hard to say how that will impact the status of the RAM.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If the boot counter is not reset, but kept to the last value, wouldn&amp;#39;t that allow the anti-brick system to continue?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Are you worried that you will get false positives, where the anti-brick system will boot into the bootloader even if the firmware is technically functional?&lt;/p&gt;
&lt;p&gt;I assume the power failure must happen during the boot sequence for this to be a problem?&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>