<?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 Microcontrollers中的主题 Flash Swap Crashing on Prepare</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Flash-Swap-Crashing-on-Prepare/m-p/646673#M39243</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;After I update my firmware, set swap state to Complete and reboot my K64F system runs fine showing swap state as Ready and running out of the appropriate block. When I then set swap state to Prepare 0x02 system crashes with SRS1 showing the LOCKUP bit set. This happens occasionally and am trying to understand why this is happening.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Reading the flash_demo_frdmk64f code, and comparing to AN4533 app note - I see one discrepancy right away.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;AN4533 4.1.1 First Swap states that if swap state is uninitialized, you:&lt;/P&gt;&lt;P&gt;(1) initialize the system (assume - PFlashSwapCtl set FTFx_SWAP_SET_INDICATOR_ADDR)&lt;/P&gt;&lt;P&gt;(2) Erase the nonactive (upper block) - in my case the upper 4K (PSWAP_INDICATOR + PFLASH_SIZE/2). My PSWAP_INDICATOR is set to 0x7F000.&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In flash_swap.c, the code does the following:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;(1) Erases BOTH the active and non-active block:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-size: 11px;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ret = FlashEraseSector(&amp;amp;flashSSDConfig,PSWAP_INDICATOR_ADDR + P_FLASH_SIZE/2, P_SECTOR_SIZE,g_FlashLaunchCommand);&lt;/P&gt;&lt;P style="font-size: 11px;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ret |= FlashEraseSector(&amp;amp;flashSSDConfig,PSWAP_INDICATOR_ADDR, P_SECTOR_SIZE,g_FlashLaunchCommand);&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;(2) Initializes the system&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="color: #4e9072; font-size: 11px;"&gt;/* after this call, swap state = UPDATE_ERS */&lt;/P&gt;&lt;P style="font-size: 11px;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ret = PFlashSwapCtl(&amp;amp;flashSSDConfig, PSWAP_INDICATOR_ADDR, FTFx_SWAP_SET_INDICATOR_ADDR, &amp;amp;currentSwapMode, &amp;amp;currentSwapBlock, &amp;amp;nextSwapBlock, g_FlashLaunchCommand);&lt;/P&gt;&lt;P style="font-size: 11px;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;SPAN style="color: #931a68;"&gt;if&lt;/SPAN&gt; ((FTFx_OK != ret)||(currentSwapMode!= FTFx_SWAP_UPDATE_ERASED))&lt;/P&gt;&lt;P style="font-size: 11px;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/P&gt;&lt;P style="font-size: 11px;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;SPAN style="color: #931a68;"&gt;return&lt;/SPAN&gt; ret;&lt;/P&gt;&lt;P style="font-size: 11px;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My questions -&amp;nbsp;&lt;/P&gt;&lt;P&gt;(1) Why does sample code erase the active block where PSWAP_INDICATOR is set?&lt;/P&gt;&lt;P&gt;(2) Why does sample code erase first then initialize?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;-Raj&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 26 Jan 2017 02:20:11 GMT</pubDate>
    <dc:creator>rajbatra</dc:creator>
    <dc:date>2017-01-26T02:20:11Z</dc:date>
    <item>
      <title>Flash Swap Crashing on Prepare</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Flash-Swap-Crashing-on-Prepare/m-p/646673#M39243</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;After I update my firmware, set swap state to Complete and reboot my K64F system runs fine showing swap state as Ready and running out of the appropriate block. When I then set swap state to Prepare 0x02 system crashes with SRS1 showing the LOCKUP bit set. This happens occasionally and am trying to understand why this is happening.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Reading the flash_demo_frdmk64f code, and comparing to AN4533 app note - I see one discrepancy right away.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;AN4533 4.1.1 First Swap states that if swap state is uninitialized, you:&lt;/P&gt;&lt;P&gt;(1) initialize the system (assume - PFlashSwapCtl set FTFx_SWAP_SET_INDICATOR_ADDR)&lt;/P&gt;&lt;P&gt;(2) Erase the nonactive (upper block) - in my case the upper 4K (PSWAP_INDICATOR + PFLASH_SIZE/2). My PSWAP_INDICATOR is set to 0x7F000.&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In flash_swap.c, the code does the following:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;(1) Erases BOTH the active and non-active block:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-size: 11px;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ret = FlashEraseSector(&amp;amp;flashSSDConfig,PSWAP_INDICATOR_ADDR + P_FLASH_SIZE/2, P_SECTOR_SIZE,g_FlashLaunchCommand);&lt;/P&gt;&lt;P style="font-size: 11px;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ret |= FlashEraseSector(&amp;amp;flashSSDConfig,PSWAP_INDICATOR_ADDR, P_SECTOR_SIZE,g_FlashLaunchCommand);&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;(2) Initializes the system&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="color: #4e9072; font-size: 11px;"&gt;/* after this call, swap state = UPDATE_ERS */&lt;/P&gt;&lt;P style="font-size: 11px;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ret = PFlashSwapCtl(&amp;amp;flashSSDConfig, PSWAP_INDICATOR_ADDR, FTFx_SWAP_SET_INDICATOR_ADDR, &amp;amp;currentSwapMode, &amp;amp;currentSwapBlock, &amp;amp;nextSwapBlock, g_FlashLaunchCommand);&lt;/P&gt;&lt;P style="font-size: 11px;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;SPAN style="color: #931a68;"&gt;if&lt;/SPAN&gt; ((FTFx_OK != ret)||(currentSwapMode!= FTFx_SWAP_UPDATE_ERASED))&lt;/P&gt;&lt;P style="font-size: 11px;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/P&gt;&lt;P style="font-size: 11px;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;SPAN style="color: #931a68;"&gt;return&lt;/SPAN&gt; ret;&lt;/P&gt;&lt;P style="font-size: 11px;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My questions -&amp;nbsp;&lt;/P&gt;&lt;P&gt;(1) Why does sample code erase the active block where PSWAP_INDICATOR is set?&lt;/P&gt;&lt;P&gt;(2) Why does sample code erase first then initialize?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;-Raj&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 26 Jan 2017 02:20:11 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Flash-Swap-Crashing-on-Prepare/m-p/646673#M39243</guid>
      <dc:creator>rajbatra</dc:creator>
      <dc:date>2017-01-26T02:20:11Z</dc:date>
    </item>
    <item>
      <title>Re: Flash Swap Crashing on Prepare</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Flash-Swap-Crashing-on-Prepare/m-p/646674#M39244</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I solved my issue and thought I'd share in case it's helpful to others or if people concur/disagree with my findings.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Reading the K64 Reference Manual, section 29.4.12.14 it states that :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;&lt;/P&gt;&lt;DIV class="" title="Page 715"&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;UL&gt;&lt;LI style="font-size: 14.000000pt;"&gt;&lt;P&gt;&lt;SPAN style="font-size: 14.000000pt;"&gt;0x01 (Initialize Swap System to UPDATE-ERASED State) - After verifying that the current swap state is UNINITIALIZED, and that &lt;STRONG&gt;both&lt;/STRONG&gt; phrases which will contain the swap indicators (located in each half of the Program flash memory within the relative double-phrase flash address provided) are &lt;STRONG&gt;erased&lt;/STRONG&gt;, &lt;/SPAN&gt;&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;and therefore I need to erase both blocks and do it first as it's verifying - hence the demo app appears to be what I should do.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This however, didn't help when I issued the Prepare command to the swap controller. This was answered by AN4695 as my system is running interrupts in the same block as 0x7F000. Note- my code is well below 0x7F000 but runs in the same block.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;DIV class="" title="Page 3"&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;P&gt;&lt;SPAN style="font-weight: bold; font-size: 16.000000pt;"&gt;2.2 Avoiding Read While Write violations: ISR code &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.000000pt;"&gt;If an interrupt occurs during a flash erase/program operation, the Read While Write restriction will be violated if the interrupt service routine (ISR) code is located in the same flash &lt;STRONG&gt;block&lt;/STRONG&gt; as the erase/program operation is occurring on. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.000000pt;"&gt;This situation can be avoided with three possible options: &lt;/SPAN&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI style="font-size: 10.000000pt;"&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.000000pt;"&gt;The first option is to disable/enable interrupts before/after the flash command operation. If interrupts are disabled, any &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.000000pt;"&gt;interrupt that occurs during the flash operation will be pending when interrupts are re-enabled. &lt;/SPAN&gt;&lt;/P&gt;&lt;/LI&gt;&lt;LI style="font-size: 10.000000pt;"&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.000000pt;"&gt;The second option is to ensure that the ISR code is never in the same block as in-software flash erase/programming is &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.000000pt;"&gt;performed. &lt;/SPAN&gt;&lt;/P&gt;&lt;/LI&gt;&lt;LI style="font-size: 10.000000pt;"&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.000000pt;"&gt;The third option is to relocate the expected ISR into RAM for the duration of the erase or program time. See &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: rgb(0.000000%, 0.000000%, 100.000000%); font-size: 10.000000pt;"&gt;Instructions for creating a RAM function &lt;/SPAN&gt;&lt;SPAN style="font-size: 10.000000pt;"&gt;for more details on how to create a RAM function. &lt;/SPAN&gt;&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So, I fenced the swap ctl function that sets system to prepare as follows:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-size: 11px;"&gt;&lt;STRONG&gt;INT_SYS_DisableIRQGlobal();&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="font-size: 11px;"&gt;&lt;/P&gt;&lt;P style="font-size: 11px;"&gt;&amp;nbsp; &amp;nbsp; error_code = PFlashSwapCtl(&amp;amp;_flash_ssd_config, PSWAP_INDICATOR_ADDR,&lt;/P&gt;&lt;P style="font-size: 11px;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mode, &amp;amp;swap_mode,&lt;/P&gt;&lt;P style="font-size: 11px;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;amp;current_running_block, &amp;amp;next_running_block,&lt;/P&gt;&lt;P style="font-size: 11px;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; _flash_launch_command);&lt;/P&gt;&lt;P style="font-size: 11px;"&gt;&lt;/P&gt;&lt;P style="font-size: 11px;"&gt;&amp;nbsp; &amp;nbsp;&lt;STRONG&gt; INT_SYS_EnableIRQGlobal();&lt;/STRONG&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think app note AN4533 should add these clarifications.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;-Raj&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 26 Jan 2017 22:57:13 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Flash-Swap-Crashing-on-Prepare/m-p/646674#M39244</guid>
      <dc:creator>rajbatra</dc:creator>
      <dc:date>2017-01-26T22:57:13Z</dc:date>
    </item>
  </channel>
</rss>

