<?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>LPCXpresso IDEのトピックRe: AN11008 flash storage code hard faults</title>
    <link>https://community.nxp.com/t5/LPCXpresso-IDE/AN11008-flash-storage-code-hard-faults/m-p/592748#M30141</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by NXP_Europe on Wed Jan 18 07:11:56 MST 2012&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Hello,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;*TmpVarRec = *VarRec; copies the content of the VarRec pointer to the address of the TmpVarRec pointer, because they are both of the VARIABLE_RECORD * type. All the bytes of the structure are copied. This makes the following line redundant, but it works fine.&lt;/SPAN&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;&amp;nbsp; for (Byte = 0; Byte &amp;lt; MAX_VARIABLE_SIZE; Byte++) TmpVarRec-&amp;gt;Data[Byte] = VarRec-&amp;gt;Data[Byte];
&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;SPAN&gt;SECTOR_RECORD structure size = 48&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;VARIABLE_RECORD structure size = 16&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;With one call to NVOL_SetVariableRecord, a flash block of 256 is written. The 256 bytes will exactly accomodate 1sector+ 13 variable records, or 16 variable records. With modified structure sizes the TmpVarRec pointer could write outside the Buffer array. This happens if Offset &amp;gt; (256 - the size of the VARIABLE_RECORD structure). Therefore the question, did you modify the structure sizes?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 15 Jun 2016 21:29:21 GMT</pubDate>
    <dc:creator>lpcware</dc:creator>
    <dc:date>2016-06-15T21:29:21Z</dc:date>
    <item>
      <title>AN11008 flash storage code hard faults</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/AN11008-flash-storage-code-hard-faults/m-p/592747#M30140</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by JSalisbury on Fri Aug 26 10:08:50 MST 2011&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I am starting to use the code supplied with AN11008 and have noticed some hard faults, they seem to occour about line 782 of flash_nvol.c It seems as if the pointer provided to *TmpVarRec is somtimes outside the memory space and values such as 0x5xxxxxxx have been seen is the line *TmpVarRec=*VarRec safe, as there is an array in the variable record?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;
for (Byte = 0; Byte &amp;lt; 256; Byte++) Buffer[Byte] = 0xFF;

&amp;nbsp;&amp;nbsp;&amp;nbsp; // get offset of temporary variable record in 256 byte segment
&amp;nbsp;&amp;nbsp;&amp;nbsp; TmpVarRec = (VARIABLE_RECORD *)(Buffer + (Offset % 256));
&amp;nbsp;&amp;nbsp;&amp;nbsp; // copy variable record
&amp;nbsp;&amp;nbsp;&amp;nbsp; *TmpVarRec = *VarRec;
for (Byte = 0; Byte &amp;lt; MAX_VARIABLE_SIZE; Byte++)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TmpVarRec-&amp;gt;Data[Byte] = VarRec-&amp;gt;Data[Byte];
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;SPAN&gt;Should it be more like the code below?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;
for (Byte = 0; Byte &amp;lt; 256; Byte++) Buffer[Byte] = 0xFF;

&amp;nbsp;&amp;nbsp;&amp;nbsp; // get offset of temporary variable record in 256 byte segment
&amp;nbsp;&amp;nbsp;&amp;nbsp; TmpVarRec = (VARIABLE_RECORD *)(Buffer + (Offset % 256));
&amp;nbsp;&amp;nbsp;&amp;nbsp; // copy variable record
&amp;nbsp;&amp;nbsp;&amp;nbsp; //*TmpVarRec = *VarRec;
&amp;nbsp;&amp;nbsp;&amp;nbsp; TmpVarRec-&amp;gt;Checksum = VarRec-&amp;gt;Checksum;
&amp;nbsp;&amp;nbsp;&amp;nbsp; TmpVarRec-&amp;gt;Flags = VarRec-&amp;gt;Flags;
&amp;nbsp;&amp;nbsp;&amp;nbsp; TmpVarRec-&amp;gt;Id = VarRec-&amp;gt;Id;
 &lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 21:29:20 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/AN11008-flash-storage-code-hard-faults/m-p/592747#M30140</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T21:29:20Z</dc:date>
    </item>
    <item>
      <title>Re: AN11008 flash storage code hard faults</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/AN11008-flash-storage-code-hard-faults/m-p/592748#M30141</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by NXP_Europe on Wed Jan 18 07:11:56 MST 2012&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Hello,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;*TmpVarRec = *VarRec; copies the content of the VarRec pointer to the address of the TmpVarRec pointer, because they are both of the VARIABLE_RECORD * type. All the bytes of the structure are copied. This makes the following line redundant, but it works fine.&lt;/SPAN&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;&amp;nbsp; for (Byte = 0; Byte &amp;lt; MAX_VARIABLE_SIZE; Byte++) TmpVarRec-&amp;gt;Data[Byte] = VarRec-&amp;gt;Data[Byte];
&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;SPAN&gt;SECTOR_RECORD structure size = 48&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;VARIABLE_RECORD structure size = 16&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;With one call to NVOL_SetVariableRecord, a flash block of 256 is written. The 256 bytes will exactly accomodate 1sector+ 13 variable records, or 16 variable records. With modified structure sizes the TmpVarRec pointer could write outside the Buffer array. This happens if Offset &amp;gt; (256 - the size of the VARIABLE_RECORD structure). Therefore the question, did you modify the structure sizes?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 21:29:21 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/AN11008-flash-storage-code-hard-faults/m-p/592748#M30141</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T21:29:21Z</dc:date>
    </item>
  </channel>
</rss>

