<?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>topic Re: Section programming (PGMSEC) on K66 fails in Kinetis Microcontrollers</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Section-programming-PGMSEC-on-K66-fails/m-p/1172780#M58602</link>
    <description>&lt;P&gt;Hello Omar,&lt;/P&gt;&lt;P&gt;Thank you for your reply.&lt;/P&gt;&lt;P&gt;From what I understand, the swap features are not available on this processor...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Meanwhile I've found the solution to my problem. I was using sizes in phrases instead of double-phrase... When preparing the &lt;FONT face="courier new,courier"&gt;PGMSEC&lt;FONT face="arial,helvetica,sans-serif"&gt; command, the assignments to &lt;FONT face="courier new,courier"&gt;FCCOB4&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;FCCOB5&lt;/FONT&gt; should be:&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;FTFE-&amp;gt;FCCOB4 = (uint8_t)(((sizeof(data) / 16U) &amp;gt;&amp;gt; 8U) &amp;amp; 0xFFU);
FTFE-&amp;gt;FCCOB5 = (uint8_t)((sizeof(data) / 16U) &amp;amp; 0xFFU);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, as a side-note, the two P-flash blocks do not seem to be fully decoupled. I've imroved my code to remove the active wait for the &lt;FONT face="courier new,courier"&gt;CCIR&lt;/FONT&gt; bit. This resulted in sometimes running in read collision errors (&lt;FONT face="courier new,courier"&gt;RDCOLERR&lt;/FONT&gt;) when attempting to read data too early (even though the &lt;FONT face="courier new,courier"&gt;CCIR&lt;/FONT&gt; bit was set when starting the command). Also when performing several write operations successively, some write operations were being skipped. I could fix this by running my entire software from RAM.&lt;/P&gt;</description>
    <pubDate>Mon, 26 Oct 2020 02:46:45 GMT</pubDate>
    <dc:creator>ajuc</dc:creator>
    <dc:date>2020-10-26T02:46:45Z</dc:date>
    <item>
      <title>Section programming (PGMSEC) on K66 fails</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Section-programming-PGMSEC-on-K66-fails/m-p/1160422#M58300</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I am attempting to write data in the P-flash of my K66FX (MK66FX1M0VMD18) controller. However it sometimes fails with an ACCERR without apparent reason...&lt;/P&gt;&lt;P&gt;My code is running in the first block of the P-flash and I am attempting to write to the second block. The commands to erase the sector where the data will be written (ERSSRC) and to make the FlexRAM available as RAM (SETRAM) both complete successfully. All the P-flash is currently unprotected.&lt;BR /&gt;Here is some sample code to make it easier to understand:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;const uint32_t address = 0xA0000UL;
// Fill up data to be written
uint8_t data[0x800U];
for(uint16_t i = 0U; i &amp;lt; sizeof(data); ++i) {
    data[i] = (uint8_t)(i &amp;amp; 0xFFU);
}

// Erase
FTFE-&amp;gt;FCCOB0 = 0x09U; // ERSSCR
FTFE-&amp;gt;FCCOB1 = (uint8_t)((address &amp;gt;&amp;gt; 16U) &amp;amp; 0xFFU);
FTFE-&amp;gt;FCCOB2 = (uint8_t)((address &amp;gt;&amp;gt; 8U) &amp;amp; 0xFFU);
FTFE-&amp;gt;FCCOB3 = (uint8_t)(address &amp;amp; 0xFFU);
FTFE-&amp;gt;FSTAT = 0x80U;
while((FTFE-&amp;gt;FSTAT &amp;amp; 0x80U) == 0U) {
    // Wait for the command to complete
}

// Set the FlexRAM function
FTFE-&amp;gt;FCCOB0 = 0x81U; // SETRAM
FTFE-&amp;gt;FCCOB1 = 0xFFU;
FTFE-&amp;gt;FSTAT = 0x80U;
while((FTFE-&amp;gt;FSTAT &amp;amp; 0x80U) == 0U) {
    // Wait for the command to complete
}

