<?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>MPC5xxxのトピックErasing Flash in MPC5748G Causing Flash Corrupted</title>
    <link>https://community.nxp.com/t5/MPC5xxx/Erasing-Flash-in-MPC5748G-Causing-Flash-Corrupted/m-p/1689839#M23965</link>
    <description>&lt;P&gt;In my bootlodaer program, I need to erase flash region 0x1000000 - 0x127ffff on the 5748G. This time when I erase the falsh, some error condition occurs that causes the erase to fail, and I'm not sure exactly what causes the failure and this bootloader has worked fine for a long time. When I connected the debugger and checked the flash I found another region on the flash (0xFB0000 - 0xFB7FFFF) was corrupted. I would like to know what possible reasons could cause this to happen and what I can do in the software after the flash data is corrupted. Also is there some documentation about erasing and programing of the flash on 5748G. Thanks!&lt;/P&gt;&lt;P&gt;This is the erase function&lt;/P&gt;&lt;LI-CODE lang="c"&gt;static blt_bool FlashEraseSectors(blt_int8u first_sector_idx, blt_int8u last_sector_idx)
{
  blt_bool result = BLT_TRUE;
  blt_int8u sectorIdx;
  blt_addr sectorBaseAddr;
  blt_int32u timeout_val;
  uint32_t *lockReg;
  uint32_t *selReg;
  blt_bool bNeedErase = BLT_FALSE;
  uint32_t sectorSize;

  /* validate the sector numbers */
  if (first_sector_idx &amp;gt; last_sector_idx)
  {
    result = BLT_FALSE;
  }

  /* only continue if all is okay so far */
  if (result == BLT_TRUE)
  {
    if (last_sector_idx &amp;gt; (FLASH_TOTAL_SECTORS - 1))
    {
      result = BLT_FALSE;
    }
  }

  /* only continue if all is okay so far */
  if (BLT_TRUE == result)
  {
    DISABLE_INTERRUPTS();
    // initiate the erase operation
    C55FMC.MCR.B.ERS = 1;

    for (sectorIdx = first_sector_idx; sectorIdx &amp;lt;= last_sector_idx; sectorIdx++)
    {
      if (flashLayout[sectorIdx].erased == BLT_FALSE)
      {
        bNeedErase = BLT_TRUE;
        sectorBaseAddr = flashLayout[sectorIdx].sector_start;
        sectorSize = flashLayout[sectorIdx].sector_size;

        // unlock the block
        lockReg = (uint32_t*) ((uint32_t) &amp;amp;C55FMC.LOCK0.R + (flashLayout[sectorIdx].sel_reg * 4));
        *lockReg &amp;amp;= ~(1UL &amp;lt;&amp;lt; flashLayout[sectorIdx].sel_bit);

        // select the block to erase
        selReg = (uint32_t*) ((uint32_t) &amp;amp;C55FMC.SEL0.R + (flashLayout[sectorIdx].sel_reg * 4));
        *selReg |= (1UL &amp;lt;&amp;lt; flashLayout[sectorIdx].sel_bit);

        // write the first address in flash memory.  (erase interlock write)
        *(blt_int32u*) sectorBaseAddr = 0xFFFFFFFF; /* Interlock write */

        flashLayout[sectorIdx].erased = BLT_TRUE;
      }

      if (BLT_TRUE == bNeedErase)
      {
        // start the internal erase sequence
        C55FMC.MCR.B.EHV = 1;

        // wait until erase completed
        // erasing a 256KB sector takes about 1.2s to complete
        timeout_val = TimerGet() + ERASE_TIMEOUT_MS;
        while (C55FMC.MCR.B.DONE == 0)
        {
          // reset the watchdog
          CopService();
          if (TimerGet() &amp;gt; timeout_val)
          {
            result = BLT_FALSE;
            break;
          }
        }

        // confirm erase was successful
        if (C55FMC.MCR.B.PEG != 1)
        {
          result = BLT_FALSE;
        }

        // de-select all blocks
        C55FMC.SEL0.R = 0;
        C55FMC.SEL1.R = 0;
        C55FMC.SEL2.R = 0;

        // end internal erase sequence
        C55FMC.MCR.B.EHV = 0;
      }
    }

    // end the erase operation
    C55FMC.MCR.B.ERS = 0;

    ENABLE_INTERRUPTS();
  }
  (void) sectorSize;
  /* give the result back to the caller */
  return result;
} /*** end of FlashEraseSectors ***/&lt;/LI-CODE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="微信图片_20230715105317.png" style="width: 999px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/232818i7D858C224577A907/image-size/large?v=v2&amp;amp;px=999" role="button" title="微信图片_20230715105317.png" alt="微信图片_20230715105317.png" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;微信图片_20230715105317.png&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 21 Jul 2023 01:20:14 GMT</pubDate>
    <dc:creator>shanix</dc:creator>
    <dc:date>2023-07-21T01:20:14Z</dc:date>
    <item>
      <title>Erasing Flash in MPC5748G Causing Flash Corrupted</title>
      <link>https://community.nxp.com/t5/MPC5xxx/Erasing-Flash-in-MPC5748G-Causing-Flash-Corrupted/m-p/1689839#M23965</link>
      <description>&lt;P&gt;In my bootlodaer program, I need to erase flash region 0x1000000 - 0x127ffff on the 5748G. This time when I erase the falsh, some error condition occurs that causes the erase to fail, and I'm not sure exactly what causes the failure and this bootloader has worked fine for a long time. When I connected the debugger and checked the flash I found another region on the flash (0xFB0000 - 0xFB7FFFF) was corrupted. I would like to know what possible reasons could cause this to happen and what I can do in the software after the flash data is corrupted. Also is there some documentation about erasing and programing of the flash on 5748G. Thanks!&lt;/P&gt;&lt;P&gt;This is the erase function&lt;/P&gt;&lt;LI-CODE lang="c"&gt;static blt_bool FlashEraseSectors(blt_int8u first_sector_idx, blt_int8u last_sector_idx)
{
  blt_bool result = BLT_TRUE;
  blt_int8u sectorIdx;
  blt_addr sectorBaseAddr;
  blt_int32u timeout_val;
  uint32_t *lockReg;
  uint32_t *selReg;
  blt_bool bNeedErase = BLT_FALSE;
  uint32_t sectorSize;

  /* validate the sector numbers */
  if (first_sector_idx &amp;gt; last_sector_idx)
  {
    result = BLT_FALSE;
  }

  /* only continue if all is okay so far */
  if (result == BLT_TRUE)
  {
    if (last_sector_idx &amp;gt; (FLASH_TOTAL_SECTORS - 1))
    {
      result = BLT_FALSE;
    }
  }

  /* only continue if all is okay so far */
  if (BLT_TRUE == result)
  {
    DISABLE_INTERRUPTS();
    // initiate the erase operation
    C55FMC.MCR.B.ERS = 1;

    for (sectorIdx = first_sector_idx; sectorIdx &amp;lt;= last_sector_idx; sectorIdx++)
    {
      if (flashLayout[sectorIdx].erased == BLT_FALSE)
      {
        bNeedErase = BLT_TRUE;
        sectorBaseAddr = flashLayout[sectorIdx].sector_start;
        sectorSize = flashLayout[sectorIdx].sector_size;

        // unlock the block
        lockReg = (uint32_t*) ((uint32_t) &amp;amp;C55FMC.LOCK0.R + (flashLayout[sectorIdx].sel_reg * 4));
        *lockReg &amp;amp;= ~(1UL &amp;lt;&amp;lt; flashLayout[sectorIdx].sel_bit);

        // select the block to erase
        selReg = (uint32_t*) ((uint32_t) &amp;amp;C55FMC.SEL0.R + (flashLayout[sectorIdx].sel_reg * 4));
        *selReg |= (1UL &amp;lt;&amp;lt; flashLayout[sectorIdx].sel_bit);

        // write the first address in flash memory.  (erase interlock write)
        *(blt_int32u*) sectorBaseAddr = 0xFFFFFFFF; /* Interlock write */

        flashLayout[sectorIdx].erased = BLT_TRUE;
      }

      if (BLT_TRUE == bNeedErase)
      {
        // start the internal erase sequence
        C55FMC.MCR.B.EHV = 1;

        // wait until erase completed
        // erasing a 256KB sector takes about 1.2s to complete
        timeout_val = TimerGet() + ERASE_TIMEOUT_MS;
        while (C55FMC.MCR.B.DONE == 0)
        {
          // reset the watchdog
          CopService();
          if (TimerGet() &amp;gt; timeout_val)
          {
            result = BLT_FALSE;
            break;
          }
        }

        // confirm erase was successful
        if (C55FMC.MCR.B.PEG != 1)
        {
          result = BLT_FALSE;
        }

        // de-select all blocks
        C55FMC.SEL0.R = 0;
        C55FMC.SEL1.R = 0;
        C55FMC.SEL2.R = 0;

        // end internal erase sequence
        C55FMC.MCR.B.EHV = 0;
      }
    }

    // end the erase operation
    C55FMC.MCR.B.ERS = 0;

    ENABLE_INTERRUPTS();
  }
  (void) sectorSize;
  /* give the result back to the caller */
  return result;
} /*** end of FlashEraseSectors ***/&lt;/LI-CODE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="微信图片_20230715105317.png" style="width: 999px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/232818i7D858C224577A907/image-size/large?v=v2&amp;amp;px=999" role="button" title="微信图片_20230715105317.png" alt="微信图片_20230715105317.png" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;微信图片_20230715105317.png&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jul 2023 01:20:14 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MPC5xxx/Erasing-Flash-in-MPC5748G-Causing-Flash-Corrupted/m-p/1689839#M23965</guid>
      <dc:creator>shanix</dc:creator>
      <dc:date>2023-07-21T01:20:14Z</dc:date>
    </item>
    <item>
      <title>Re: Erasing Flash in MPC5748G Causing Flash Corrupted</title>
      <link>https://community.nxp.com/t5/MPC5xxx/Erasing-Flash-in-MPC5748G-Causing-Flash-Corrupted/m-p/1690005#M23966</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;I would like to know what possible reasons could cause this to happen and what I can do in the software after the flash data is corrupted.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Ok, are there any violations of voltage once you start erase? is there an reset or just the erase fail?&lt;/P&gt;
