<?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: Kinetis K10FX512 read flash hard fault</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Kinetis-K10FX512-read-flash-hard-fault/m-p/439236#M25669</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dario&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You are not respecting the phrase programming requirements fo the Flash in the K10FX512.&lt;/P&gt;&lt;P&gt;You are only allowed to write 8 byte blocks at at time (phrase) and any attempt to write to one of these phrases (8 byte blocks) that is not erased will corrupt the Flash and cause it to return a hard fault afterwards (it then requires an erase to recover).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You need to change your code to leave a long word space after the 5th long word that you have written:&lt;/P&gt;&lt;P&gt;eg:&lt;/P&gt;&lt;P&gt;0x10000004, 0x10000008, 0x1000000C, 0x10000010 and 0x10000014 + 0xffffffff&lt;/P&gt;&lt;P&gt;and then add futher data after that and it will work (or some other equivalent method).&lt;/P&gt;&lt;P&gt;The problem is that the Flash is being written as follows (assuming X is divisible by 4):&lt;/P&gt;&lt;P&gt;Phase Address X = 0x10000004, 0x10000008&lt;/P&gt;&lt;P&gt;Phase X + 1 = 0x1000000C, 0x10000010&lt;/P&gt;&lt;P&gt;Phase X + 2 = 0x10000014 + 0xffffffff&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you tried to write at long word offset 5 it was doing&lt;/P&gt;&lt;P&gt;Phase X + 2 = 0x10000014 + "changed value"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It is not allowed to write to a phrase twice (without a sector erase inbetween) and so your problem arisies.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Mark&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Kinetis: &lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="http://www.utasker.com/kinetis.html" rel="nofollow"&gt;http://www.utasker.com/kinetis.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;K60: &lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="http://www.utasker.com/kinetis/TWR-K60N512.html" rel="nofollow"&gt;http://www.utasker.com/kinetis/TWR-K60N512.html&lt;/A&gt;&lt;SPAN&gt; / &lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="http://www.utasker.com/kinetis/TWR-K60D100M.html" rel="nofollow"&gt;http://www.utasker.com/kinetis/TWR-K60D100M.html&lt;/A&gt;&lt;SPAN&gt; / &lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="http://www.utasker.com/kinetis/TWR-K60F120M.html" rel="nofollow"&gt;http://www.utasker.com/kinetis/TWR-K60F120M.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;For the complete "out-of-the-box" Kinetis experience and faster time to market&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #7ed529;"&gt;:smileyinfo: Out-of-the-box support for 46 Kinetis boards and 10 IDEs (&lt;EM&gt;460 combinations from a single code source with no porting required&lt;/EM&gt;)&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 07 Oct 2015 12:44:00 GMT</pubDate>
    <dc:creator>mjbcswitzerland</dc:creator>
    <dc:date>2015-10-07T12:44:00Z</dc:date>
    <item>
      <title>Kinetis K10FX512 read flash hard fault</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Kinetis-K10FX512-read-flash-hard-fault/m-p/439234#M25667</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello friends,&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px; padding-left: 30px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;we are working with MK10FX512VLQ12 on our custom developed board. We completed almost the firmware for the intended application, and had no problem until now.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem started while trying to implement the bootloader functionality. The bootloader FW writes some parameters in flash memory, that are used by both applications (bootloader and user). After the write is done, we check if the parameters are really in flash on the desired locations, but while accessing the flash location, the MCU goes to hard fault.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I will try to clarify all the steps that we make before the hard fault.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px; padding-left: 30px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;After reset we check a flag in memory (0x9000), that indicates if the bootloader application should be started, or should we jump to the user application. The read function looks like:&lt;/LI&gt;&lt;/UL&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class="c++" name="code"&gt;#define BL_RUN_FLAG_ADDRESS&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0x9000&amp;nbsp;&amp;nbsp; bootloader_run_flag = *((uint32_t*) BL_RUN_FLAG_ADDRESS);&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;P style="min-height: 8pt; padding: 0px; padding-left: 60px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="line-height: 1.5;"&gt;The read function returns the correct value, and is set to enter the bootloader application if no user application is present.&lt;/SPAN&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;In the bootloader application (after the PE_init) we first check if there are 5 parameters writen i memory (0x9004, 0x9008, 0x900C, 0x9010 and 0x9014), if not (and they are not at first start of the bootloader application) we write the parameters to this locations. To write this parameters we use the IntFLASH PE component from &lt;A _jive_internal="true" href="https://community.nxp.com/external-link.jspa?url=http%3A%2F%2Fmcuoneclipse.com%2F2014%2F05%2F31%2Fconfiguration-data-using-the-internal-flash-instead-of-an-external-eeprom%2F" rel="nofollow noopener noreferrer" target="_blank"&gt;Configuration Data: Using the Internal FLASH instead of an external EEPROM | MCU on Eclipse&lt;/A&gt;. Below is the code to check if the data is written, and to write the data.&lt;/LI&gt;&lt;/UL&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class="c++" name="code"&gt;if(BL_CheckMsgIDinFlash()){ &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BL_WriteMsgIDtoFlash();&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Cpu_SystemReset(); }&amp;nbsp; bool BL_CheckMsgIDinFlash(void) { &amp;nbsp; uint32_t rtrn = 0; &amp;nbsp; uint32_t i = 0;&amp;nbsp; &amp;nbsp; for (i = 0; i &amp;lt; MSGID_NR; i++) { &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (Flash_MSGID[i] != *((uint32_t*) (BL_RUN_FLAG_ADDRESS + ((i + 1) * 4)))) { &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rtrn++; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &amp;nbsp; } &amp;nbsp; return (bool) rtrn; }&amp;nbsp; bool BL_WriteMsgIDtoFlash(void) { &amp;nbsp; uint32_t i = 0; &amp;nbsp; uint32_t err = 0; &amp;nbsp; uint32_t tmp32 = 0; &amp;nbsp; uint32_t addr = 0;&amp;nbsp; &amp;nbsp; for (i = 0; i &amp;lt; MSGID_NR; i++) { &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tmp32 = Flash_MSGID[i]; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; addr = BL_RUN_FLAG_ADDRESS + (i + 1) * 4; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; err = IFsh1_SetBlockFlash((IFsh1_TDataAddress) &amp;amp;tmp32, addr, 4); // write data to specified location in flash &amp;nbsp;&amp;nbsp; } return err; }&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;When I run this part of code in debugger, the memory locations are not written correctly, at least the debugger shows it incorrectly. While single stepping trough &lt;SPAN style="font-family: 'courier new', courier;"&gt;BL_WriteMsgIDtoFlash() &lt;/SPAN&gt;i have this in my memory locations:&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px; padding-left: 30px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class="j-rte-table"&gt;&lt;TABLE border="1" class="jiveBorder" height="205" jive-data-cell="{&amp;quot;color&amp;quot;:&amp;quot;#3D3D3D&amp;quot;,&amp;quot;textAlign&amp;quot;:&amp;quot;left&amp;quot;,&amp;quot;padding&amp;quot;:&amp;quot;6&amp;quot;,&amp;quot;backgroundColor&amp;quot;:&amp;quot;transparent&amp;quot;,&amp;quot;fontFamily&amp;quot;:&amp;quot;Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif&amp;quot;,&amp;quot;verticalAlign&amp;quot;:&amp;quot;baseline&amp;quot;}" jive-data-header="{&amp;quot;color&amp;quot;:&amp;quot;#505050&amp;quot;,&amp;quot;backgroundColor&amp;quot;:&amp;quot;#F2F2F2&amp;quot;,&amp;quot;textAlign&amp;quot;:&amp;quot;left&amp;quot;,&amp;quot;padding&amp;quot;:&amp;quot;6&amp;quot;}" style="border: 1px solid #c6c6c6; width: 599px; height: 183px;"&gt;&lt;THEAD&gt;&lt;TR&gt;&lt;TH style="border:1px solid black;border: 1px solid #c6c6c6;background-color: #f2f2f2;padding: 6px;color: #505050;text-align: left;" valign="middle"&gt;&lt;STRONG&gt;Step&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="border:1px solid black;border: 1px solid #c6c6c6;background-color: #f2f2f2;padding: 6px;color: #505050;text-align: left;" valign="middle"&gt;&lt;STRONG&gt;0x9000&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="border:1px solid black;border: 1px solid #c6c6c6;padding: 6px;color: #505050;background-color: #f2f2f2;text-align: left;" valign="middle"&gt;&lt;STRONG&gt;0x9004&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="border:1px solid black;border: 1px solid #c6c6c6;padding: 6px;color: #505050;background-color: #f2f2f2;text-align: left;" valign="middle"&gt;&lt;STRONG&gt;0x9008&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="border:1px solid black;border: 1px solid #c6c6c6;padding: 6px;color: #505050;background-color: #f2f2f2;text-align: left;" valign="middle"&gt;&lt;STRONG&gt;0x900C&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="border:1px solid black;border: 1px solid #c6c6c6;padding: 6px;color: #505050;background-color: #f2f2f2;text-align: left;" valign="middle"&gt;&lt;STRONG&gt;0x9010&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="border:1px solid black;border: 1px solid #c6c6c6;padding: 6px;color: #505050;background-color: #f2f2f2;text-align: left;" valign="middle"&gt;&lt;STRONG&gt;0x9014&lt;/STRONG&gt;&lt;/TH&gt;&lt;/TR&gt;&lt;/THEAD&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD style="border:1px solid black;border: 1px solid #c6c6c6;padding: 6px;"&gt;1&lt;/TD&gt;&lt;TD style="border:1px solid black;border: 1px solid #c6c6c6;padding: 6px;"&gt;&lt;TABLE border="1" class="jiveBorder" height="294" jive-data-cell="{&amp;quot;color&amp;quot;:&amp;quot;#3D3D3D&amp;quot;,&amp;quot;textAlign&amp;quot;:&amp;quot;left&amp;quot;,&amp;quot;padding&amp;quot;:&amp;quot;6&amp;quot;,&amp;quot;backgroundColor&amp;quot;:&amp;quot;transparent&amp;quot;,&amp;quot;fontFamily&amp;quot;:&amp;quot;Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif&amp;quot;,&amp;quot;verticalAlign&amp;quot;:&amp;quot;baseline&amp;quot;}" jive-data-header="{&amp;quot;color&amp;quot;:&amp;quot;#505050&amp;quot;,&amp;quot;backgroundColor&amp;quot;:&amp;quot;#F2F2F2&amp;quot;,&amp;quot;textAlign&amp;quot;:&amp;quot;left&amp;quot;,&amp;quot;padding&amp;quot;:&amp;quot;6&amp;quot;}" style="border: 1px solid #c6c6c6;"&gt;&lt;TBODY&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;0xFFFFFFFF&lt;/TD&gt;&lt;TD style="border:1px solid black;border: 1px solid #c6c6c6;padding: 6px;"&gt;0x00000431&lt;/TD&gt;&lt;TD style="border:1px solid black;border: 1px solid #c6c6c6;padding: 6px;"&gt;0xFFFFFFFF&lt;/TD&gt;&lt;TD style="border:1px solid black;border: 1px solid #c6c6c6;padding: 6px;"&gt;0xFFFFFFFF&lt;/TD&gt;&lt;TD style="border:1px solid black;border: 1px solid #c6c6c6;padding: 6px;"&gt;0xFFFFFFFF&lt;/TD&gt;&lt;TD style="border:1px solid black;border: 1px solid #c6c6c6;padding: 6px;"&gt;0xFFFFFFFF&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="border:1px solid black;border: 1px solid #c6c6c6;padding: 6px;"&gt;2&lt;/TD&gt;&lt;TD style="border:1px solid black;border: 1px solid #c6c6c6;padding: 6px;"&gt;0xFFFFFFFF&lt;/TD&gt;&lt;TD style="border:1px solid black;border: 1px solid #c6c6c6;padding: 6px;"&gt;0x00000431&lt;/TD&gt;&lt;TD style="border:1px solid black;border: 1px solid #c6c6c6;padding: 6px;"&gt;0x00000432&lt;/TD&gt;&lt;TD style="border:1px solid black;border: 1px solid #c6c6c6;padding: 6px;"&gt;0xFFFFFFFF&lt;/TD&gt;&lt;TD style="border:1px solid black;border: 1px solid #c6c6c6;padding: 6px;"&gt;0xFFFFFFFF&lt;/TD&gt;&lt;TD style="border:1px solid black;border: 1px solid #c6c6c6;padding: 6px;"&gt;0xFFFFFFFF&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="border:1px solid black;border: 1px solid #c6c6c6;padding: 6px;"&gt;3&lt;/TD&gt;&lt;TD style="border:1px solid black;border: 1px solid #c6c6c6;padding: 6px;"&gt;0xFFFFFFFF&lt;/TD&gt;&lt;TD style="border:1px solid black;border: 1px solid #c6c6c6;padding: 6px;"&gt;0xFFFFFFFF&lt;/TD&gt;&lt;TD style="border:1px solid black;border: 1px solid #c6c6c6;padding: 6px;"&gt;0xFFFFFFFF&lt;/TD&gt;&lt;TD style="border:1px solid black;border: 1px solid #c6c6c6;padding: 6px;"&gt;0xFFFFFFFF&lt;/TD&gt;&lt;TD style="border:1px solid black;border: 1px solid #c6c6c6;padding: 6px;"&gt;0xFFFFFFFF&lt;/TD&gt;&lt;TD style="border:1px solid black;border: 1px solid #c6c6c6;padding: 6px;"&gt;0xFFFFFFFF&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="border:1px solid black;border: 1px solid #c6c6c6;padding: 6px;"&gt;4&lt;/TD&gt;&lt;TD style="border:1px solid black;border: 1px solid #c6c6c6;padding: 6px;"&gt;0xFFFFFFFF&lt;/TD&gt;&lt;TD style="border:1px solid black;border: 1px solid #c6c6c6;padding: 6px;"&gt;0xFFFFFFFF&lt;/TD&gt;&lt;TD style="border:1px solid black;border: 1px solid #c6c6c6;padding: 6px;"&gt;0xFFFFFFFF&lt;/TD&gt;&lt;TD style="border:1px solid black;border: 1px solid #c6c6c6;padding: 6px;"&gt;0xFFFFFFFF&lt;/TD&gt;&lt;TD style="border:1px solid black;border: 1px solid #c6c6c6;padding: 6px;"&gt;0x00000434&lt;/TD&gt;&lt;TD style="border:1px solid black;border: 1px solid #c6c6c6;padding: 6px;"&gt;0xFFFFFFFF&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="border:1px solid black;border: 1px solid #c6c6c6;padding: 6px;"&gt;5&lt;/TD&gt;&lt;TD style="border:1px solid black;border: 1px solid #c6c6c6;padding: 6px;"&gt;0xFFFFFFFF&lt;/TD&gt;&lt;TD style="border:1px solid black;border: 1px solid #c6c6c6;padding: 6px;"&gt;0xFFFFFFFF&lt;/TD&gt;&lt;TD style="border:1px solid black;border: 1px solid #c6c6c6;padding: 6px;"&gt;0xFFFFFFFF&lt;/TD&gt;&lt;TD style="border:1px solid black;border: 1px solid #c6c6c6;padding: 6px;"&gt;0xFFFFFFFF&lt;/TD&gt;&lt;TD style="border:1px solid black;border: 1px solid #c6c6c6;padding: 6px;"&gt;0x00000434&lt;/TD&gt;&lt;TD style="border:1px solid black;border: 1px solid #c6c6c6;padding: 6px;"&gt;0x00000435&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/DIV&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;On the third step the first two locations are erased, and at the end the two last locations are correct. &lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px; padding-left: 30px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;After that I reset the CPU and do again the whole procedure. First I check the Bootloader flag on location 0x9000, and at this point the CPU goes in the hard fault handler. &lt;/LI&gt;&lt;/UL&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class="c++" name="code"&gt;bootloader_run_flag = *((uint32_t*) BL_RUN_FLAG_ADDRESS);&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;I read the flowing values in the system registers:&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px; padding-left: 30px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class="j-rte-table"&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/DIV&gt;&lt;DIV class="j-rte-table"&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD colspan="1" style=""&gt;Register&lt;/TD&gt;&lt;TD colspan="1" style=""&gt;Value&lt;/TD&gt;&lt;TD colspan="1" style=""&gt;Location&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style=""&gt;stacked_r0&lt;/TD&gt;&lt;TD style=""&gt;0xffffffff&lt;/TD&gt;&lt;TD style=""&gt;0x1fff111c&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style=""&gt;stacked_r1&lt;/TD&gt;&lt;TD style=""&gt;0x00000000&lt;/TD&gt;&lt;TD style=""&gt;0x1fff1120&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style=""&gt;stacked_r2&lt;/TD&gt;&lt;TD style=""&gt;0x00000000&lt;/TD&gt;&lt;TD style=""&gt;0x1fff1124&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style=""&gt;stacked_r3&lt;/TD&gt;&lt;TD style=""&gt;0x00009000&lt;/TD&gt;&lt;TD style=""&gt;0x1fff1128&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style=""&gt;stacked_r12&lt;/TD&gt;&lt;TD style=""&gt;0x00000000&lt;/TD&gt;&lt;TD style=""&gt;0x1fff112c&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style=""&gt;stacked_lr&lt;/TD&gt;&lt;TD style=""&gt;0x0000371d&lt;/TD&gt;&lt;TD style=""&gt;0x1fff1130&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style=""&gt;stacked_pc&lt;/TD&gt;&lt;TD style=""&gt;&lt;STRONG style="color: #3d3d3d;"&gt;0x000036fe&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD style=""&gt;0x1fff1134&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style=""&gt;stacked_psr&lt;/TD&gt;&lt;TD style=""&gt;0x21000000&lt;/TD&gt;&lt;TD style=""&gt;0x1fff1138&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style=""&gt;_CFSR&lt;/TD&gt;&lt;TD style=""&gt;0x00008200&lt;/TD&gt;&lt;TD style=""&gt;0x1fff113c&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style=""&gt;_HFSR&lt;/TD&gt;&lt;TD style=""&gt;0x40000000&lt;/TD&gt;&lt;TD style=""&gt;0x1fff1140&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style=""&gt;_DFSR&lt;/TD&gt;&lt;TD style=""&gt;0x00000009&lt;/TD&gt;&lt;TD style=""&gt;0x1fff1144&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style=""&gt;_AFSR&lt;/TD&gt;&lt;TD style=""&gt;0x00000000&lt;/TD&gt;&lt;TD style=""&gt;0x1fff1148&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style=""&gt;_BFAR&lt;/TD&gt;&lt;TD style=""&gt;0x00009000&lt;/TD&gt;&lt;TD style=""&gt;0x1fff1150&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style=""&gt;_MMAR&lt;/TD&gt;&lt;TD style=""&gt;0x00009000&lt;/TD&gt;&lt;TD style=""&gt;0x1fff114c&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/DIV&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The PC shows the last location where it broke, and this is the part of the code:&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class="c++" name="code"&gt;222&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; bootloader_run_flag = *((uint32_t*) BL_RUN_FLAG_ADDRESS); 000036fa:&amp;nbsp;&amp;nbsp; mov r3,#0x9000 000036fe:&amp;nbsp;&amp;nbsp; ldr r3,[r3,#0] 00003700:&amp;nbsp;&amp;nbsp; str r3,[r7,#4]&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The same problem happens when I try immediately read the memory locations after the write command, without resetting the CPU.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I attached also the InitFLASH source files for reference.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm very confused now, because we implemented this bootloader firmware on two other devices (MK10DX128 and MK40DN512) and it works without any problems.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anyone have a suggestion what could be the problem here?&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;Dario&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Original Attachment has been moved to: &lt;A _jive_internal="true" href="https://community.nxp.com/docs/DOC-337563" rel="nofollow noopener noreferrer" target="_blank"&gt;Generated_Code.rar&lt;/A&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 06 Oct 2015 17:25:22 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Kinetis-K10FX512-read-flash-hard-fault/m-p/439234#M25667</guid>
      <dc:creator>darioantolovic</dc:creator>
      <dc:date>2015-10-06T17:25:22Z</dc:date>
    </item>
    <item>
      <title>Re: Kinetis K10FX512 read flash hard fault</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Kinetis-K10FX512-read-flash-hard-fault/m-p/439235#M25668</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Today we did some more debugging,&lt;SPAN style="line-height: 1.5;"&gt; and came to a weird behavior of the MCU while writing data to flash.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Attached you can find a CodeWarrior (10.6) project with an example application of the behavior.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To clarify the behavior, we try to write 5 data bytes to flash memory on locations 0x10000004, 0x10000008, 0x1000000C, 0x10000010 and 0x10000014. The data bytes are:&lt;/P&gt;&lt;P&gt;uint32_t Flash_MSGID[5] = { 0x430U, 0x431U, 0x431U, 0x431U, 0x431U};&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;We use the FLASH_LDD component from ProcessorExpert to write and read data. If we write the above mentioned array Flash_MSGID, there is no problem, and the data is written and read correctly. But if we change the value of second element in the array to 0x430U, then we get corrupted data on that locations, and the read command generates a hard fault condition.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;uint32_t Flash_MSGID[5] = { 0x430U, 0x430U, 0x431U, 0x431U, 0x431U};&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope someone can give us some help with this problem.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Oct 2015 11:51:15 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Kinetis-K10FX512-read-flash-hard-fault/m-p/439235#M25668</guid>
      <dc:creator>darioantolovic</dc:creator>
      <dc:date>2015-10-07T11:51:15Z</dc:date>
    </item>
    <item>
      <title>Re: Kinetis K10FX512 read flash hard fault</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Kinetis-K10FX512-read-flash-hard-fault/m-p/439236#M25669</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dario&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You are not respecting the phrase programming requirements fo the Flash in the K10FX512.&lt;/P&gt;&lt;P&gt;You are only allowed to write 8 byte blocks at at time (phrase) and any attempt to write to one of these phrases (8 byte blocks) that is not erased will corrupt the Flash and cause it to return a hard fault afterwards (it then requires an erase to recover).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You need to change your code to leave a long word space after the 5th long word that you have written:&lt;/P&gt;&lt;P&gt;eg:&lt;/P&gt;&lt;P&gt;0x10000004, 0x10000008, 0x1000000C, 0x10000010 and 0x10000014 + 0xffffffff&lt;/P&gt;&lt;P&gt;and then add futher data after that and it will work (or some other equivalent method).&lt;/P&gt;&lt;P&gt;The problem is that the Flash is being written as follows (assuming X is divisible by 4):&lt;/P&gt;&lt;P&gt;Phase Address X = 0x10000004, 0x10000008&lt;/P&gt;&lt;P&gt;Phase X + 1 = 0x1000000C, 0x10000010&lt;/P&gt;&lt;P&gt;Phase X + 2 = 0x10000014 + 0xffffffff&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you tried to write at long word offset 5 it was doing&lt;/P&gt;&lt;P&gt;Phase X + 2 = 0x10000014 + "changed value"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It is not allowed to write to a phrase twice (without a sector erase inbetween) and so your problem arisies.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Mark&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Kinetis: &lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="http://www.utasker.com/kinetis.html" rel="nofollow"&gt;http://www.utasker.com/kinetis.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;K60: &lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="http://www.utasker.com/kinetis/TWR-K60N512.html" rel="nofollow"&gt;http://www.utasker.com/kinetis/TWR-K60N512.html&lt;/A&gt;&lt;SPAN&gt; / &lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="http://www.utasker.com/kinetis/TWR-K60D100M.html" rel="nofollow"&gt;http://www.utasker.com/kinetis/TWR-K60D100M.html&lt;/A&gt;&lt;SPAN&gt; / &lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="http://www.utasker.com/kinetis/TWR-K60F120M.html" rel="nofollow"&gt;http://www.utasker.com/kinetis/TWR-K60F120M.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;For the complete "out-of-the-box" Kinetis experience and faster time to market&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #7ed529;"&gt;:smileyinfo: Out-of-the-box support for 46 Kinetis boards and 10 IDEs (&lt;EM&gt;460 combinations from a single code source with no porting required&lt;/EM&gt;)&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Oct 2015 12:44:00 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Kinetis-K10FX512-read-flash-hard-fault/m-p/439236#M25669</guid>
      <dc:creator>mjbcswitzerland</dc:creator>
      <dc:date>2015-10-07T12:44:00Z</dc:date>
    </item>
    <item>
      <title>Re: Kinetis K10FX512 read flash hard fault</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Kinetis-K10FX512-read-flash-hard-fault/m-p/439237#M25670</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Mark,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thank You for the answer, it helped us a lot.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You are right, the problem was that we didn't respect the phrase requirements for this MCU.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;We changed everything so that we write always 8 byte blocks at once, and now works everything OK. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;Dario&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Nov 2015 08:11:17 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Kinetis-K10FX512-read-flash-hard-fault/m-p/439237#M25670</guid>
      <dc:creator>darioantolovic</dc:creator>
      <dc:date>2015-11-06T08:11:17Z</dc:date>
    </item>
  </channel>
</rss>

