<?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>LPC MicrocontrollersのトピックRe: LPC SPIFILIB v1.01 bug in spifiProgram()</title>
    <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC-SPIFILIB-v1-01-bug-in-spifiProgram/m-p/741219#M29892</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Arjan,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The SPIFI Library provided in source is a simple example, it do not take into consideration of corner cases. We provided the source files so you can debug and make enhancements to the code according to what you need.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope it helps!&lt;/P&gt;&lt;P&gt;Victor.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-----------------------------------------------------------------------------------------------------------------------&lt;BR /&gt;Note: If this post answers your question, please click the Correct Answer button. Thank you!&lt;BR /&gt;-----------------------------------------------------------------------------------------------------------------------&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 05 Apr 2018 15:20:26 GMT</pubDate>
    <dc:creator>victorjimenez</dc:creator>
    <dc:date>2018-04-05T15:20:26Z</dc:date>
    <item>
      <title>LPC SPIFILIB v1.01 bug in spifiProgram()</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC-SPIFILIB-v1-01-bug-in-spifiProgram/m-p/741218#M29891</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;While implementing a file system on a LPC4088 with MX25L6445E serial flash using LPCSPIFILIB v1.01, I found a bug in the spifiProgram() function.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The function programs a certain amount of bytes to an address in serial flash. However it doesn’t take into account the possibility that the start address to write may have an offset from the page boundary. Therefore it’s possible that data is written beyond the upper boundary of the page, effectively writing data to the start of the same page instead of the next page.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The solution is to subtract the page offset from the page size, in order to determine the amount of bytes that fir into the current page. This is the source code with my solution, which has been tested on a LPC4088 with a Macronix MX25L6445E serial flash:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier\ new, courier, monospace; font-size: 13px;"&gt;/* Program the device with the passed buffer */&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier\ new, courier, monospace; font-size: 13px;"&gt;/* 2018-03-07 AO: Changed code so the 'uint32_t addr' parameter can also contain&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier\ new, courier, monospace; font-size: 13px;"&gt;* an address that starts at an offset from the page boundary. */&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;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier\ new, courier, monospace; font-size: 13px;"&gt;SPIFI_ERR_T spifiProgram(const SPIFI_HANDLE_T *pHandle, uint32_t addr, const uint32_t *writeBuff, uint32_t bytes)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier\ new, courier, monospace; font-size: 13px;"&gt;{&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier\ new, courier, monospace; font-size: 13px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; uint32_t sendBytes;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier\ new, courier, monospace; font-size: 13px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; SPIFI_ERR_T err = SPIFI_ERR_NONE;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier\ new, courier, monospace; font-size: 13px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; uint32_t PageOffset;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier\ new, courier, monospace; font-size: 13px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; uint32_t MaxSendBytes;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier\ new, courier, monospace; font-size: 13px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Program using up to page size */&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier\ new, courier, monospace; font-size: 13px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; while ((bytes &amp;gt; 0) &amp;amp;&amp;amp; (err == SPIFI_ERR_NONE)) {&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier\ new, courier, monospace; font-size: 13px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PageOffset = addr &amp;amp; (pHandle-&amp;gt;pInfoData-&amp;gt;pageSize - 1); /* Assuming page size is always 2^x */&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier\ new, courier, monospace; font-size: 13px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MaxSendBytes = pHandle-&amp;gt;pInfoData-&amp;gt;pageSize - PageOffset;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier\ new, courier, monospace; font-size: 13px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sendBytes = bytes;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier\ new, courier, monospace; font-size: 13px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (sendBytes &amp;gt; MaxSendBytes) {&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier\ new, courier, monospace; font-size: 13px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sendBytes = MaxSendBytes;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier\ new, courier, monospace; font-size: 13px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier\ new, courier, monospace; font-size: 13px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; err = pHandle-&amp;gt;pFamFx-&amp;gt;pageProgram(pHandle, addr, writeBuff, sendBytes);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier\ new, courier, monospace; font-size: 13px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; addr += sendBytes;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier\ new, courier, monospace; font-size: 13px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; writeBuff += (sendBytes &amp;gt;&amp;gt; 2);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier\ new, courier, monospace; font-size: 13px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; bytes -= sendBytes;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier\ new, courier, monospace; font-size: 13px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier\ new, courier, monospace; font-size: 13px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return err;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier\ new, courier, monospace; font-size: 13px;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would appreciate your comments.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 28 Mar 2018 06:37:15 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/LPC-SPIFILIB-v1-01-bug-in-spifiProgram/m-p/741218#M29891</guid>
      <dc:creator>arjanoskam</dc:creator>
      <dc:date>2018-03-28T06:37:15Z</dc:date>
    </item>
    <item>
      <title>Re: LPC SPIFILIB v1.01 bug in spifiProgram()</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC-SPIFILIB-v1-01-bug-in-spifiProgram/m-p/741219#M29892</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Arjan,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The SPIFI Library provided in source is a simple example, it do not take into consideration of corner cases. We provided the source files so you can debug and make enhancements to the code according to what you need.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope it helps!&lt;/P&gt;&lt;P&gt;Victor.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-----------------------------------------------------------------------------------------------------------------------&lt;BR /&gt;Note: If this post answers your question, please click the Correct Answer button. Thank you!&lt;BR /&gt;-----------------------------------------------------------------------------------------------------------------------&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Apr 2018 15:20:26 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/LPC-SPIFILIB-v1-01-bug-in-spifiProgram/m-p/741219#M29892</guid>
      <dc:creator>victorjimenez</dc:creator>
      <dc:date>2018-04-05T15:20:26Z</dc:date>
    </item>
    <item>
      <title>Re: LPC SPIFILIB v1.01 bug in spifiProgram()</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC-SPIFILIB-v1-01-bug-in-spifiProgram/m-p/741220#M29893</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Victor,&lt;/P&gt;&lt;P&gt;NXP presents the SPIFI Library as a driver library, not as an example. Both on the &lt;A href="https://www.nxp.com/products/processors-and-microcontrollers/arm-based-processors-and-mcus/lpc-cortex-m-mcus/lpc1800-cortex-m3/lpc-spifi-peripheral:SPIFI-NXP-MICROCONTROLLERS"&gt;website&lt;/A&gt; and in the LPC4088 manual, chapter 15.2:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;Using the SPIFI, as described in this chapter, accomplished with a driver library&lt;/P&gt;&lt;P&gt;available from NXP Semiconductors.&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: small; font-family: Arial;"&gt;&lt;STRONG&gt;Remark: &lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: small; font-family: Arial;"&gt;The SPIFI software library with the SPIFI API are available on LPCWare.com.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;And I think writing a buffer to an offset from a page boundary is hardly a corner case, in fact I would expect it happens a lot when using a file system.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;Anyway, I ran into a problem and I fixed it to my satisfaction. I shared my solution with the community to help anybody who runs into the same problem, and maybe get some feedback or a better solution.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kind regards,&lt;/P&gt;&lt;P&gt;Arjan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 09 Apr 2018 11:14:24 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/LPC-SPIFILIB-v1-01-bug-in-spifiProgram/m-p/741220#M29893</guid>
      <dc:creator>arjanoskam</dc:creator>
      <dc:date>2018-04-09T11:14:24Z</dc:date>
    </item>
  </channel>
</rss>

