<?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 Programming block 0 of Kinetis K20 in Kinetis Microcontrollers</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Programming-block-0-of-Kinetis-K20/m-p/1002622#M55933</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have to replace a bootloader (in-application!) placed in the first 1k of the first sector of a K20-flash.&amp;nbsp; It does not work with the ProcessorExpert libs (I still have to use) without colliding with the flash configuration fields. Programming of&amp;nbsp; all other flash works as planned.&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;Can anybody give me a workflow how to flash the first sector?&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;Thanks in advance&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;Wolfgang&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 04 Nov 2019 14:34:10 GMT</pubDate>
    <dc:creator>wolfgangdietz</dc:creator>
    <dc:date>2019-11-04T14:34:10Z</dc:date>
    <item>
      <title>Programming block 0 of Kinetis K20</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Programming-block-0-of-Kinetis-K20/m-p/1002622#M55933</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have to replace a bootloader (in-application!) placed in the first 1k of the first sector of a K20-flash.&amp;nbsp; It does not work with the ProcessorExpert libs (I still have to use) without colliding with the flash configuration fields. Programming of&amp;nbsp; all other flash works as planned.&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;Can anybody give me a workflow how to flash the first sector?&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;Thanks in advance&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;Wolfgang&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Nov 2019 14:34:10 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Programming-block-0-of-Kinetis-K20/m-p/1002622#M55933</guid>
      <dc:creator>wolfgangdietz</dc:creator>
      <dc:date>2019-11-04T14:34:10Z</dc:date>
    </item>
    <item>
      <title>Re: Programming block 0 of Kinetis K20</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Programming-block-0-of-Kinetis-K20/m-p/1002623#M55934</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;&lt;BR /&gt;I have used the following code in K20 (and K66) in-place boot-loader updating in uTasker based products. I am not sure what problems you have but this is a reference that has been used successfully and you may be able to replace its flash calls with whatever you have to do the same.&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;Beware that updating the first sector is risky since a power cycle during the process will leave the device in a state that can't recover.&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;Mark&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;Reference instructions - It can be called at any time but generally immediately after starting.&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;&lt;SPAN style="font-family: Courier New, Courier, monospace;"&gt;#include "serialArray.h"&lt;/SPAN&gt;&lt;BR /&gt; &lt;BR /&gt; &lt;SPAN style="font-family: Courier New, Courier, monospace;"&gt;static void fnUpdateSerialLoader(void)&lt;BR /&gt; {&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp; if (memcmp(serial_loader, fnGetFlashAdd((unsigned char *)0x00000000), sizeof(serial_loader)) != 0) { // if the loader in Flash is different to the one embedded in code&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; unsigned char *ptrFlashDestination;&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; unsigned char *ptrSerialLoader = serial_loader;&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (memcmp(serial_loader, fnGetFlashAdd((unsigned char *)0x00000000), _FLASH_GRANULARITY) != 0) { // check whether the first sector requires modifying&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _fnEraseFlashSector((unsigned char *)0, _FLASH_GRANULARITY);&amp;nbsp; // delete first sector&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _fnWriteBytesFlash((unsigned char *)0x400, &amp;amp;serial_loader[0x400], 16); // program critical flash configuration&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _fnWriteBytesFlash((unsigned char *)0, &amp;amp;serial_loader[0], 0x400); // program start&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _fnWriteBytesFlash((unsigned char *)0x410, &amp;amp;serial_loader[0x410], (_FLASH_GRANULARITY - 0x410)); // program end&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ptrFlashDestination = (unsigned char *)_FLASH_GRANULARITY;&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ptrSerialLoader += _FLASH_GRANULARITY;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp; // after critical first sector has been programmed continue with the rest&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; while (ptrFlashDestination &amp;lt; (unsigned char *)(4 * 1024)) {&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // for each sector in the serial loader area&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _fnEraseFlashSector(ptrFlashDestination, _FLASH_GRANULARITY);// erase all boot loader sectors&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _fnWriteBytesFlash(ptrFlashDestination, ptrSerialLoader, _FLASH_GRANULARITY); // program sector&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ptrSerialLoader += _FLASH_GRANULARITY;&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ptrFlashDestination += _FLASH_GRANULARITY;&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR /&gt; }&lt;/SPAN&gt;&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;1. serialArray.h contains the new loader code to program:&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;serialArray.h can be created from the serial loader's binary file using&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;uTaskerFileCreate serialLoader.bin serialArray.h serial_loader&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;It assumes the input file is called serialLoader.bin&lt;BR /&gt;The output file is serialArray.h&lt;BR /&gt;and in this file an array is created&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;extern unsigned char serial_loader[] = {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0xXX, 0xYY, ... // filled out by conversion program&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ....&lt;BR /&gt;};&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;Details of the conversion program at &lt;A href="http://www.utasker.com/forum/index.php?topic=1445.0" target="test_blank"&gt;http://www.utasker.com/forum/index.php?topic=1445.0&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Nov 2019 22:25:28 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Programming-block-0-of-Kinetis-K20/m-p/1002623#M55934</guid>
      <dc:creator>mjbcswitzerland</dc:creator>
      <dc:date>2019-11-04T22:25:28Z</dc:date>
    </item>
    <item>
      <title>Re: Programming block 0 of Kinetis K20</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Programming-block-0-of-Kinetis-K20/m-p/1002624#M55935</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Mark,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;many thanks for your fast response.&lt;/P&gt;&lt;P&gt;It really seems to be quite easy, but unfortunately it doesn´t work.&lt;/P&gt;&lt;P&gt;Your three step  solution shows the same results as my one step approach: Nothing :smileyalert: has been flashed and the readout protection of the K20 is set afterwards.&lt;/P&gt;&lt;P&gt;As far as I could see   the Flash configuration fields and the  Flash Security Register, FTFE_FSEC, FTFE_FPROT etc,  are set correctly (no write protection etc.)  before starting and after programming step two (config fields) though nothing has been flashed.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there any other FTFE-reg I have to configure before?&lt;/P&gt;&lt;P&gt;Note: I still use (have to us)  the PE flash components Flash1_Write etc. which worked perfectly in the past.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Wolfgang&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Von: mjbcswitzerland &amp;lt;admin@community.nxp.com&amp;gt;&lt;/P&gt;&lt;P&gt;Gesendet: Montag, 4. November 2019 23:26&lt;/P&gt;&lt;P&gt;An: Wolfgang Dietz &amp;lt;w.dietz@medatec.com&amp;gt;&lt;/P&gt;&lt;P&gt;Betreff: Re:  - Re: Programming block 0 of Kinetis K20&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;NXP Community &amp;lt;https://community.freescale.com/resources/statics/1000/35400-NXP-Community-Email-banner-600x75.jpg&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Re: Programming block 0 of Kinetis K20&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;reply from Mark Butcher&amp;lt;https://community.nxp.com/people/mjbcswitzerland?et=watches.email.thread&amp;gt; in Kinetis Microcontrollers - View the full discussion&amp;lt;https://community.nxp.com/message/1227836?commentID=1227836&amp;amp;et=watches.email.thread#comment-1227836&amp;gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Nov 2019 13:03:37 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Programming-block-0-of-Kinetis-K20/m-p/1002624#M55935</guid>
      <dc:creator>wolfgangdietz</dc:creator>
      <dc:date>2019-11-05T13:03:37Z</dc:date>
    </item>
    <item>
      <title>Re: Programming block 0 of Kinetis K20</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Programming-block-0-of-Kinetis-K20/m-p/1002625#M55936</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Wolfgang&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;If the processor is secured after the operation it means that the flash configuration (from 0x400) is programmed with 0xff 0xff, ..&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;This happens when the first sector is erased but nothing is written before a reset is performed.&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;This usually happens when there is a 'crash' after the initial erase operation, which can be due to - for example - watchdog timeout taking place or interrupt not being disabled (and vectors in the first sector being required to handle them).&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;You should be able to use normal debug techniques to find out what happens after the erase is performed and before the new code is written.&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;Mark&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Nov 2019 18:40:23 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Programming-block-0-of-Kinetis-K20/m-p/1002625#M55936</guid>
      <dc:creator>mjbcswitzerland</dc:creator>
      <dc:date>2019-11-05T18:40:23Z</dc:date>
    </item>
    <item>
      <title>Re: Programming block 0 of Kinetis K20</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Programming-block-0-of-Kinetis-K20/m-p/1002626#M55937</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Mark,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thanks to your tips I found the cause of the problems,  even thought I could not yet clarify the background of the behavior due to time problems.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I used to test the steps by in-circuit-debugging and the procedure crashed always, probably by the debugger-internal interrupt-processing.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It works perfectly running the application without debugger.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Once again thanks!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Wolfgang&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;Von: mjbcswitzerland &amp;lt;admin@community.nxp.com&amp;gt;&lt;/P&gt;&lt;P&gt;Gesendet: Dienstag, 5. November 2019 19:41&lt;/P&gt;&lt;P&gt;An: Wolfgang Dietz &amp;lt;w.dietz@medatec.com&amp;gt;&lt;/P&gt;&lt;P&gt;Betreff: Re:  - Re: Programming block 0 of Kinetis K20&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;NXP Community &amp;lt;https://community.freescale.com/resources/statics/1000/35400-NXP-Community-Email-banner-600x75.jpg&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Re: Programming block 0 of Kinetis K20&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;reply from Mark Butcher&amp;lt;https://community.nxp.com/people/mjbcswitzerland?et=watches.email.thread&amp;gt; in Kinetis Microcontrollers - View the full discussion&amp;lt;https://community.nxp.com/message/1228361?commentID=1228361&amp;amp;et=watches.email.thread#comment-1228361&amp;gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Nov 2019 18:28:32 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Programming-block-0-of-Kinetis-K20/m-p/1002626#M55937</guid>
      <dc:creator>wolfgangdietz</dc:creator>
      <dc:date>2019-11-07T18:28:32Z</dc:date>
    </item>
  </channel>
</rss>

