<?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>Kinetis Software Development KitのトピックRe: SDK 2.0 FLASH_Erase causing core lockup</title>
    <link>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/SDK-2-0-FLASH-Erase-causing-core-lockup/m-p/483998#M4196</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for your answer &lt;SPAN style="color: #51626f; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;XiangJun ,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;At the moment, my code is actually working, and I'm experimenting to understand why - the code that I posted was not working when I posted it, but now seems to work for some reason.&amp;nbsp; I assume that I missed something which I later fixed while experimenting.&amp;nbsp; I have found that disabling interrupts with __disable_irq(); is the only way to make it work, none of the other methods do (&lt;/SPAN&gt;taskENTER_CRITICAL(),&amp;nbsp; taskDISABLE_INTERRUPTS(), portDISABLE_INTERRUPTS()).&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regarding your suggestion, I have disabled interrupts, so if I understand correctly, the RTOS scheduler cannot run until the Flash operation is complete, which is fine - it seems to take about 7.6 ms to do the sector erase, during which time interrupts are disabled.&amp;nbsp; In my application I can tolerate that, as the flash writes will only happen during initial setup of the product and not while running in the field.&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your suggested change would apply in my case to a piece of code which is #ifdef'ed out by the macro FLASH_DRIVER_IS_FLASH_RESIDENT being #defined.&amp;nbsp; The same while loop also appears in the RAM copy of that function, flash_run_command() - in that case, would not calling &lt;SPAN style="color: #51626f; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;vTaskDelay() execute code from Flash, which is the thing I'm trying avoid?&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks again for spending time thinking about this.&amp;nbsp; When I'm more confident in what's making it work, I'll post a more complete answer.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Chris&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 20 May 2016 17:21:50 GMT</pubDate>
    <dc:creator>cwpaynter</dc:creator>
    <dc:date>2016-05-20T17:21:50Z</dc:date>
    <item>
      <title>SDK 2.0 FLASH_Erase causing core lockup</title>
      <link>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/SDK-2-0-FLASH-Erase-causing-core-lockup/m-p/483996#M4194</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am using KSKD 3.0, with SDK 2.0 to run a FREERtos project on a standalone board with a MK22FN256VLL12 on it.&lt;/P&gt;&lt;P&gt;During the initialization, before the RTOS is started with vTaskStartScheduler(), I am able to erase and write to the last couple of sectors of Flash with the following code:&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 8pt;"&gt;uint32_t try_flash_erase_in_rtos( void )&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 8pt;"&gt;{&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; uint32_t destAdrss = SETTINGS_0_START;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; status_t&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; result;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (!nv_initialized) {&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NVInit();&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; nv_initialized = 1;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // try disabling interrupts&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // taskENTER_CRITICAL();&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // taskDISABLE_INTERRUPTS();&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; __disable_irq();&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // erase sector before trying to write (can only write 0 bits, not 1)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; result = FLASH_Erase(&amp;amp;flashDriver, destAdrss, FSL_FEATURE_FLASH_PFLASH_BLOCK_SECTOR_SIZE, kFLASH_apiEraseKey);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (kStatus_FLASH_Success != result)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return FALSE;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // taskENABLE_INTERRUPTS();&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // portENABLE_INTERRUPTS();&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // taskEXIT_CRITICAL();&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; __enable_irq();&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; __disable_irq();&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; flash_security_state_t securityStatus;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; result = FLASH_GetSecurityState(&amp;amp;flashDriver, &amp;amp;securityStatus);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // now write the struct to the flash&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; result = FLASH_Program(&amp;amp;flashDriver, destAdrss, (uint32_t *)&amp;amp;SystemSettings, sizeof(SystemSettings));&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; uint32_t failAddr, failDat;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; result = FLASH_VerifyProgram(&amp;amp;flashDriver, destAdrss, sizeof(SystemSettings), (uint32_t *)&amp;amp;SystemSettings, kFLASH_marginValueUser, &amp;amp;failAddr, &amp;amp;failDat);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; __enable_irq();&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (kStatus_FLASH_Success != result) {&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return FALSE;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return TRUE;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 8pt;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, if I try to execute that code from inside a running task, The call to FLASH_Erase() causes a core lockup and restarts my program.&amp;nbsp; If I manually erase the whole chip first, and comment out the call to FLASH_Erase(), the call to FLASH_Write() works fine with no reset, and actually does program the flash. &lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;From tracing through the SDK code, it appears that the flash-erasing code is copied to RAM, so I don't think it's an issue of writing to flash while running code from it.&amp;nbsp; I'm also disabling interrupts, so I don't think I'm getting any unwanted execution of ISR code from Flash.&amp;nbsp; I did see a reference to resetting the flash cache, but there is at least some mention of the cache in the call to the RAM function, so I'm assuming it's addressed...&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;much thanks for any suggestions.&amp;nbsp;&amp;nbsp; Chris&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;BTW, the clock configuration is taken directly from the SDK flash demo code; core clock is 80 MHz, flash clock is 20 MHz, running in PEE mode.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 May 2016 22:14:25 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/SDK-2-0-FLASH-Erase-causing-core-lockup/m-p/483996#M4194</guid>
      <dc:creator>cwpaynter</dc:creator>
      <dc:date>2016-05-19T22:14:25Z</dc:date>
    </item>
    <item>
      <title>Re: SDK 2.0 FLASH_Erase causing core lockup</title>
      <link>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/SDK-2-0-FLASH-Erase-causing-core-lockup/m-p/483997#M4195</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, Chris,&lt;/P&gt;&lt;P&gt;Regarding your question, I have checked the flash erase code, it uses the polling mode to check if the erasing operation is over or not.&lt;/P&gt;&lt;P&gt;status_t FLASH_Erase(flash_config_t *config, uint32_t start, uint32_t lengthInBytes, uint32_t key)&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt; .....&lt;/P&gt;&lt;P&gt;flash_command_sequence(config);&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;flash_command_sequence(flash_config_t *config)&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;....&lt;/P&gt;&lt;P&gt;while (!(FTFx-&amp;gt;FSTAT &amp;amp; FTFx_FSTAT_CCIF_MASK))&lt;/P&gt;&lt;P&gt;{}&lt;/P&gt;&lt;P&gt;....&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;I suppose that the RTOS scheduler will stick to the while() loop, can not schedule the other task. I suggest you add the task delay function so that the FLASH_Erase() function can give up the control and block itself. you can change the code as following.&lt;/P&gt;&lt;P&gt;flash_command_sequence(flash_config_t *config)&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;while (!(FTFx-&amp;gt;FSTAT &amp;amp; FTFx_FSTAT_CCIF_MASK))&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;vTaskDelay(1000us);&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;This is my guess, pls have a try.&lt;/P&gt;&lt;P&gt;BR&lt;/P&gt;&lt;P&gt;XiangJun Rong&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 May 2016 08:09:06 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/SDK-2-0-FLASH-Erase-causing-core-lockup/m-p/483997#M4195</guid>
      <dc:creator>xiangjun_rong</dc:creator>
      <dc:date>2016-05-20T08:09:06Z</dc:date>
    </item>
    <item>
      <title>Re: SDK 2.0 FLASH_Erase causing core lockup</title>
      <link>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/SDK-2-0-FLASH-Erase-causing-core-lockup/m-p/483998#M4196</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for your answer &lt;SPAN style="color: #51626f; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;XiangJun ,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;At the moment, my code is actually working, and I'm experimenting to understand why - the code that I posted was not working when I posted it, but now seems to work for some reason.&amp;nbsp; I assume that I missed something which I later fixed while experimenting.&amp;nbsp; I have found that disabling interrupts with __disable_irq(); is the only way to make it work, none of the other methods do (&lt;/SPAN&gt;taskENTER_CRITICAL(),&amp;nbsp; taskDISABLE_INTERRUPTS(), portDISABLE_INTERRUPTS()).&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regarding your suggestion, I have disabled interrupts, so if I understand correctly, the RTOS scheduler cannot run until the Flash operation is complete, which is fine - it seems to take about 7.6 ms to do the sector erase, during which time interrupts are disabled.&amp;nbsp; In my application I can tolerate that, as the flash writes will only happen during initial setup of the product and not while running in the field.&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your suggested change would apply in my case to a piece of code which is #ifdef'ed out by the macro FLASH_DRIVER_IS_FLASH_RESIDENT being #defined.&amp;nbsp; The same while loop also appears in the RAM copy of that function, flash_run_command() - in that case, would not calling &lt;SPAN style="color: #51626f; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;vTaskDelay() execute code from Flash, which is the thing I'm trying avoid?&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks again for spending time thinking about this.&amp;nbsp; When I'm more confident in what's making it work, I'll post a more complete answer.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Chris&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 May 2016 17:21:50 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/SDK-2-0-FLASH-Erase-causing-core-lockup/m-p/483998#M4196</guid>
      <dc:creator>cwpaynter</dc:creator>
      <dc:date>2016-05-20T17:21:50Z</dc:date>
    </item>
    <item>
      <title>Re: SDK 2.0 FLASH_Erase causing core lockup</title>
      <link>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/SDK-2-0-FLASH-Erase-causing-core-lockup/m-p/483999#M4197</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;OK, everything's working well now.&amp;nbsp; Working code is pasted below.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Originally I started with the flash_erase_program_verify sample code for the FRDMK22F dev board, and it's pretty straightforward.&amp;nbsp; Problems come up when:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;I moved to the smaller &lt;SPAN style="color: #51626f; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;MK22FN256VLL12 &lt;/SPAN&gt;processor, which has only one block of flash.&amp;nbsp; The dev board has two, so the demo code runs from block 0, and the sectors which are read and written are in block 1, so you don't get Read-While-Write errors. &lt;/LI&gt;&lt;LI&gt;I employed the sample code in a FREERtos task, where interrupts are flying, including a bunch of my own.&amp;nbsp; Again, the larger chip on the dev board would have been fine, 'cause the ISRS would have been in block 0, and writes to block 1. &lt;/LI&gt;&lt;LI&gt;For some reason, if I don't disable interrupts during the flash verify operations, I still get the core lockup.&amp;nbsp; I would have thought that was a read-only operation for flash, so no conflict, but there you go. &lt;/LI&gt;&lt;LI&gt;None of the interrupt disable mechanisms I tried prevented the core lockup until I found a reference to the low level __disable_irq() calls.&amp;nbsp; Calling taskENTER_CRITICAL(),&amp;nbsp; taskDISABLE_INTERRUPTS(), portDISABLE_INTERRUPTS(), none of those prevented the core lockup.&amp;nbsp; &lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; &lt;SPAN style="font-size: 8pt; font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp; // erase sector before trying to write (can only write 0 bits, not 1).&amp;nbsp; Note that ALL interrupts&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // are disabled, because FLASH_Erase() needs to copy some code into RAM and run there with&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // no read access to Flash (i.e ISRs) wile the erase operation is going on.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; __disable_irq();&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; result = FLASH_Erase(&amp;amp;flashDriver, destAdrss, FSL_FEATURE_FLASH_PFLASH_BLOCK_SECTOR_SIZE, kFLASH_apiEraseKey);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; __enable_irq();&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (kStatus_FLASH_Success != result)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return ERASE_FAILED;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: 'courier new', courier;"&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-size: 8pt; font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // make sure we actually managed to erase the sector&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; __disable_irq();&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; result = FLASH_VerifyErase(&amp;amp;flashDriver, destAdrss, FSL_FEATURE_FLASH_PFLASH_BLOCK_SECTOR_SIZE, kFLASH_marginValueUser);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; __enable_irq();&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (kStatus_FLASH_Success != result) {&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return ERASE_FAILED;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: 'courier new', courier;"&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-size: 8pt; font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // now write the struct to the flash - interrupts disabled again to prevent any read access to flash while writing.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Note that the write size needs to be a multiple of 8 bytes.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; __disable_irq();&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; result = FLASH_Program(&amp;amp;flashDriver, destAdrss, (uint32_t *)&amp;amp;SystemSettings, sizeof(SystemSettings));&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; __enable_irq();&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (kStatus_FLASH_Success != result) {&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return WRITE_FAILED;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: 'courier new', courier;"&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-size: 8pt; font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // verify the write&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; __disable_irq();&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; result = FLASH_VerifyProgram(&amp;amp;flashDriver, destAdrss, sizeof(SystemSettings), (uint32_t *)&amp;amp;SystemSettings, kFLASH_marginValueUser, &amp;amp;failAddr, &amp;amp;failDat);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; __enable_irq();&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (kStatus_FLASH_Success != result) {&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return WRITE_FAILED;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 May 2016 22:58:15 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/SDK-2-0-FLASH-Erase-causing-core-lockup/m-p/483999#M4197</guid>
      <dc:creator>cwpaynter</dc:creator>
      <dc:date>2016-05-20T22:58:15Z</dc:date>
    </item>
  </channel>
</rss>

