<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Kinetis Microcontrollers中的主题 Re: Hard Faults reading program Flash memory</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Hard-Faults-reading-program-Flash-memory/m-p/548773#M33441</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ok.&amp;nbsp; So why would creating a pointer to a memory location and reading consecutive Flash values generate a hard fault?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 22 Aug 2016 20:48:20 GMT</pubDate>
    <dc:creator>ryanmonfils</dc:creator>
    <dc:date>2016-08-22T20:48:20Z</dc:date>
    <item>
      <title>Hard Faults reading program Flash memory</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Hard-Faults-reading-program-Flash-memory/m-p/548771#M33439</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;BR /&gt;I have custom firmware consisting of a Bootloader and application on the Kinetis K22FN1M0VLL12.&amp;nbsp; My Bootloader goes through the following sequence.&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1) Send a command to erase enough Flash to program the new application.&lt;/P&gt;&lt;P&gt;2) Send the application in packets via the UART.&amp;nbsp; Write each packet into Flash as it comes in.&lt;/P&gt;&lt;P&gt;3) Reboot&lt;/P&gt;&lt;P&gt;4) Compute a CRC over the entire application in Flash and compare against a pre-calculated value.&lt;/P&gt;&lt;P&gt;5) If the CRCs match, jump to the application.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I don't believe I'm doing anything unusual.&amp;nbsp; I've been testing with corrupt application images to ensure that the system recovers properly and have discovered an issue.&amp;nbsp; Sometimes after an update while looping through the CRC calculation, I will jump into a Hard Fault.&amp;nbsp; I can't understand why this is happening and am not sure what to try next.&amp;nbsp; The Hard Fault seems to coincide with the portion of the application I corrupted but it shouldn't matter since I am just reading the Flash location.&amp;nbsp; Any suggestions?&amp;nbsp; Below is the snippet of CRC code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="c++" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_14718967394964209" data-hasrefreshed="true" data-renderedposition="430_50_798_304" jivemacro_uid="_14718967394964209" modifiedtitle="true"&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;uint16_t calulate16BitCrc (uint32_t startAddress, uint32_t length)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;{&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; volatile char* dataPtr;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: rgba(0, 0, 0, 0); font-size: 12px; font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; char newData;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; uint16_t crc;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; dataPtr = (uint8_t*)startAddress;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; crc = 0x5555;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for (int i = 0; i &amp;lt; length; i++)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; newData = *dataPtr;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; crc ^= newData;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; crc &amp;amp;= 0xFFFF;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; crc = (crc &amp;gt;&amp;gt; 15) | (crc &amp;lt;&amp;lt; 1);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dataPtr++;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return crc;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 22 Aug 2016 20:16:56 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Hard-Faults-reading-program-Flash-memory/m-p/548771#M33439</guid>
      <dc:creator>ryanmonfils</dc:creator>
      <dc:date>2016-08-22T20:16:56Z</dc:date>
    </item>
    <item>
      <title>Re: Hard Faults reading program Flash memory</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Hard-Faults-reading-program-Flash-memory/m-p/548772#M33440</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Most 'flash read errors' will generate a hard fault.&amp;nbsp; Email me if you want details.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 22 Aug 2016 20:31:15 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Hard-Faults-reading-program-Flash-memory/m-p/548772#M33440</guid>
      <dc:creator>egoodii</dc:creator>
      <dc:date>2016-08-22T20:31:15Z</dc:date>
    </item>
    <item>
      <title>Re: Hard Faults reading program Flash memory</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Hard-Faults-reading-program-Flash-memory/m-p/548773#M33441</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ok.&amp;nbsp; So why would creating a pointer to a memory location and reading consecutive Flash values generate a hard fault?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 22 Aug 2016 20:48:20 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Hard-Faults-reading-program-Flash-memory/m-p/548773#M33441</guid>
      <dc:creator>ryanmonfils</dc:creator>
      <dc:date>2016-08-22T20:48:20Z</dc:date>
    </item>
    <item>
      <title>Re: Hard Faults reading program Flash memory</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Hard-Faults-reading-program-Flash-memory/m-p/548774#M33442</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN&gt;Sorry, the details are not for a public forum.&amp;nbsp; Email me at &lt;/SPAN&gt;&lt;A class="jive-link-email-small" href="mailto:goodrich@lectronix.biz"&gt;goodrich@lectronix.biz&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There is nothing wrong with your code, the issue goes deeper than that. CFSR and/or DFSR MAY give a 'hint'.&amp;nbsp; I can tell you exactly what is going on.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 22 Aug 2016 22:58:02 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Hard-Faults-reading-program-Flash-memory/m-p/548774#M33442</guid>
      <dc:creator>egoodii</dc:creator>
      <dc:date>2016-08-22T22:58:02Z</dc:date>
    </item>
    <item>
      <title>Re: Hard Faults reading program Flash memory</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Hard-Faults-reading-program-Flash-memory/m-p/548775#M33443</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I would also recommend to read&lt;STRONG&gt; Configurable Fault Status Register&lt;/STRONG&gt; (CFSR) defined in &lt;STRONG&gt;System Control Space&lt;/STRONG&gt; (SCS-&amp;gt;CFSR) of the core registers. From this status you can get more information what could potetialy cause the hardfault. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If CM0+ usage I would expect unaligned memory access occurred during code execution.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, the same can happend on CM4 (which allow unaligned accesses) if &lt;STRONG&gt;UNALIGN_TRP&lt;/STRONG&gt; bit in &lt;STRONG&gt;Configuration and Control Register&lt;/STRONG&gt; (CCR) is set to 1. In such case when unaligned memory access occur Unaligned access UsageFault will be generated. If &lt;STRONG&gt;USGFAULTENA&lt;/STRONG&gt; in &lt;STRONG&gt;System Handler Control and State Register &lt;/STRONG&gt;(SHCSR)&lt;SPAN style="color: #000000; font-family: Verdana, Tahoma, Arial, Helvetica, sans-serif; font-size: small;"&gt; &lt;/SPAN&gt; is set to 0, then usage fault exception is disabled and hard fault is generated instead of.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;regards&lt;/P&gt;&lt;P&gt;R.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Aug 2016 06:37:35 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Hard-Faults-reading-program-Flash-memory/m-p/548775#M33443</guid>
      <dc:creator>rastislav_pavlanin</dc:creator>
      <dc:date>2016-08-23T06:37:35Z</dc:date>
    </item>
    <item>
      <title>Re: Hard Faults reading program Flash memory</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Hard-Faults-reading-program-Flash-memory/m-p/548776#M33444</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;For a little information on this 'poorly held secret', I can also refer you to:&lt;/P&gt;&lt;P&gt;&lt;A _jive_internal="true" href="https://community.nxp.com/message/439645?commentID=439645#comment-439645" title="https://community.nxp.com/message/439645?commentID=439645#comment-439645"&gt;https://community.nxp.com/message/439645?commentID=439645#comment-439645&lt;/A&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Aug 2016 15:56:13 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Hard-Faults-reading-program-Flash-memory/m-p/548776#M33444</guid>
      <dc:creator>egoodii</dc:creator>
      <dc:date>2016-08-23T15:56:13Z</dc:date>
    </item>
    <item>
      <title>Re: Hard Faults reading program Flash memory</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Hard-Faults-reading-program-Flash-memory/m-p/548777#M33445</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'll leave the flash read part to others.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your CRC looks suspicious.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A 16-bit CRC is only good for 4K minus 1 bit of data for the mathematical properties to apply.&lt;BR /&gt;The initialization &amp;nbsp;0x5555 is not one of the standard ones. &amp;nbsp;The standard ones have been selected so that the math properties do apply, so that leading and trailing zeros or ones don't cause issues.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For all but very small parts, those less than 4K a 32 bit CRC should be used.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;SPAN style="color: #242729; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; font-size: 12px;"&gt;Reversing CRC – Theory and Practice.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #242729; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; font-size: 12px;"&gt;&lt;A href="http://stigge.org/martin/pub/SAR-PR-2006-05.pdf" style="color: #2989c5;" title="http://stigge.org/martin/pub/SAR-PR-2006-05.pdf"&gt;http://stigge.org/martin/pub/SAR-PR-2006-05.pdf&lt;/A&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #242729; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; font-size: 12px;"&gt;&lt;A href="http://chrisballance.com/wp-content/uploads/2015/10/CRC-Primer.html" style="color: #2989c5;" title="http://chrisballance.com/wp-content/uploads/2015/10/CRC-Primer.html"&gt;CRC primer by Ross Williams&lt;/A&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've spent far to much time reading books on&amp;nbsp;syndrome lengths of Galois fields and such. &amp;nbsp;Just wish someone with a math background would write the CRC Handbook that says 'this one does that for data block of size X'... :-(&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Aug 2016 17:18:47 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Hard-Faults-reading-program-Flash-memory/m-p/548777#M33445</guid>
      <dc:creator>bobpaddock</dc:creator>
      <dc:date>2016-08-23T17:18:47Z</dc:date>
    </item>
    <item>
      <title>Re: Hard Faults reading program Flash memory</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Hard-Faults-reading-program-Flash-memory/m-p/548778#M33446</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;True enough in general.&amp;nbsp; However, due to the 'other features' of the flash system which are causing these hard-faults, the CRC operation is, in fact, relatively superfluous.&amp;nbsp; The chances of IT catching an error from a 'faulty-flash-read' that did NOT 'kill the loop' on such in a hard-fault is downright negligible.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Aug 2016 17:40:40 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Hard-Faults-reading-program-Flash-memory/m-p/548778#M33446</guid>
      <dc:creator>egoodii</dc:creator>
      <dc:date>2016-08-23T17:40:40Z</dc:date>
    </item>
  </channel>
</rss>

