<?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>Keil uVision 5+nRF51822+BLES110 softdevice: best way to implement a checksum at compile/build time?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/6645/keil-uvision-5-nrf51822-bles110-softdevice-best-way-to-implement-a-checksum-at-compile-build-time</link><description>Hello, I have inherited a (good) project in which the previous designer implemented a checksum using a value calculated from this: 
 char* pMemory = 0;
return crc16_ccitt(pMemory, NVS_TESTPAGE*((uint16_t)NRF_FICR-&amp;gt;CODEPAGESIZE)); 
 Her firmware compares</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 27 Apr 2015 12:30:30 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/6645/keil-uvision-5-nrf51822-bles110-softdevice-best-way-to-implement-a-checksum-at-compile-build-time" /><item><title>RE: Keil uVision 5+nRF51822+BLES110 softdevice: best way to implement a checksum at compile/build time?</title><link>https://devzone.nordicsemi.com/thread/23296?ContentTypeID=1</link><pubDate>Mon, 27 Apr 2015 12:30:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:620a396b-319b-4ed7-a653-ddf8c5d37e34</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;@riceman: Good to hear. If you are ok with the answer, could you accept the answer to close the case.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Keil uVision 5+nRF51822+BLES110 softdevice: best way to implement a checksum at compile/build time?</title><link>https://devzone.nordicsemi.com/thread/23295?ContentTypeID=1</link><pubDate>Mon, 27 Apr 2015 06:00:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:36a59da1-5e24-4423-aacb-de5a7e4baad6</guid><dc:creator>riceman0</dc:creator><description>&lt;p&gt;Thanks for the help... the self-saving checksum worked, once I debugged my logic.  I&amp;#39;m going with that solution.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Keil uVision 5+nRF51822+BLES110 softdevice: best way to implement a checksum at compile/build time?</title><link>https://devzone.nordicsemi.com/thread/23294?ContentTypeID=1</link><pubDate>Thu, 23 Apr 2015 13:37:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a5e57288-abac-4d65-a96c-30d9ee926cab</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;It depends on how you flash and reset the chip when programming. Most likely the chip got running after you flash it, before you enter debug mode. I would suggest you to debug using UART trace instead.&lt;/p&gt;
&lt;p&gt;You have to make sure CRC calculation is not include the flash area that you store CRC checksum value. You can think of writing it to UICR area. What I&amp;#39;m seeing is that you are calculating the whole flash region with NVS_TESTPAGE*((uint16_t)NRF_FICR-&amp;gt;CODEPAGESIZE) size. (except for UICR area)&lt;/p&gt;
&lt;p&gt;Running the device in debug mode should make no different with running it in normal mode in term of functionality.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Keil uVision 5+nRF51822+BLES110 softdevice: best way to implement a checksum at compile/build time?</title><link>https://devzone.nordicsemi.com/thread/23293?ContentTypeID=1</link><pubDate>Thu, 23 Apr 2015 12:44:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d01d9b1c-fa3f-445b-bae5-04002c22c702</guid><dc:creator>riceman0</dc:creator><description>&lt;p&gt;(this is a response to hungbui, in case I mis-posted... thank you)&lt;/p&gt;
&lt;p&gt;Actually thank you, I had a similar thought (just have it self-program on the first run) shortly after I hit &amp;quot;submit.&amp;quot;  :) So I tried exactly that, created a new flash storage item, and checked it for a NOTFIRSTRUN magic number, and if it is the first run, calc and set the CRC.  That doesn&amp;#39;t seem to work either though, here&amp;#39;s my experience:&lt;/p&gt;
&lt;p&gt;I never see the FIRSTRUN logic path fire... I think this must be because my firmware actually runs once or twice before I can actually get into debug mode.  Does that make sense?&lt;/p&gt;
&lt;p&gt;Second, even though NOTFIRSTRUN is &amp;quot;mysteriously&amp;quot; set, the subsequent CRC checks fail.  My theory is that this is because the CRC calculated in debug mode is different than the CRC calculated in release mode?  Does that make sense too?   Can I expect this to work in release mode then?&lt;/p&gt;
&lt;p&gt;Also I assume that the crc calculated with this&lt;/p&gt;
&lt;p&gt;crc16_ccitt(pMemory, NVS_TESTPAGE*((uint16_t)NRF_FICR-&amp;gt;CODEPAGESIZE));&lt;/p&gt;
&lt;p&gt;does NOT span flash memory accessed via API functions like&lt;/p&gt;
&lt;p&gt;ble_flash_page_write&lt;/p&gt;
&lt;p&gt;is that right?  Otherwise her logic never would have worked, she would break the CRC every time she reconfigured.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Keil uVision 5+nRF51822+BLES110 softdevice: best way to implement a checksum at compile/build time?</title><link>https://devzone.nordicsemi.com/thread/23292?ContentTypeID=1</link><pubDate>Thu, 23 Apr 2015 09:26:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f9e3085d-95bd-47b8-bd4f-63511d6fd35e</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi Riceman,&lt;/p&gt;
&lt;p&gt;Please correct me if I&amp;#39;m wrong.&lt;/p&gt;
&lt;p&gt;You want to generate a check sum and write it to flash in the factory testing process before it goes to the market. So that on normal operation when booting up it can check for flash integrity ?&lt;/p&gt;
&lt;p&gt;I am not sure why you need to read it out via Serial at ( c)and then write it back at (d), why not checking if it&amp;#39;s the first run (using a magic byte such as 0xBEEF) you calculate the crc, then write to flash the CRC. Of course the part of flash that you store the CRC should not be calculated for CRC.&lt;/p&gt;
&lt;p&gt;Alternativelly, if you don&amp;#39;t want to use the code to store the crc on flash, you can use the CRC calculating tool (crc.exe) to calculate the crc value and can use nrfjprog to write into flash on the nRF51.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>