<?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 P-flash Erase Error in S12 / MagniV Microcontrollers</title>
    <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/P-flash-Erase-Error/m-p/1831057#M19732</link>
    <description>&lt;P&gt;Hello, I am working on a Bootloader project using CAN communication with MC9S12XS64.&lt;/P&gt;&lt;P&gt;We are currently using interrupts for CAN and are working on a project using Process expert.&lt;/P&gt;&lt;P&gt;For my next flash programming task, I tested the XS series' P flash example code and my code that applied it.&lt;/P&gt;&lt;P&gt;Code:&lt;/P&gt;&lt;P&gt;&lt;FONT size="4"&gt;------------------------------------------------------------------------&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;UINT8 PFlash_EraseSector(UINT32 address)&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;{&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;while((FSTAT &amp;amp; FSTAT_CCIF_MASK) == 0); //wait if command in progress&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;FSTAT = 0x30; //clear ACCERR and PVIOL&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;FCCOBIX = 0x00;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;FCCOB = 0x0A00 | ((address &amp;amp; 0x007F0000)&amp;gt;&amp;gt;16);&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;FCCOBIX = 0x01;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;FCCOB = (address &amp;amp; 0x0000FFF8);&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;FSTAT = 0x80; //launch command&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;while((FSTAT &amp;amp; FSTAT_CCIF_MASK) == 0); //wait for done&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;if((FSTAT &amp;amp; (FSTAT_ACCERR_MASK | FSTAT_FPVIOL_MASK)) != 0)&amp;nbsp;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;nbsp;return FlashEraseError;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;else&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;nbsp;return noErr;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;}&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;UINT8 PFlash_EraseSectorBySector(UINT32 addr_l, UINT32 addr_h)&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;{&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;UINT32 Address;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;UINT8 Error;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;for(Address = addr_l; Address &amp;lt; addr_h; Address += FLASH_SECTOR_SIZE)&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;{&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;Error = PFlash_EraseSector(Address);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;if(Error != noErr)&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;return(Error);&lt;/FONT&gt;&lt;BR /&gt;}&lt;BR /&gt;&lt;FONT size="2"&gt;return(noErr);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;}&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;void Memory_Write(void)&lt;BR /&gt;{&lt;BR /&gt;if(u8BootPhraseRcvd == 1) // If a complete booth phrase was received&lt;BR /&gt;{&lt;BR /&gt;u8BootPhraseRcvd = 0;&lt;BR /&gt;&lt;BR /&gt;if(Verify_Phrase_Checksum()) // Check that phrase checksum matches&lt;BR /&gt;{&lt;BR /&gt;&lt;BR /&gt;if(!u8flashErased) // the flash hasn't been erased, erase it&lt;BR /&gt;{&lt;BR /&gt;PFlash_EraseSectorBySector(0x7F0000, 0x7FEFDF); // Jump to RAM and Erase Flash, return to Flash when done.&lt;BR /&gt;u8flashErased = 1; //Indicate that flash has been erased&lt;BR /&gt;&lt;BR /&gt;} .....&amp;nbsp;ellipsis .....&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="4"&gt;---------------------------------------------------------------------&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;The code compiles fine.&lt;BR /&gt;Debug and run in hiwave.&lt;BR /&gt;When the specified CAN msg is sent and the requirements are met,&lt;/P&gt;&lt;P&gt;PFlash_EraseSectorBySector (0x7F0000, 0x7FEFDFUL) is executed.&lt;/P&gt;&lt;P&gt;Afterwards, the results were confirmed through real-time debugging in hiwave.&lt;BR /&gt;FlashEraseError occurs in the error checking code of the example code.&lt;/P&gt;&lt;P&gt;During PFlash_EraseSector(UINT32 address)&lt;/P&gt;&lt;P&gt;FSTAT = 0x80; //launch command&lt;BR /&gt;while((FSTAT &amp;amp; FSTAT_CCIF_MASK) == 0); //wait for done&lt;/P&gt;&lt;P&gt;If I run the code without it, it runs without an error, but I don't know if this is correct.&lt;/P&gt;&lt;P&gt;I'd like to know what the problem is and how to make it work properly.&lt;/P&gt;&lt;DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;</description>
    <pubDate>Tue, 19 Mar 2024 10:02:52 GMT</pubDate>
    <dc:creator>kuksu</dc:creator>
    <dc:date>2024-03-19T10:02:52Z</dc:date>
    <item>
      <title>P-flash Erase Error</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/P-flash-Erase-Error/m-p/1831057#M19732</link>
      <description>&lt;P&gt;Hello, I am working on a Bootloader project using CAN communication with MC9S12XS64.&lt;/P&gt;&lt;P&gt;We are currently using interrupts for CAN and are working on a project using Process expert.&lt;/P&gt;&lt;P&gt;For my next flash programming task, I tested the XS series' P flash example code and my code that applied it.&lt;/P&gt;&lt;P&gt;Code:&lt;/P&gt;&lt;P&gt;&lt;FONT size="4"&gt;------------------------------------------------------------------------&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;UINT8 PFlash_EraseSector(UINT32 address)&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;{&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;while((FSTAT &amp;amp; FSTAT_CCIF_MASK) == 0); //wait if command in progress&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;FSTAT = 0x30; //clear ACCERR and PVIOL&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;FCCOBIX = 0x00;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;FCCOB = 0x0A00 | ((address &amp;amp; 0x007F0000)&amp;gt;&amp;gt;16);&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;FCCOBIX = 0x01;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;FCCOB = (address &amp;amp; 0x0000FFF8);&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;FSTAT = 0x80; //launch command&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;while((FSTAT &amp;amp; FSTAT_CCIF_MASK) == 0); //wait for done&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;if((FSTAT &amp;amp; (FSTAT_ACCERR_MASK | FSTAT_FPVIOL_MASK)) != 0)&amp;nbsp;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;nbsp;return FlashEraseError;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;else&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;nbsp;return noErr;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;}&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;UINT8 PFlash_EraseSectorBySector(UINT32 addr_l, UINT32 addr_h)&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;{&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;UINT32 Address;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;UINT8 Error;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;for(Address = addr_l; Address &amp;lt; addr_h; Address += FLASH_SECTOR_SIZE)&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;{&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;Error = PFlash_EraseSector(Address);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;if(Error != noErr)&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;return(Error);&lt;/FONT&gt;&lt;BR /&gt;}&lt;BR /&gt;&lt;FONT size="2"&gt;return(noErr);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;}&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;void Memory_Write(void)&lt;BR /&gt;{&lt;BR /&gt;if(u8BootPhraseRcvd == 1) // If a complete booth phrase was received&lt;BR /&gt;{&lt;BR /&gt;u8BootPhraseRcvd = 0;&lt;BR /&gt;&lt;BR /&gt;if(Verify_Phrase_Checksum()) // Check that phrase checksum matches&lt;BR /&gt;{&lt;BR /&gt;&lt;BR /&gt;if(!u8flashErased) // the flash hasn't been erased, erase it&lt;BR /&gt;{&lt;BR /&gt;PFlash_EraseSectorBySector(0x7F0000, 0x7FEFDF); // Jump to RAM and Erase Flash, return to Flash when done.&lt;BR /&gt;u8flashErased = 1; //Indicate that flash has been erased&lt;BR /&gt;&lt;BR /&gt;} .....&amp;nbsp;ellipsis .....&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="4"&gt;---------------------------------------------------------------------&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;The code compiles fine.&lt;BR /&gt;Debug and run in hiwave.&lt;BR /&gt;When the specified CAN msg is sent and the requirements are met,&lt;/P&gt;&lt;P&gt;PFlash_EraseSectorBySector (0x7F0000, 0x7FEFDFUL) is executed.&lt;/P&gt;&lt;P&gt;Afterwards, the results were confirmed through real-time debugging in hiwave.&lt;BR /&gt;FlashEraseError occurs in the error checking code of the example code.&lt;/P&gt;&lt;P&gt;During PFlash_EraseSector(UINT32 address)&lt;/P&gt;&lt;P&gt;FSTAT = 0x80; //launch command&lt;BR /&gt;while((FSTAT &amp;amp; FSTAT_CCIF_MASK) == 0); //wait for done&lt;/P&gt;&lt;P&gt;If I run the code without it, it runs without an error, but I don't know if this is correct.&lt;/P&gt;&lt;P&gt;I'd like to know what the problem is and how to make it work properly.&lt;/P&gt;&lt;DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 19 Mar 2024 10:02:52 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/P-flash-Erase-Error/m-p/1831057#M19732</guid>
      <dc:creator>kuksu</dc:creator>
      <dc:date>2024-03-19T10:02:52Z</dc:date>
    </item>
    <item>
      <title>Re: P-flash Erase Error</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/P-flash-Erase-Error/m-p/1832054#M19739</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;The problem can be placement of the code&lt;/P&gt;
&lt;P&gt;FSTAT = 0x80; //launch command&lt;BR /&gt;while((FSTAT &amp;amp; FSTAT_CCIF_MASK) == 0); //wait for done&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code is not allowed to be executed out of the memory which is erased of written.&lt;/P&gt;
&lt;P&gt;This part of the code should be in different memory or memory block, for example, &amp;nbsp;the RAM or somewhere else.&lt;/P&gt;
&lt;P&gt;Attached is the example.&lt;/P&gt;
&lt;P&gt;Search for text&lt;/P&gt;
&lt;P&gt;//==============================================================================&lt;/P&gt;
&lt;P&gt;//PFLASH Send_Command&lt;/P&gt;
&lt;P&gt;//==============================================================================&lt;/P&gt;
&lt;P&gt;In the main.c module.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best regards,&lt;/P&gt;
&lt;P&gt;Ladislav&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2024 13:10:59 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/P-flash-Erase-Error/m-p/1832054#M19739</guid>
      <dc:creator>lama</dc:creator>
      <dc:date>2024-03-20T13:10:59Z</dc:date>
    </item>
  </channel>
</rss>

