<?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 retention failure</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/85770/ram-retention-failure</link><description>Hello 
 I am trying to figure out the ram retention on my nRF52-DK using SES and SDK v17.1.0. I&amp;#39;ve run through the example ram_retention , and studied a topic in Nordic&amp;#39;s documentation, as well as a couple of threads here in DevZone, like this one , and</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 16 Mar 2022 11:32:26 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/85770/ram-retention-failure" /><item><title>RE: RAM retention failure</title><link>https://devzone.nordicsemi.com/thread/358390?ContentTypeID=1</link><pubDate>Wed, 16 Mar 2022 11:32:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d1ff6f31-5d1a-4d5d-af08-4f6f76e191f6</guid><dc:creator>Pero Krivic</dc:creator><description>&lt;p&gt;Awesome! Thanks Vidar!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RAM retention failure</title><link>https://devzone.nordicsemi.com/thread/358388?ContentTypeID=1</link><pubDate>Wed, 16 Mar 2022 11:28:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:27caef9a-a47d-49b1-8382-3d3e9cd21b25</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;The linker starts with the first sections and sequentially works its way up one section at a time. So the start address of a section is usually dependent on the size of previous sections. You may, for instance, notice that .non_init gets shifted up when you add more static zero initialized variables in your code (placed in .bss)&lt;/p&gt;
