<?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>Writing variable in RAM after programming</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/8818/writing-variable-in-ram-after-programming</link><description>Hello, 
 i want to write a global unsigned long variable in RAM after programming the device. The Use-Case is to set the clock value to the actual time. So the new unsigned long value will be generated from the host PC from the actual time. This new</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 03 Sep 2015 07:30:26 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/8818/writing-variable-in-ram-after-programming" /><item><title>RE: Writing variable in RAM after programming</title><link>https://devzone.nordicsemi.com/thread/32371?ContentTypeID=1</link><pubDate>Thu, 03 Sep 2015 07:30:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b2583ff9-f295-4f7f-ba76-ba9ca3557212</guid><dc:creator>RK</dc:creator><description>&lt;pre&gt;&lt;code&gt;J-Link&amp;gt;halt
PC = 0001D5C6, CycleCnt = A86EB1D0  
R0 = FFFFFFFF, R1 = FFFFFFFF, R2 = 00000003, R3 = 0001F000
R4 = FFFFFFFF, R5 = 00000000, R6 = 00000000, R7 = 00000000
R8 = 00000000, R9 = 00000000, R10= 00000000, R11= 00000000
R12= 00000000
SP(R13)= 200021F0, MSP= 200021F0, PSP= 00000000, R14(LR) = FFFFFFFF
XPSR = 61000000: APSR = nZCvq, EPSR = 01000000, IPSR = 000 (NoException)
CFBP = 00000000, CONTROL = 00, FAULTMASK = 00, BASEPRI = 00, PRIMASK = 00
FPU regs: FPU not enabled / not implemented on connected CPU.
J-Link&amp;gt;mem32 0x20000000, 1
20000000 = 00003000 
J-Link&amp;gt;mem32 0x20002990, 1
20002990 = 772CCFFD 
J-Link&amp;gt;w4 0x20002990, 0x12345678
Writing 12345678 -&amp;gt; 20002990
J-Link&amp;gt;mem32 0x20002990, 1
20002990 = 12345678 
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;that happens to be an NRF52 board because it was on the table, but it works fine as you can see&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Writing variable in RAM after programming</title><link>https://devzone.nordicsemi.com/thread/32374?ContentTypeID=1</link><pubDate>Thu, 03 Sep 2015 07:29:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f346d282-1387-430d-a02c-6a744af0bc1b</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;removed and turned into an answer as comments don&amp;#39;t format properly&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Writing variable in RAM after programming</title><link>https://devzone.nordicsemi.com/thread/32373?ContentTypeID=1</link><pubDate>Thu, 03 Sep 2015 07:14:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:64aac5cb-7caa-4cb1-8651-cd822732486b</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;works perfectly for me - no unlocking needed, it&amp;#39;s RAM. As long as the processor is halted, it writes to the memory.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Writing variable in RAM after programming</title><link>https://devzone.nordicsemi.com/thread/32372?ContentTypeID=1</link><pubDate>Thu, 03 Sep 2015 06:46:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2554919e-7c9f-4ff4-93d9-f1a9dc3c04e9</guid><dc:creator>Andreas</dc:creator><description>&lt;p&gt;Good moorning, now I tried the JLink Commander.
First I did&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;h
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;then I did&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;w4 0x20002990, 0x55E7EAF0
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;But when I read back the memory, I get:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;mem32 0x20002990, 1: 20002992 = 00000000
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I expected to get 55E7EAF0, when I read back the memory!?
Also in my application, it seems that the memory doesn`t have the right value... Any ideas? Do I have to unlock the memory in any way?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Writing variable in RAM after programming</title><link>https://devzone.nordicsemi.com/thread/32370?ContentTypeID=1</link><pubDate>Wed, 02 Sep 2015 06:59:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:333d32ff-3bec-4487-87ed-5e4923856fca</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;I just tried it - if you connect via JLink and&lt;/p&gt;
&lt;p&gt;halt, reset, write the memory, then go .. it works.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Writing variable in RAM after programming</title><link>https://devzone.nordicsemi.com/thread/32369?ContentTypeID=1</link><pubDate>Wed, 02 Sep 2015 06:55:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2c1fba60-2384-4ae6-9478-c31f9a4a2f75</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;yes you can use JLink from the command line - you&amp;#39;ll use something (from memory) like&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;h 
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;to halt&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;w4 &amp;lt;addr&amp;gt;, value
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;then&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;go
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;to restart - however if you&amp;#39;ve stopped when the softdevice is running and advertising, it&amp;#39;s not going to work.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Writing variable in RAM after programming</title><link>https://devzone.nordicsemi.com/thread/32368?ContentTypeID=1</link><pubDate>Wed, 02 Sep 2015 06:53:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:24c84a9e-fb9e-4ecc-a908-b260cc2c63e8</guid><dc:creator>Andreas</dc:creator><description>&lt;p&gt;Thanks for the correction ;-)
It is a known issue, that we will lose the value in real life after a reset. But normally there should be no reset. And the device will work correctly after a reset. Only one default value won`t be set.
Can I use JLink from the command line?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Writing variable in RAM after programming</title><link>https://devzone.nordicsemi.com/thread/32367?ContentTypeID=1</link><pubDate>Wed, 02 Sep 2015 06:41:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f76aca9f-757c-4207-afcd-07dfcc6a1b5f</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;lose, not loose.&lt;/p&gt;
&lt;p&gt;I have no idea how nrfjprog works. I&amp;#39;d use JLink myself to do the same thing.&lt;/p&gt;
&lt;p&gt;However, if you&amp;#39;ve started the softdevice and are doing anything, even advertising, it&amp;#39;s not going to work because halting the chip is going to cause the softdevice to assert when you start it up again, thus needing a reset. Are you doing something like that?&lt;/p&gt;
&lt;p&gt;And how is this supposed to work in real life if the chip resets, at that point you will again lose all the data and have to connect it back up a PC to reload the value.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Writing variable in RAM after programming</title><link>https://devzone.nordicsemi.com/thread/32366?ContentTypeID=1</link><pubDate>Wed, 02 Sep 2015 06:27:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cb3da2fc-f815-415c-9d09-6da24babebc7</guid><dc:creator>Andreas</dc:creator><description>&lt;p&gt;Hello RK,
thanks for that hint. It helped a lot. So I tried following workflow: 1. nrfjprog.exe --e 2. nrfjprog.exe --program Firmware.hex 3. nrfjprog.exe --ramwr 0x20002990 --val 0x86A1FDC 4. nrfjprog.exe --run.
But the program execution doesn`t start. I have to do nrfjprog.exe --reset to start the execution. But then I will lose my RAM value...? Do I have to set the pc and sp value when doing nrfjprog.exe --run?&lt;/p&gt;
&lt;p&gt;Thanks, regards, BTprogrammer&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Writing variable in RAM after programming</title><link>https://devzone.nordicsemi.com/thread/32365?ContentTypeID=1</link><pubDate>Wed, 02 Sep 2015 00:44:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fde4172e-d4fb-4432-8c8a-1c97ef7e4414</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;If you want to find the address of the variable you can&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;look in the map file&lt;/li&gt;
&lt;li&gt;use objdump on the elf file&lt;/li&gt;
&lt;li&gt;use nm on the elf file&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;remember to include debug information (although the map file will tell you either way)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Writing variable in RAM after programming</title><link>https://devzone.nordicsemi.com/thread/32363?ContentTypeID=1</link><pubDate>Tue, 01 Sep 2015 13:00:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:170f83b3-4654-4889-ab9d-231c936bed62</guid><dc:creator>Stefan Birnir Sverrisson</dc:creator><description>&lt;p&gt;Perhaps &lt;a href="http://www.keil.com/support/docs/2829.htm"&gt;this&lt;/a&gt; is what you are asking for.  There is an example of using this in e.g. dfu_types.h file in the SDK under \nRF51_SDK_9.0.0_2e23562\components\libraries\bootloader_dfu\&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Writing variable in RAM after programming</title><link>https://devzone.nordicsemi.com/thread/32364?ContentTypeID=1</link><pubDate>Tue, 01 Sep 2015 11:29:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a44ec33a-cec8-45d5-a0a1-4747662dc645</guid><dc:creator>Andreas</dc:creator><description>&lt;p&gt;Hello Stefan, thanks for the update. The idea is, that the address of a global variable won&lt;code&gt;t change. We use this in other µControllers with GDB. But I&lt;/code&gt;m not able to get the address of the variable. Do you have any idea regarding that problem?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Writing variable in RAM after programming</title><link>https://devzone.nordicsemi.com/thread/32362?ContentTypeID=1</link><pubDate>Tue, 01 Sep 2015 07:04:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:81131c50-13e9-45ac-870f-bd1f3f6baae1</guid><dc:creator>Andreas</dc:creator><description>&lt;p&gt;Hello Stefan, thank you for your answer and sorry for my late reply. As I mentioned, I want to use the --ramwr option to manipulate one of my global application variables. So the workflow will be: 1. Put the CPU into halt state . 2. Manipulate the specific RAM value. 3. Let the CPU run. Am I right!?&lt;/p&gt;
&lt;p&gt;Another question, how can I get the RAM address of the global variable!? printf(&amp;quot;address: %p&amp;quot;, variable); didnt`t work.
Regards, BTprogrammer&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Writing variable in RAM after programming</title><link>https://devzone.nordicsemi.com/thread/32361?ContentTypeID=1</link><pubDate>Fri, 21 Aug 2015 16:07:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:477a9365-27af-4ab9-8123-10cfeb37e0cd</guid><dc:creator>Stefan Birnir Sverrisson</dc:creator><description>&lt;p&gt;Hi BTprogrammer&lt;/p&gt;
&lt;p&gt;You can write to RAM with using e.g.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;nrfjprog --ramwr 20007050  --val 0x12345678
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and read back the memory content with e.g.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;nrfjprog --memrd 20007000  --n 256
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Just make sure the application will not use the same RAM space, as it might overwrite your written value. &lt;a href="https://devzone.nordicsemi.com/question/21787/available-ram-for-the-application/"&gt;Here is a thread&lt;/a&gt; that contains information about how the RAM space is constructed. &lt;a href="https://devzone.nordicsemi.com/question/28726/how-to-execute-code-from-ram-on-nrf51/"&gt;This thread&lt;/a&gt; contains some info on how to configure the ROM and RAM space of the application in Keil. If you have e.g. the nRF51 QFAC chip with 32kB of RAM (the chip residing on nRF51-DK and nRF51-dongle development kits) then you can make the application use space from e.g. 0x20000000 to 0x20007000 and then you will have RAM memory space 0x20007000 to 20008000 untouched by the application.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Update 1.9.2015&lt;/strong&gt;
&lt;a href="https://devzone.nordicsemi.com/question/28726/how-to-execute-code-from-ram-on-nrf51/"&gt;This thread&lt;/a&gt; contains only how to divide the RAM into sections. Right now, I am not sure how you would put a variable into a specific RAM location. It may be possible, perhaps others can step in and share their knowledge on that.&lt;/p&gt;
&lt;p&gt;Another option would be to use one of the onboard peripherals, like the UART, to write to A variable (in RAM or flash). You could have the UART hardwired to the PC or you could use virtual UART and transmit the value wirelessly over BLE if you have a BLE enabled PC. For that purpose, use the NUS service (Nordic UART Service over BLE) to transmit data over a BLE link. &lt;a href="http://infocenter.nordicsemi.com/index.jsp"&gt;This example&lt;/a&gt; in &lt;a href="http://developer.nordicsemi.com/nRF51_SDK/nRF51_SDK_v9.x.x/"&gt;nRF51 SDK 9.0.0&lt;/a&gt; implements both the actual UART to communicate with PC and the BLE UART (NUS service)&lt;/p&gt;
&lt;p&gt;You could also use pstorage RAW mode (when BLE softdevice enebled) or NVMC (no softdevice enabled) to write directly to an address in flash memory from you program, and also write to the same address with nrfjprog --memwr command from PC.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>