&lt;P&gt;Is C55FMC_MCR [PEG] set? Could you elaborate closet the failure analyzes?&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;Also is there some documentation about erasing and programing of the flash on 5748G. Thanks!&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes, detailed documentation on erase /program is in reference manual: chapter 74.6.1.3 Erase&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="petervlna_0-1689916535417.png" style="width: 564px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/232867i215AD0E2C2EAED27/image-dimensions/564x694?v=v2" width="564" height="694" role="button" title="petervlna_0-1689916535417.png" alt="petervlna_0-1689916535417.png" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;petervlna_0-1689916535417.png&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Best regards,&lt;/P&gt;
&lt;P&gt;Peter&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jul 2023 05:15:54 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MPC5xxx/Erasing-Flash-in-MPC5748G-Causing-Flash-Corrupted/m-p/1690005#M23966</guid>
      <dc:creator>petervlna</dc:creator>
      <dc:date>2023-07-21T05:15:54Z</dc:date>
    </item>
    <item>
      <title>Re: Erasing Flash in MPC5748G Causing Flash Corrupted</title>
      <link>https://community.nxp.com/t5/MPC5xxx/Erasing-Flash-in-MPC5748G-Causing-Flash-Corrupted/m-p/1690113#M23968</link>
      <description>&lt;P&gt;I am not sure is there any&amp;nbsp;&lt;SPAN&gt;violations of voltage, but I am sure that there is no reset and C55FMC_MCR [PEG] is not set. It seems like that it is just the erase fail. Actually I can't provide more&amp;nbsp;elaborated information,&amp;nbsp;because when this happened due to the urgent need to get the device working properly, I have no time to do the&amp;nbsp;failure analyzes. So I want to know some possible reasons that can make the flash corrupted happen.&amp;nbsp;I think maybe these possible reasons will provide some useful clues to locate the root cause of this problem. Thanks.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jul 2023 07:10:56 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MPC5xxx/Erasing-Flash-in-MPC5748G-Causing-Flash-Corrupted/m-p/1690113#M23968</guid>
      <dc:creator>shanix</dc:creator>
      <dc:date>2023-07-21T07:10:56Z</dc:date>
    </item>
    <item>
      <title>Re: Erasing Flash in MPC5748G Causing Flash Corrupted</title>
      <link>https://community.nxp.com/t5/MPC5xxx/Erasing-Flash-in-MPC5748G-Causing-Flash-Corrupted/m-p/1691121#M23982</link>
      <description>&lt;P&gt;Ok,&lt;/P&gt;