&lt;p&gt;SES generates the actual linker script from the flash_placement.xml file. The generated linker script can be found together with the other output files.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RAM retention failure</title><link>https://devzone.nordicsemi.com/thread/358381?ContentTypeID=1</link><pubDate>Wed, 16 Mar 2022 11:14:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ad98e653-456c-47d5-877d-d51a76addf36</guid><dc:creator>Pero Krivic</dc:creator><description>&lt;p&gt;Cool. One last question: in short words, how does the compiler (linker?) determine the addresses of all those sections? I always though it was pregiven in the .ld file (though I never bothered to look it up there)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RAM retention failure</title><link>https://devzone.nordicsemi.com/thread/358378?ContentTypeID=1</link><pubDate>Wed, 16 Mar 2022 11:08:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a0e4f125-2d8b-4ca5-bacb-9cbf53d0a772</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Yes, you can specify a fixed start address for the non_init section in your flash_placemecement.xml file.&lt;/p&gt;
&lt;p&gt;e.g.&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1647428568138v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;Note that this fixed address must be somewhere between .tbss and &amp;nbsp; .heap (or .stack if you don&amp;#39;t use heap).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RAM retention failure</title><link>https://devzone.nordicsemi.com/thread/358340?ContentTypeID=1</link><pubDate>Wed, 16 Mar 2022 08:07:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2dadc709-be7e-48c0-9971-eca5ea79c27d</guid><dc:creator>Pero Krivic</dc:creator><description>[quote userid="4240" url="~/f/nordic-q-a/85770/ram-retention-failure/358338#358338"]You can see where the .non_init section is located in RAM from the memory usage view in SES here (or from the *.map output):[/quote]
&lt;p&gt;Can you believe, I did exaxtly that last night? I found out that my variable lives at 0x20003F00, i.e in the section RAM 1. When I turned off all sections except that one, it worked just fine! How cool is that?&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Important: the .non_init section does not start at a fixed address. So it may change between builds. E.g. when you turn off or enable compiler optimization.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;span&gt;This is what I also noticed. Is there a way to fix a variable at the given section and make sure it stays there every time?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RAM retention failure</title><link>https://devzone.nordicsemi.com/thread/358338?ContentTypeID=1</link><pubDate>Wed, 16 Mar 2022 07:54:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f7f70ce4-38a6-4553-a2e9-8edeefb354ef</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Excellent &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;
[quote userid="74012" url="~/f/nordic-q-a/85770/ram-retention-failure/358294#358294"]Is that a right way to do things here? Check the variable in RAM, and turn the BLE depending on it?[/quote]
&lt;p&gt;Yes, this will work.&lt;/p&gt;
[quote userid="74012" url="~/f/nordic-q-a/85770/ram-retention-failure/358294#358294"] Can you tell me how to find out where my variable actually is, and how to pick a proper RAM region accordingly?[/quote]
&lt;p&gt;You can see where the .non_init section is located in RAM from the memory usage view in SES here (or from the *.map output): &lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1647416987786v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;And when you know the address, you can look up the which RAM slave and section it belongs to by referring to figure 1 in the &lt;span class="item"&gt;&lt;a class="" title="Memory" href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.ps.v1.1/memory.html?cp=4_2_0_7#memory"&gt;Memory&lt;/a&gt;&lt;/span&gt; chapter of the PS. Each 4K section consumes about 30 nA when retention is enabled.&lt;/p&gt;
&lt;p&gt;Important: the .non_init section does not start at a fixed address. So it may change between builds. E.g. when you turn off or enable compiler optimization.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RAM retention failure</title><link>https://devzone.nordicsemi.com/thread/358294?ContentTypeID=1</link><pubDate>Tue, 15 Mar 2022 18:54:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:245afd45-753b-4199-8d17-f46bd2cef0e8</guid><dc:creator>Pero Krivic</dc:creator><description>&lt;p&gt;Hey Vidar, this has worked out! Thanks man, you&amp;#39;re awesome!&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve taken your approach with&amp;nbsp;NRF_POWER-&amp;gt;RAM[i].POWERSET functions, since I turn SoftDevice on, only after the RAM retention is set, and only if the variable retained in RAM checks out. Is that a right way to do things here? Check the variable in RAM, and turn the BLE depending on it?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Second, I feel it&amp;#39;s kinda waste of power to turn on all of the RAM regions, since my 4-byte variable resides only in one of them. Can you tell me how to find out where my variable actually is, and how to pick a proper RAM region accordingly?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;P&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RAM retention failure</title><link>https://devzone.nordicsemi.com/thread/358121?ContentTypeID=1</link><pubDate>Tue, 15 Mar 2022 08:22:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:645b7021-cc0e-4997-b8b6-1c3fcaa12ac1</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Thanks for uploading the project. That made it easy to test here. The problem was that you used the sd_power_ram_power_set() function before the Softdevice was enabled so the function was just returning NRF_ERROR_SOFTDEVICE_NOT_ENABLED without actually configuring the power register.&lt;/p&gt;
&lt;p&gt;Peripheral view of the POWER module when running your original code:&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1647332379996v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;Notice that the retention bits are set to &amp;#39;0&amp;#39;.&lt;/p&gt;
&lt;p&gt;You can access the POWER registers directly as long as the softdevice is disabled. E.g.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;      NRF_POWER-&amp;gt;RAM[i].POWERSET = ((POWER_RAM_POWER_S0POWER_On &amp;lt;&amp;lt; POWER_RAM_POWER_S0POWER_Pos) |
                                   (POWER_RAM_POWER_S1POWER_On &amp;lt;&amp;lt; POWER_RAM_POWER_S1POWER_Pos) |
                                   (POWER_RAM_POWER_S0RETENTION_On &amp;lt;&amp;lt; POWER_RAM_POWER_S0RETENTION_Pos) |
                                   (POWER_RAM_POWER_S1RETENTION_On &amp;lt;&amp;lt; POWER_RAM_POWER_S1RETENTION_Pos));&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Vidar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RAM retention failure</title><link>https://devzone.nordicsemi.com/thread/358067?ContentTypeID=1</link><pubDate>Mon, 14 Mar 2022 19:09:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a1b89c78-306d-470a-88a6-cab3f39cb411</guid><dc:creator>Pero Krivic</dc:creator><description>&lt;p&gt;Hello Vidor, thanks for the reply. I&amp;#39;m not using the bootloader, as far as I know. I have started from&amp;nbsp;&lt;em&gt;ble_app_uart&amp;nbsp;&lt;/em&gt;and built upon it, never including any bootloader.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Hey, if it helps, I have uploaded you a complete project -&amp;nbsp; I&amp;#39;ve stripped down all functionality except ble-uart and ram retention to demonstrate the issue. It should run on PCA10040:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/MERS.zip"&gt;devzone.nordicsemi.com/.../MERS.zip&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Best, P&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RAM retention failure</title><link>https://devzone.nordicsemi.com/thread/358056?ContentTypeID=1</link><pubDate>Mon, 14 Mar 2022 17:01:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5b147d6b-6843-4370-9b98-3c41cd6e2b68</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;The RAM configuration looks to be correct. However, when the noinit section gets corrupted it usually is because there is a bootloader overwriting the section on startup. Could that be the case here? If not, I will try to set up a test tomorrow and see if I can replicate the issue on my side.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Vidar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>