// Copy the data to be written into FlexRAM
volatile uint8_t *flexram_address = (volatile uint8_t *)0x14000000UL;
for(uint16_t i = 0U; i &amp;lt; sizeof(data); ++i) {
    flexram_address[i] = data[i];
}
// Write
FTFE-&amp;gt;FCCOB0 = 0x0BU; // PGMSEC
FTFE-&amp;gt;FCCOB1 = (uint8_t)((address &amp;gt;&amp;gt; 16U) &amp;amp; 0xFFU);
FTFE-&amp;gt;FCCOB2 = (uint8_t)((address &amp;gt;&amp;gt; 8U) &amp;amp; 0xFFU);
FTFE-&amp;gt;FCCOB3 = (uint8_t)(address &amp;amp; 0xFFU);
FTFE-&amp;gt;FCCOB4 = (uint8_t)(((sizeof(data) / 8U) &amp;gt;&amp;gt; 8U) &amp;amp; 0xFFU);
FTFE-&amp;gt;FCCOB5 = (uint8_t)((sizeof(data) / 8U) &amp;amp; 0xFFU);
FTFE-&amp;gt;FSTAT = 0x80U;
while((FTFE-&amp;gt;FSTAT &amp;amp; 0x80U) == 0U) {
    // Wait for the command to complete
    // It will complete with ACCERR
}&lt;/LI-CODE&gt;&lt;P&gt;Reducing the size of the data to write to 512 bytes will make the command succeed. However, according to the manual, it should be possible to write up to 1kB. Also, attempting to write 512 bytes at another location, for example 0xA0C40, fails as well. Even though this address is aligned to 128-bits and the sector boundary is not exceeded...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Am I missing something or have you already experienced a similar problem?&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 05:48:52 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Section-programming-PGMSEC-on-K66-fails/m-p/1160422#M58300</guid>
      <dc:creator>ajuc</dc:creator>
      <dc:date>2020-09-29T05:48:52Z</dc:date>
    </item>
    <item>
      <title>Re: Section programming (PGMSEC) on K66 fails</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Section-programming-PGMSEC-on-K66-fails/m-p/1163571#M58376</link>
      <description>&lt;P&gt;Hello &lt;A id="link_12" href="https://community.nxp.com/t5/user/viewprofilepage/user-id/146040" target="_self"&gt;ajuc&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the swap system is enabled, the swap indicator address in each program flash block is implicitly protected from sector erase unless the swap system is in the UPDATE or UPDATE-ERASED state and the program flash sector containing the swap indicator address being erased is in the non-active block.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, applying voltages to the I/O when the processor is not powered can lead to corruption of flash contents, corruption of flash control logic, or corruption of device configuration and trim values which in turn can lead the processor reporting as secured or failure the processor to respond to and complete flash commands.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let me know if this is helpful, if you have more questions do not hesitate to ask me.&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;/P&gt;
&lt;P&gt;Omar&lt;/P&gt;</description>
      <pubDate>Tue, 06 Oct 2020 17:45:46 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Section-programming-PGMSEC-on-K66-fails/m-p/1163571#M58376</guid>
      <dc:creator>Omar_Anguiano</dc:creator>
      <dc:date>2020-10-06T17:45:46Z</dc:date>
    </item>
    <item>
      <title>Re: Section programming (PGMSEC) on K66 fails</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Section-programming-PGMSEC-on-K66-fails/m-p/1172780#M58602</link>
      <description>&lt;P&gt;Hello Omar,&lt;/P&gt;&lt;P&gt;Thank you for your reply.&lt;/P&gt;&lt;P&gt;From what I understand, the swap features are not available on this processor...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Meanwhile I've found the solution to my problem. I was using sizes in phrases instead of double-phrase... When preparing the &lt;FONT face="courier new,courier"&gt;PGMSEC&lt;FONT face="arial,helvetica,sans-serif"&gt; command, the assignments to &lt;FONT face="courier new,courier"&gt;FCCOB4&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;FCCOB5&lt;/FONT&gt; should be:&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;FTFE-&amp;gt;FCCOB4 = (uint8_t)(((sizeof(data) / 16U) &amp;gt;&amp;gt; 8U) &amp;amp; 0xFFU);
FTFE-&amp;gt;FCCOB5 = (uint8_t)((sizeof(data) / 16U) &amp;amp; 0xFFU);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, as a side-note, the two P-flash blocks do not seem to be fully decoupled. I've imroved my code to remove the active wait for the &lt;FONT face="courier new,courier"&gt;CCIR&lt;/FONT&gt; bit. This resulted in sometimes running in read collision errors (&lt;FONT face="courier new,courier"&gt;RDCOLERR&lt;/FONT&gt;) when attempting to read data too early (even though the &lt;FONT face="courier new,courier"&gt;CCIR&lt;/FONT&gt; bit was set when starting the command). Also when performing several write operations successively, some write operations were being skipped. I could fix this by running my entire software from RAM.&lt;/P&gt;</description>
      <pubDate>Mon, 26 Oct 2020 02:46:45 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Section-programming-PGMSEC-on-K66-fails/m-p/1172780#M58602</guid>
      <dc:creator>ajuc</dc:creator>
      <dc:date>2020-10-26T02:46:45Z</dc:date>
    </item>
  </channel>
</rss>