&lt;P&gt;So short list:&lt;/P&gt;
&lt;P&gt;1. voltage violation&lt;/P&gt;
&lt;P&gt;2. Interrupts are on&lt;/P&gt;
&lt;P&gt;3. random event, like radiation&lt;/P&gt;
&lt;P&gt;4. executed code get lost and corrupted flash by interrupting its programming process.&lt;/P&gt;
&lt;P&gt;You may also like to check if there was any exception called.&lt;/P&gt;
&lt;P&gt;Best regards,&lt;/P&gt;
&lt;P&gt;Peter&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jul 2023 07:15:24 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MPC5xxx/Erasing-Flash-in-MPC5748G-Causing-Flash-Corrupted/m-p/1691121#M23982</guid>
      <dc:creator>petervlna</dc:creator>
      <dc:date>2023-07-24T07:15:24Z</dc:date>
    </item>
    <item>
      <title>Re: Erasing Flash in MPC5748G Causing Flash Corrupted</title>
      <link>https://community.nxp.com/t5/MPC5xxx/Erasing-Flash-in-MPC5748G-Causing-Flash-Corrupted/m-p/1727029#M24301</link>
      <description>Hi, petervlna, I want to know why interrupts can cause flash corrupted. And is there any software methods to recover the corrupted flash? Thanks.</description>
      <pubDate>Thu, 21 Sep 2023 09:23:58 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MPC5xxx/Erasing-Flash-in-MPC5748G-Causing-Flash-Corrupted/m-p/1727029#M24301</guid>
      <dc:creator>shanix</dc:creator>
      <dc:date>2023-09-21T09:23:58Z</dc:date>
    </item>
  </channel>
</rss>

