<?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: Flash erase/write fails after deep sleep wakeup in Kinetis Microcontrollers</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Flash-erase-write-fails-after-deep-sleep-wakeup/m-p/508273#M31970</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I don't know that this is related to your problem or not however not having the Interrupt Enable and Disable instructions marked as Volatile can result in hair pulling debugging sessions with some compilers as optimizer reorder code (Code Motion).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What I use for GCC:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#define ATTR_NO_INSTRUMENT_FUNCTION __attribute__( ( no_instrument_function ) )&lt;BR /&gt;/*&lt;/P&gt;&lt;P&gt; * This is the only method available in the ARMv6-M architecture&lt;/P&gt;&lt;P&gt; * (Cortex-M0/M0+)&lt;/P&gt;&lt;P&gt; *&lt;/P&gt;&lt;P&gt; * In normal applications there is no need to add any barrier&lt;/P&gt;&lt;P&gt; * instruction after using a CPS instruction to enable an interrupt.&lt;/P&gt;&lt;P&gt; *&lt;/P&gt;&lt;P&gt; * If an interrupt was already in the pending state, the processor&lt;/P&gt;&lt;P&gt; * accepts the interrupt after the “CPSIE I” is executed. However,&lt;/P&gt;&lt;P&gt; * additional instructions can be executed before the processor enters&lt;/P&gt;&lt;P&gt; * the exception handler:&lt;/P&gt;&lt;P&gt; *&lt;/P&gt;&lt;P&gt; *&amp;nbsp; For Cortex-M3 or Cortex-M4, the processor can execute up to TWO&lt;/P&gt;&lt;P&gt; *&amp;nbsp; additional instructions before entering the interrupt service&lt;/P&gt;&lt;P&gt; *&amp;nbsp; routine.&lt;/P&gt;&lt;P&gt; *&lt;/P&gt;&lt;P&gt; *&amp;nbsp; For Cortex-M0, the processor can execute up to ONE additional&lt;/P&gt;&lt;P&gt; *&amp;nbsp; instruction before entering the interrupt service routine.&lt;/P&gt;&lt;P&gt; *&lt;/P&gt;&lt;P&gt; */&lt;/P&gt;&lt;P&gt;static inline ATTR_NO_INSTRUMENT_FUNCTION void irq_enable( void )&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp; __asm__ __volatile__ ("cpsie i"); /* Clear PRIMASK */&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/*&lt;/P&gt;&lt;P&gt; * The CPSID instruction is self-synchronized to the instruction&lt;/P&gt;&lt;P&gt; * stream and there is no requirement to insert memory barrier&lt;/P&gt;&lt;P&gt; * instructions after CPSID.&lt;/P&gt;&lt;P&gt; */&lt;/P&gt;&lt;P&gt;static inline ATTR_NO_INSTRUMENT_FUNCTION void irq_disable( void )&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp; __asm__ __volatile__ ("cpsid i");&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 29 Mar 2016 11:57:02 GMT</pubDate>
    <dc:creator>bobpaddock</dc:creator>
    <dc:date>2016-03-29T11:57:02Z</dc:date>
    <item>
      <title>Flash erase/write fails after deep sleep wakeup</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Flash-erase-write-fails-after-deep-sleep-wakeup/m-p/508267#M31964</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;For my Kinetis K21 project, after deepsleep wakeup(lls)( Before going to sleep erase/write flash is working without any problem ), any try to erase/write flash sector from software is giving hard fault. Even if we do software reset, still problem persists. While issuing the command for sector erase the controller is giving hard fault. But after a power on reset it is possible to erase/write the flash.&amp;nbsp; Please help me to narrow down the issue and solve it.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Mar 2016 02:31:43 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Flash-erase-write-fails-after-deep-sleep-wakeup/m-p/508267#M31964</guid>
      <dc:creator>renjithks</dc:creator>
      <dc:date>2016-03-29T02:31:43Z</dc:date>
    </item>
    <item>
      <title>Re: Flash erase/write fails after deep sleep wakeup</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Flash-erase-write-fails-after-deep-sleep-wakeup/m-p/508268#M31965</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi RENJITH K S,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; When you wakeup from the LLS mode, did you disable the global interrupt before doing the flash erase/write operation?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Normally, the hardfault is caused by the interrupt when doing the flash operation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; So, please check your flash operation code at first, you disable the global interrupt before flash operation, after the flash operation is finished, then enable the global interrupt again!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Wish it helps you!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Have a great day,&lt;BR /&gt;Jingjing&lt;/P&gt;&lt;P&gt;&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>Tue, 29 Mar 2016 04:51:38 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Flash-erase-write-fails-after-deep-sleep-wakeup/m-p/508268#M31965</guid>
      <dc:creator>kerryzhou</dc:creator>
      <dc:date>2016-03-29T04:51:38Z</dc:date>
    </item>
    <item>
      <title>Re: Flash erase/write fails after deep sleep wakeup</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Flash-erase-write-fails-after-deep-sleep-wakeup/m-p/508269#M31966</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Interrupts are disabled in my code before doing the flash operation. Before going to sleep all the flash operations are working fine with the same code. Only after sleep wake-up it's giving the issue, and will start working if we do a power-on reset.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Mar 2016 05:01:02 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Flash-erase-write-fails-after-deep-sleep-wakeup/m-p/508269#M31966</guid>
      <dc:creator>renjithks</dc:creator>
      <dc:date>2016-03-29T05:01:02Z</dc:date>
    </item>
    <item>
      <title>Re: Flash erase/write fails after deep sleep wakeup</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Flash-erase-write-fails-after-deep-sleep-wakeup/m-p/508270#M31967</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi RENJITH K S,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; Please attach your test project, and tell me the full name of your chip, I need to check it on my side.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Waiting for your reply!&lt;/P&gt;&lt;P&gt;Jingjing&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Mar 2016 05:13:05 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Flash-erase-write-fails-after-deep-sleep-wakeup/m-p/508270#M31967</guid>
      <dc:creator>kerryzhou</dc:creator>
      <dc:date>2016-03-29T05:13:05Z</dc:date>
    </item>
    <item>
      <title>Re: Flash erase/write fails after deep sleep wakeup</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Flash-erase-write-fails-after-deep-sleep-wakeup/m-p/508271#M31968</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-size: 14pt;"&gt;Problem Description: Facing problem in Write/Erase Flash, after wake-up from sleep.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 14pt;"&gt;Environment : Kinetis K21(K21FN1M0M12)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 14pt;"&gt;Tool: CodeWarrior for MCU - Version 10.5&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 14.0pt;"&gt;Detailed Description:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 14.0pt;"&gt;For the Kinetis K21 project, we are facing issues with in-software flash write. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 14.0pt;"&gt;Flash operations (Read, Write and Erase) are working fine always when you boot the device. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 14.0pt;"&gt;Only after deep-sleep(using &lt;STRONG&gt;&lt;SPAN style="color: black; background: silver;"&gt;enter_lls&lt;/SPAN&gt; &lt;/STRONG&gt;&lt;SPAN style="color: black;"&gt;API&lt;/SPAN&gt;) wakeup, in few devices the flash erase/write is failing, and we have noticed FTFE Read Collision Error Flag &lt;STRONG style="background: yellow;"&gt;RDCOLERR&lt;/STRONG&gt; of FTFE_FSTAT register is getting set while initiating the flash erase command. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 14.0pt;"&gt;In debug mode if we execute the same code for flash operations step by step, the issue is not reproducible. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 14.0pt;"&gt;Even with a software reset flash is not accessible for erase/write. Only after a power on reset it is possible to erase/write the flash.&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Mar 2016 07:16:09 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Flash-erase-write-fails-after-deep-sleep-wakeup/m-p/508271#M31968</guid>
      <dc:creator>renjithks</dc:creator>
      <dc:date>2016-03-29T07:16:09Z</dc:date>
    </item>
    <item>
      <title>Re: Flash erase/write fails after deep sleep wakeup</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Flash-erase-write-fails-after-deep-sleep-wakeup/m-p/508272#M31969</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;/** Macro to enable all interrupts. */&lt;/P&gt;&lt;P&gt;#define EnableInterrupts asm ("CPSIE&amp;nbsp; i")&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/** Macro to disable all interrupts. */&lt;/P&gt;&lt;P&gt;#define DisableInterrupts asm ("CPSID&amp;nbsp; i")&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/**&lt;/P&gt;&lt;P&gt; * @brief erase a sector of the flash&lt;/P&gt;&lt;P&gt; */&lt;/P&gt;&lt;P&gt;int flash_sectorErase( unsigned int* FlashPointer )&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; int Return = E_FLASH_SUCCESS;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; uint32_t FlashPtr = (uint32_t)FlashPointer;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* checking access error */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if ( FTFE_FSTAT &amp;amp; ( FTFE_FSTAT_ACCERR_MASK |&lt;/P&gt;&lt;P&gt;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FTFE_FSTAT_FPVIOL_MASK&amp;nbsp; |&lt;/P&gt;&lt;P&gt;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FTFE_FSTAT_RDCOLERR_MASK ) )&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* clear error flag */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FTFE_FSTAT |= ( FTFE_FSTAT_ACCERR_MASK |&lt;/P&gt;&lt;P&gt;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FTFE_FSTAT_FPVIOL_MASK |&lt;/P&gt;&lt;P&gt;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FTFE_FSTAT_RDCOLERR_MASK );&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FTFE_FCNFG &amp;amp;= ~(FTFE_FCNFG_RDCOLLIE_MASK);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; DisableInterrupts;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Allocate space on stack to run flash command out of SRAM */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* wait till CCIF is set*/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; while (!(FTFE_FSTAT &amp;amp; FTFE_FSTAT_CCIF_MASK));&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Write command to FCCOB registers */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FTFE_FCCOB0 = FlashCmd_SectorErase;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FTFE_FCCOB1 = (uint8_t)(FlashPtr &amp;gt;&amp;gt; 16);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FTFE_FCCOB2 = (uint8_t)((FlashPtr &amp;gt;&amp;gt; 8) &amp;amp; 0xFF);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FTFE_FCCOB3 = (uint8_t)(FlashPtr &amp;amp; 0xFF);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Execute the Flash write&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; SpSub();&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; /* checking access error */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (FTFE_FSTAT &amp;amp; FTFE_FSTAT_ACCERR_MASK)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* clear error flag */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FTFE_FSTAT |= FTFE_FSTAT_ACCERR_MASK;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* update return value*/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Return |= E_FLASH_FACCERR;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* checking protection error */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else if (FTFE_FSTAT &amp;amp; FTFE_FSTAT_FPVIOL_MASK)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* clear error flag */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FTFE_FSTAT |= FTFE_FSTAT_FPVIOL_MASK;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* update return value*/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Return |= E_FLASH_FPVIOL;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else if (FTFE_FSTAT &amp;amp; FTFE_FSTAT_RDCOLERR_MASK)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* clear error flag */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FTFE_FSTAT |= FTFE_FSTAT_RDCOLERR_MASK;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* update return value*/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Return |= E_FLASH_RDCOLERR;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* checking MGSTAT0 non-correctable error */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else if (FTFE_FSTAT &amp;amp; FTFE_FSTAT_MGSTAT0_MASK)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Return |= E_FLASH_MGSTAT0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; EnableInterrupts;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FTFE_FCNFG |= FTFE_FCNFG_RDCOLLIE_MASK;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* function return */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return&amp;nbsp; Return;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/**&lt;/P&gt;&lt;P&gt; * @brief&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Execute the Flash write while running out of SRAM&lt;/P&gt;&lt;P&gt; */&lt;/P&gt;&lt;P&gt;__attribute__ ((section(".mydata"))) void SpSub(void)&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Launch command */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FTFE_FSTAT |= FTFE_FSTAT_CCIF_MASK;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* wait for command completion */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; while (!(FTFE_FSTAT &amp;amp; FTFE_FSTAT_CCIF_MASK));&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;/* Leave this immediately after SpSub */&lt;/P&gt;&lt;P&gt;void SpSubEnd(void) {}&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Mar 2016 07:19:48 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Flash-erase-write-fails-after-deep-sleep-wakeup/m-p/508272#M31969</guid>
      <dc:creator>renjithks</dc:creator>
      <dc:date>2016-03-29T07:19:48Z</dc:date>
    </item>
    <item>
      <title>Re: Flash erase/write fails after deep sleep wakeup</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Flash-erase-write-fails-after-deep-sleep-wakeup/m-p/508273#M31970</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I don't know that this is related to your problem or not however not having the Interrupt Enable and Disable instructions marked as Volatile can result in hair pulling debugging sessions with some compilers as optimizer reorder code (Code Motion).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What I use for GCC:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#define ATTR_NO_INSTRUMENT_FUNCTION __attribute__( ( no_instrument_function ) )&lt;BR /&gt;/*&lt;/P&gt;&lt;P&gt; * This is the only method available in the ARMv6-M architecture&lt;/P&gt;&lt;P&gt; * (Cortex-M0/M0+)&lt;/P&gt;&lt;P&gt; *&lt;/P&gt;&lt;P&gt; * In normal applications there is no need to add any barrier&lt;/P&gt;&lt;P&gt; * instruction after using a CPS instruction to enable an interrupt.&lt;/P&gt;&lt;P&gt; *&lt;/P&gt;&lt;P&gt; * If an interrupt was already in the pending state, the processor&lt;/P&gt;&lt;P&gt; * accepts the interrupt after the “CPSIE I” is executed. However,&lt;/P&gt;&lt;P&gt; * additional instructions can be executed before the processor enters&lt;/P&gt;&lt;P&gt; * the exception handler:&lt;/P&gt;&lt;P&gt; *&lt;/P&gt;&lt;P&gt; *&amp;nbsp; For Cortex-M3 or Cortex-M4, the processor can execute up to TWO&lt;/P&gt;&lt;P&gt; *&amp;nbsp; additional instructions before entering the interrupt service&lt;/P&gt;&lt;P&gt; *&amp;nbsp; routine.&lt;/P&gt;&lt;P&gt; *&lt;/P&gt;&lt;P&gt; *&amp;nbsp; For Cortex-M0, the processor can execute up to ONE additional&lt;/P&gt;&lt;P&gt; *&amp;nbsp; instruction before entering the interrupt service routine.&lt;/P&gt;&lt;P&gt; *&lt;/P&gt;&lt;P&gt; */&lt;/P&gt;&lt;P&gt;static inline ATTR_NO_INSTRUMENT_FUNCTION void irq_enable( void )&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp; __asm__ __volatile__ ("cpsie i"); /* Clear PRIMASK */&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/*&lt;/P&gt;&lt;P&gt; * The CPSID instruction is self-synchronized to the instruction&lt;/P&gt;&lt;P&gt; * stream and there is no requirement to insert memory barrier&lt;/P&gt;&lt;P&gt; * instructions after CPSID.&lt;/P&gt;&lt;P&gt; */&lt;/P&gt;&lt;P&gt;static inline ATTR_NO_INSTRUMENT_FUNCTION void irq_disable( void )&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp; __asm__ __volatile__ ("cpsid i");&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Mar 2016 11:57:02 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Flash-erase-write-fails-after-deep-sleep-wakeup/m-p/508273#M31970</guid>
      <dc:creator>bobpaddock</dc:creator>
      <dc:date>2016-03-29T11:57:02Z</dc:date>
    </item>
    <item>
      <title>Re: Flash erase/write fails after deep sleep wakeup</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Flash-erase-write-fails-after-deep-sleep-wakeup/m-p/508274#M31971</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I could get the reason for failure, but couldn't fix the issue still. SCB_SFSR shows its an "instruction bus error" and SCB_BFAR shows the bus fault address as 0xe000edf8( debug core register DCRDR ). RDCOLERR is set in&amp;nbsp; FSTAT register at the hard fault.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am clearing FSTAT_CCIF to initiate the operation in RAM( SpSub ), and also wait there for completion before returning.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I tried to disable cache also, but even that didn't help.&lt;/P&gt;&lt;P&gt;FMC_PFB0CR &amp;amp;= 0xFFFFFFE0;&lt;/P&gt;&lt;P&gt;FMC_PFB1CR &amp;amp;= 0xFFFFFFE0;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Mar 2016 12:25:57 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Flash-erase-write-fails-after-deep-sleep-wakeup/m-p/508274#M31971</guid>
      <dc:creator>renjithks</dc:creator>
      <dc:date>2016-03-29T12:25:57Z</dc:date>
    </item>
    <item>
      <title>Re: Flash erase/write fails after deep sleep wakeup</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Flash-erase-write-fails-after-deep-sleep-wakeup/m-p/508275#M31972</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi RENJITH KS,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; How did you test it?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; If the K21 in the LLS mode, the Debugger will be disconnected.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Now I use your flash erase code in our KSDK1.3.0, and test it on my TWR-K21F120M board, after I wakeup from the LLS mode, then do the flash sector erase, and printf the according address data, I find the flash is erased correctly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Attached code is my test code, I just modify the &lt;A href="http://www.nxp.com/products/software-and-tools/run-time-software/kinetis-software-and-tools/development-platforms-with-mbed/software-development-kit-for-kinetis-mcus:KINETIS-SDK?tid=redKINETIS_SDK"&gt;KSDK1.3.0&lt;/A&gt; k21 code:C:\Freescale\KSDK_1.3.0\examples\twrk21f120m\demo_apps\power_manager_hal_demo&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Please check the ksdk1.3.0 code on your side at first!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you still have question with my code, please let me know~&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Have a great day,&lt;BR /&gt;Jingjing&lt;/P&gt;&lt;P&gt;&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>Wed, 30 Mar 2016 03:27:09 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Flash-erase-write-fails-after-deep-sleep-wakeup/m-p/508275#M31972</guid>
      <dc:creator>kerryzhou</dc:creator>
      <dc:date>2016-03-30T03:27:09Z</dc:date>
    </item>
  </channel>
</rss>

