<?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のトピックRe: How do you write to flash on a K64f? What am I doing wrong?</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-do-you-write-to-flash-on-a-K64f-What-am-I-doing-wrong/m-p/995882#M55804</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;looked at iar and it looks really nice except.... im developing in linux, all my tools are linux based.&amp;nbsp; will looksee if it will work under wine :smileyhappy:&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 18 Nov 2019 18:32:36 GMT</pubDate>
    <dc:creator>mark4th</dc:creator>
    <dc:date>2019-11-18T18:32:36Z</dc:date>
    <item>
      <title>How do you write to flash on a K64f? What am I doing wrong?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-do-you-write-to-flash-on-a-K64f-What-am-I-doing-wrong/m-p/995855#M55777</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have read the documentation over and over and over and over and over.&amp;nbsp; I have looked at other peoples code to write to flash, none of which is suitable for my purposes (all C code and there is zero C code in my project) so I am implementing it myself in assembler.&amp;nbsp; I do not know what I am doing wrong but for every attempt to write or erase flash I get ACCERR. &lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;I will never use processor expert because this is one size fits all code and is HORRENDOUS.&amp;nbsp; It is also an impediment to understanding.&amp;nbsp; i do not ever click a "do this for me" easy button.&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;The ONLY initialization I do for the processor is to disable interrupts and the watchdog timer.&amp;nbsp; i have not attempted to modify clocks in any way.&amp;nbsp; I would be slightly annoyed if flash write access can only be done after some clock initialization because there is absolutely nothing what so ever that I can find in the documentation that suggests this is the case and as stated before, ive been over that documentation multiple times.&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;Both of the following functions result in ACCERR.&amp;nbsp; The call to ftfe_wait (not posted) initializes r7 to x040020000.&amp;nbsp; I have also tried to write each byte of the FCCOB registers individually with no change in the end result.&amp;nbsp; flash not modified and ACCERR.&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;ftfe_erase:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new, courier, monospace;"&gt;&amp;nbsp; str lr, [sp, #-4‌]!&lt;/SPAN&gt;&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new, courier, monospace;"&gt;&amp;nbsp; bl ftfe_wait&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; @ wait for previous command complete&lt;/SPAN&gt;&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new, courier, monospace;"&gt;&amp;nbsp; movs r0, #0x09&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @ erase sector from address 0x000000&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new, courier, monospace;"&gt;&amp;nbsp; str r0, [r7, FCCOB]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new, courier, monospace;"&gt;&amp;nbsp; movs r0, #CCIF&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @ run the command&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new, courier, monospace;"&gt;&amp;nbsp; strb r0, [r7, #FTFE_FSTAT]&lt;/SPAN&gt;&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new, courier, monospace;"&gt;&amp;nbsp; ldr pc, [sp], #4&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;SPAN style="font-family: courier new, courier, monospace;"&gt;ftfe_prog:&lt;BR /&gt;&amp;nbsp; str lr, [sp, #-4]!&lt;BR /&gt;&amp;nbsp; bl ftfe_wait&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; @ wait for previous command complete&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; mov r0, r5&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; @ r5 = destination address&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; lsl r0, r0, #8&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @ shift addres up 8 bits to make room for...&lt;BR /&gt;&amp;nbsp; adds r0, r0, #7&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @ program phrase&lt;BR /&gt;&amp;nbsp; str r0, [r7, FCCOB]&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; ldr r0, [r9], #4&lt;BR /&gt;&amp;nbsp; str r0, [r7, FCCOB + 4]&lt;BR /&gt;&amp;nbsp; ldr r0, [r9], #4&lt;BR /&gt;&amp;nbsp; str r0, [r7, FCCOB + 8]&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; movs r0, #CCIF&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @ run the command&lt;BR /&gt;&amp;nbsp; strb r0, [r7, #FTFE_FSTAT]&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; ldr pc, [sp], #4&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;SPAN style="font-family: courier new, courier, monospace;"&gt;P.S. these forums seem to be constructed in such a way as to make it as CLOSE to impossible for anyone to get any kind of help&amp;nbsp; I have NEVER seen any other forums that are this FREEEKING obfuscated to use.&amp;nbsp; WHERE IS THE FORUM FOR THE K64F !!!!!!!!!!!!!!!!!!&lt;/SPAN&gt;&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 02 Nov 2019 20:21:28 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-do-you-write-to-flash-on-a-K64f-What-am-I-doing-wrong/m-p/995855#M55777</guid>
      <dc:creator>mark4th</dc:creator>
      <dc:date>2019-11-02T20:21:28Z</dc:date>
    </item>
    <item>
      <title>Re: How do you write to flash on a K64f? What am I doing wrong?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-do-you-write-to-flash-on-a-K64f-What-am-I-doing-wrong/m-p/995856#M55778</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;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;You are writing the command/address in the wrong order.&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;For example, when erasing the first sector at 0x000000&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;it is not&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new, courier, monospace;"&gt;movs r0, #0x09&lt;/SPAN&gt;&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;but&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new, courier, monospace;"&gt;movs r0, #0x09000000&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;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>Mon, 04 Nov 2019 21:48:33 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-do-you-write-to-flash-on-a-K64f-What-am-I-doing-wrong/m-p/995856#M55778</guid>
      <dc:creator>mjbcswitzerland</dc:creator>
      <dc:date>2019-11-04T21:48:33Z</dc:date>
    </item>
    <item>
      <title>Re: How do you write to flash on a K64f? What am I doing wrong?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-do-you-write-to-flash-on-a-K64f-What-am-I-doing-wrong/m-p/995857#M55779</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ok my errors are all gone! yay!&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;but nothing gets erased, nothing gets programmed&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;im using a jlink edu to debug within KDS and have a memory window on 0x400 as i single step through the code.&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;If i try press F6 on my write_stuff_to_flash: function the debug session goes out to lunch.&amp;nbsp; ALL memory addresses show as zero, all registers show as zero and the disassembly shows at address -1 press the red square to abort deubg is TOTALLY not helpful.. is there a way to simply HALT the processor ?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Nov 2019 23:48:46 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-do-you-write-to-flash-on-a-K64f-What-am-I-doing-wrong/m-p/995857#M55779</guid>
      <dc:creator>mark4th</dc:creator>
      <dc:date>2019-11-04T23:48:46Z</dc:date>
    </item>
    <item>
      <title>Re: How do you write to flash on a K64f? What am I doing wrong?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-do-you-write-to-flash-on-a-K64f-What-am-I-doing-wrong/m-p/995858#M55780</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;update, had a slight oopts in my flash write code which is now fixed and the data is absolutely being written to flash.&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;i verified this using JLinkExe, connecting to the target and doing a mem8 dump on addres 0x0400 for 256 bytes... my data is there.&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;however, as i am single stepping through the code doing the actual writing the memory display of the data at 0x0400 never changes from 0xff ff ff ff ff.....&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;and as stated before, if i press F6 when the program counter points at my flash_write function to execute the entire function in one go rather than&amp;nbsp; single stepping every opcode therein the debug session goes totally out to lunch,&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;I can even set a breakpoint and click the RUN button, the breakpoint is never hit.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Nov 2019 00:06:26 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-do-you-write-to-flash-on-a-K64f-What-am-I-doing-wrong/m-p/995858#M55780</guid>
      <dc:creator>mark4th</dc:creator>
      <dc:date>2019-11-05T00:06:26Z</dc:date>
    </item>
    <item>
      <title>Re: How do you write to flash on a K64f? What am I doing wrong?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-do-you-write-to-flash-on-a-K64f-What-am-I-doing-wrong/m-p/995859#M55781</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;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;When programming in the same block of flash as the code is running in you need to execute the code from RAM instead.&lt;BR /&gt;Therefore you need to copy your code (in Flash) that is doing the flashing work into RAM (and create a Thumb call to it) and jump to it. Also you must ensure interrupts are blocked (unless all code that can be run as interrupts - including vector table - are in RAM).&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 this is not done it may work when single stepping since the Flash command is executed when the processor is stopped (and not needing to access Flash while the operation is still in progress) but it will fail if run normally. The flash is not available to the processor when it is being operated o and any attempt to access it by the processor causes a serious and non-recoverable fault....&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;To be exact, you just need to execute just the part that commands the operation and waits for its termination (which you are presently missing) from RAM. Below is (assembler) code that does it, as reference:&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;PRE class="language-c line-numbers"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;static&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;unsigned&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;short&lt;/SPAN&gt; fnFlashRoutine&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt;                               &lt;SPAN class="comment token"&gt;// to avoid potential compiler in-lining of the routine (removing position independency) the machine code is used directly&lt;/SPAN&gt;
    &lt;SPAN class="number token"&gt;0x2180&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;    &lt;SPAN class="comment token"&gt;// MOVS r1,#0x80 load the value 0x80 (command complete interrupt flag) to register r1&lt;/SPAN&gt;
    &lt;SPAN class="number token"&gt;0x7001&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;    &lt;SPAN class="comment token"&gt;// STRB r1,[r0,#0x00] write r1 (0x80) to the passed pointer location (r0)&lt;/SPAN&gt;
    &lt;SPAN class="number token"&gt;0x7801&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;    &lt;SPAN class="comment token"&gt;// LDRB r1,[r0,#0x00] read back from the same location to r1&lt;/SPAN&gt;
    &lt;SPAN class="number token"&gt;0x0609&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;    &lt;SPAN class="comment token"&gt;// LSLS r1,r1,#24 shift the register content by 24 bits to the left so that the command complete interrupt flag is at bit 31&lt;/SPAN&gt;
    &lt;SPAN class="number token"&gt;0xd5fc&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;    &lt;SPAN class="comment token"&gt;// BPL -4 if the command complete interrupt flag bit is '0' (register content is not negative value) branch back to read its value again&lt;/SPAN&gt;
    &lt;SPAN class="number token"&gt;0x4770&lt;/SPAN&gt;     &lt;SPAN class="comment token"&gt;// BX lr return from sub-routine&lt;/SPAN&gt;
&lt;SPAN class="punctuation token"&gt;}&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;which is called with&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;fnFlashRoutine((volatile unsigned char *)FLASH_STATUS_REGISTER);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // execute the command in flash&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;That is, with a pointer to the Flash status register in r0.&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 01:24:19 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-do-you-write-to-flash-on-a-K64f-What-am-I-doing-wrong/m-p/995859#M55781</guid>
      <dc:creator>mjbcswitzerland</dc:creator>
      <dc:date>2019-11-05T01:24:19Z</dc:date>
    </item>
    <item>
      <title>Re: How do you write to flash on a K64f? What am I doing wrong?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-do-you-write-to-flash-on-a-K64f-What-am-I-doing-wrong/m-p/995860#M55782</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;the part of the code doing the writing to flash is running from ram and writing data that is in ram into flash, the interrupts are also disabled and so is the wdt.&amp;nbsp; I can verify that the writes DO take place.&amp;nbsp; I just can not debug the overall project other other than single stepping the code that does the flash write - anywhere else, if there is a bl foo i can press F6 and run the entire foo function and break on the next opcode.&amp;nbsp; do that for any of the flash functions in ram and the debug session gets utterly lost in space, totally out to lunch.&amp;nbsp;&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;Also, single stepping the flash writes/erases does not show any changes in the memory display window. I can not see ANY changes what so ever to flash within the debugger but exeting back to shell and running JLinkExe i can do a memory dunp and the data is shown to have been written correctly.&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;I have not tried to just RUN the code and to hell with debugging it to check through JLinkExe if the complete flash write is successfull or not but if it is that is literally 1/10000000000 of what i need to debug.&amp;nbsp; i need to debug what happens AFTER the flash is written too and single stepping through 8k of flash writes 8 bytes at a time would be a nightmare,&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Nov 2019 02:09:56 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-do-you-write-to-flash-on-a-K64f-What-am-I-doing-wrong/m-p/995860#M55782</guid>
      <dc:creator>mark4th</dc:creator>
      <dc:date>2019-11-05T02:09:56Z</dc:date>
    </item>
    <item>
      <title>Re: How do you write to flash on a K64f? What am I doing wrong?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-do-you-write-to-flash-on-a-K64f-What-am-I-doing-wrong/m-p/995861#M55783</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;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;If the flashing code is running form SRAM there should be no problems but what doesn't look correct in your code is that you check for the flash being busy "before" starting the new command but you don't wait until the new command has completed "before returning". If you return to Flash based code before the flash operation has completed it will immediately crash (the flashing operations can take several us to several ms to complete)&amp;nbsp; - make sure also the wait code is in the SRAM and you don't return until the operation has terminated.&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;How the debugger displays flash content depends on how it is updating its window - to be sure one can command an update/refresh after modifying flash content so that it is synchronised.&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;Also, the K64 is probably using caching and so reading the Flash may return old cached values, meaning that the debugger has not seen that the content has changed because also the cache doesn't yet know that content has been modified. This can be overcome by invalidating the cache after each flash operation by writing the "invalidation flags" to FMC_PFB0CR (and FMC_PFB1CR if present).&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 12:00:34 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-do-you-write-to-flash-on-a-K64f-What-am-I-doing-wrong/m-p/995861#M55783</guid>
      <dc:creator>mjbcswitzerland</dc:creator>
      <dc:date>2019-11-05T12:00:34Z</dc:date>
    </item>
    <item>
      <title>Re: How do you write to flash on a K64f? What am I doing wrong?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-do-you-write-to-flash-on-a-K64f-What-am-I-doing-wrong/m-p/995862#M55784</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;First of all I would like to personally thank you for the help you have given, VERY much appreciated!&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;secondly... :smileyhappy:&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;All of the changes you suggested were already made last night but there are still some funky issues (see below sources).&amp;nbsp;&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;Im pasting the complete sources for this here not just snippets in case it is useful for others in the future.&amp;nbsp;&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;This code is included as a binary into a loader project which is very specific to my use case (so you make your own : ) which makes calls into this code via two pointers at the start of this code.&amp;nbsp; see sources&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;p.s. i know im only erasing 4k when my data is 16k ish ... this will be easy to fix :smileyhappy:&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-size: 12px; font-family: courier new, courier, monospace;"&gt;@ ramflash.s&amp;nbsp;&amp;nbsp; - functions to write flash data running from ram&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&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;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;@ ------------------------------------------------------------------------&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;@ the entire contents of this file are moved to ram. the only part that&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;@ actually needs to be in ram though is the ftfe_wait function&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&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;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;@ after assembly the .text section for this file is extracted to a&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;@ binary and then included into the loader build - at run time loader&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;@ will relocate this into its ram run-time address and make calls into it&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;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&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;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;.set FMC, 0x4001f000&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;.set PFB0CR, 4&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;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;.set FTFE, 0x40020000&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;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;.set FTFE_FSTAT,&amp;nbsp; 0x00&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @ flash status register&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;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;.set CCIF,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0x80&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @ command complete interrupt&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;.set RDCOLERR,&amp;nbsp;&amp;nbsp;&amp;nbsp; 0x40&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @ FTFE Read collision error&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;.set ACCERR,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0x20&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @ Flash access error&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;.set FPVOIL,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0x10&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @ Flash protection violation&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;.set MGSTAT0,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0x01&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @ Memory controller command complete status&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;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;.set FTFE_FCNFG,&amp;nbsp; 0x01&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @ flash configuration register&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;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;.set CCIE,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0x80&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @ command complete interrupt enable&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;.set RDCOLLIE,&amp;nbsp;&amp;nbsp;&amp;nbsp; 0x40&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @ read collision error interrupt enable&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;.set ERASAREQ,&amp;nbsp;&amp;nbsp;&amp;nbsp; 0x20&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @ erase all request&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;.set ERSSUSP,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0x10&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @ erase suspend&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;.set SWAP,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0x08&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @ swap&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;.set PFLSH,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0x04&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @ FTFE configuration&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;.set RAMRDY,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0x02&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @ ram ready&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;.set EERDY,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0x01&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @ ee ready&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;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;.set FTFE_SEC,&amp;nbsp;&amp;nbsp;&amp;nbsp; 0x02&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @ flash security&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;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;.set KEYEN,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0xC0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @ backdoor key security enable&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;.set MEEN,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0x30&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @ mass erase enable&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;.set FSLACC,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0x0c&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @ freescale failure analysis code&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;.set SEC,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0x03&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @ flash securithy&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;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;.set FTFE_FOPT,&amp;nbsp;&amp;nbsp; 0x03&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @ flash option register&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;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;.set FCCOB,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0x04&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @ flash common command object register&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;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&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;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;&amp;nbsp; .syntax unified&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;&amp;nbsp; .thumb&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;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;&amp;nbsp; .section .ramcode, "awx"&amp;nbsp; @ defined in the linker script&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;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;@ ------------------------------------------------------------------------&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;@ first two ints are pointers to the two functions that loader will call&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;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;&amp;nbsp; .int ftfe_prog&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @ write to flash&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;&amp;nbsp; .int ftfe_erase&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @ erase flash&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;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&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;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;@ start execution of command&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;@ wait for ftfe command to complete.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;@ invalidate cache (err... i think?)&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;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;ftfe_wait:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;&amp;nbsp; movs r0, #CCIF&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @ run the command&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;&amp;nbsp; strb r0, [r7, #FTFE_FSTAT]&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;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;0:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;&amp;nbsp; ldrb r6, [r7, #FTFE_FSTAT]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;&amp;nbsp; ands r6, r6, CCIF&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;&amp;nbsp; beq 0b&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; @ wait for command to complete&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;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;&amp;nbsp; @ if only the GNU assembler allowed me to construct a MASK from a set of&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;&amp;nbsp; @ BIT NAMES without i need to make use of the horrendous abomination of&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;&amp;nbsp; @ a C pre-processor I would not have to have magic numbers.&amp;nbsp; As soon as&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;&amp;nbsp; @ this project is complete i can throw every single GNU development tool&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;&amp;nbsp; @ in the trash where it belongs (at least for this target)&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;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;&amp;nbsp; movs r6, #0x70&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @ clear error status&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;&amp;nbsp; strb r6, [r7, #FTFE_FSTAT]&amp;nbsp;&amp;nbsp;&amp;nbsp; @ bad mojo to ignore potential erros&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;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;&amp;nbsp; movw r0, #:lower16:FMC&amp;nbsp;&amp;nbsp;&amp;nbsp; @ invalidate the cache (i think ?)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;&amp;nbsp; movt r0, #:upper16:FMC&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;&amp;nbsp; movs r1, #0x00f80000&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @ funny thing is, as soon as i added this bit&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;&amp;nbsp; ldr r2, [r0, PFB0CR]&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @ of code it was no longer needed. the flash&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;&amp;nbsp; orr r2, r2, r1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @ writes became instantly visible in the&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;&amp;nbsp; str r1, [r0, PFB0CR]&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @ debugger before i invalidate %&amp;amp;*U&amp;amp;#!&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;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;&amp;nbsp; bx lr&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;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;@ ------------------------------------------------------------------------&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;@ program 8 bytes from address pointed to by r5 to address r9&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;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;ftfe_prog:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;&amp;nbsp; str lr, [sp, #-4]!&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;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;&amp;nbsp; movw r7, #:lower16:FTFE&amp;nbsp;&amp;nbsp; @ also returns f7 = FTFE base&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;&amp;nbsp; movt r7, #:upper16:FTFE&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;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;&amp;nbsp; mov r0, r5&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; @ r5 = destination address&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;&amp;nbsp; add r0, r0, #0x07000000&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;&amp;nbsp; str r0, [r7, FCCOB]&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;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;&amp;nbsp; ldr r0, [r9], #4&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;&amp;nbsp; str r0, [r7, FCCOB + 4]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;&amp;nbsp; ldr r0, [r9], #4&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;&amp;nbsp; str r0, [r7, FCCOB + 8]&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;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;&amp;nbsp; bl ftfe_wait&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; @ run command&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;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;&amp;nbsp; ldr pc, [sp], #4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @ oooh i could do a tail call optimization !!&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;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&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;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;ftfe_erase:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;&amp;nbsp; str lr, [sp, #-4]!&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;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;&amp;nbsp; movw r7, #:lower16:FTFE&amp;nbsp;&amp;nbsp; @ also returns f7 = FTFE base&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;&amp;nbsp; movt r7, #:upper16:FTFE&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;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;&amp;nbsp; movs r0, 0x09000000&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @ erase sector 000000&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;&amp;nbsp; str r0, [r7, FCCOB]&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;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;&amp;nbsp; bl ftfe_wait&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;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;&amp;nbsp; ldr pc, [sp], #4&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;&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;There are still some funky things going on however because the ONLY way this code currently works is if i single step through all 16k of data being flashed... one opcode at a time *$^&amp;amp;($&amp;amp;!&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;If I execute these functions at full speed (pressing go or pressing f6) my entire debug session goes lost in space.&amp;nbsp; The same thing happens if i flash it then run it full tilt boogie from JLinkExe (set program counter and run).&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;&lt;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;Im thinking it must be getting stuck waiting on CCIF somehow?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Nov 2019 17:10:44 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-do-you-write-to-flash-on-a-K64f-What-am-I-doing-wrong/m-p/995862#M55784</guid>
      <dc:creator>mark4th</dc:creator>
      <dc:date>2019-11-05T17:10:44Z</dc:date>
    </item>
    <item>
      <title>Re: How do you write to flash on a K64f? What am I doing wrong?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-do-you-write-to-flash-on-a-K64f-What-am-I-doing-wrong/m-p/995863#M55785</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;/P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;P&gt;If you post a binary of your code that runs on a FRDM-K64F (if you use default clocking it will run on any board) I will be able to tell you what the problem is.&lt;BR /&gt;You will need to tell me the location of the routine&amp;nbsp;&lt;SPAN style="font-size: 12px; font-family: courier new, courier, monospace;"&gt;ftfe_wait&lt;/SPAN&gt; or the flash location of whatever code that calls the operation in question.&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 19:21:10 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-do-you-write-to-flash-on-a-K64f-What-am-I-doing-wrong/m-p/995863#M55785</guid>
      <dc:creator>mjbcswitzerland</dc:creator>
      <dc:date>2019-11-05T19:21:10Z</dc:date>
    </item>
    <item>
      <title>Re: How do you write to flash on a K64f? What am I doing wrong?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-do-you-write-to-flash-on-a-K64f-What-am-I-doing-wrong/m-p/995864#M55786</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;was going to put that together after I got home from work but crashed lol. ill see if i have the energy to do this tonight :smileyhappy:&lt;BR /&gt;tyvm!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 Nov 2019 14:36:58 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-do-you-write-to-flash-on-a-K64f-What-am-I-doing-wrong/m-p/995864#M55786</guid>
      <dc:creator>mark4th</dc:creator>
      <dc:date>2019-11-06T14:36:58Z</dc:date>
    </item>
    <item>
      <title>Re: How do you write to flash on a K64f? What am I doing wrong?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-do-you-write-to-flash-on-a-K64f-What-am-I-doing-wrong/m-p/995865#M55787</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a zip file with code that you can either build or use the pre-built binaries (elf) but my experience with debugging this code has made things far far far more frustrating.&amp;nbsp; i try single step the first few opcodes an d BOOM reset, out to lunch.&amp;nbsp; I try run then full speed and BOOM reset, out to lunch.&lt;/P&gt;&lt;P&gt;I comment them out and my flash erase still works but NOTHING is being written to flash any more.&amp;nbsp; Switched back to the actual project this is based on and im again having horrendous issues trying to debug the code.&amp;nbsp; Cant have the code to disable the WDT because that hozes the debug.&amp;nbsp; Erase works great but the damned programming is now failing here too.&lt;/P&gt;&lt;P&gt;why is this so damned difficult, i have NEVER in 30 years of embedded software had the problems im having with these horrendous development tools.&amp;nbsp; WHY would anyone want to use ANYTHING based off of eclipse and why would anyone with a conscience push such a tool on society :smileysad:&lt;/P&gt;&lt;P&gt;I have no idea what the hell is going on here, code i could run full speed over but not single step i cant do either with and its EXACTLY THE SAME OPCODES!!!&lt;/P&gt;&lt;P&gt;Where do i post my zip file ?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Nov 2019 07:17:11 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-do-you-write-to-flash-on-a-K64f-What-am-I-doing-wrong/m-p/995865#M55787</guid>
      <dc:creator>mark4th</dc:creator>
      <dc:date>2019-11-08T07:17:11Z</dc:date>
    </item>
    <item>
      <title>Re: How do you write to flash on a K64f? What am I doing wrong?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-do-you-write-to-flash-on-a-K64f-What-am-I-doing-wrong/m-p/995866#M55788</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please post a binary (not elf) together with the map file. I prefer not to build since often it may take hours to get a foreign project to build on a different system (due to paths and other unexpected things).&lt;/P&gt;&lt;P&gt;To post, do the following:&lt;/P&gt;&lt;P&gt;1. Activate the "Use advanced editor" option (top right of edit box)&lt;BR /&gt;2. Then you will see an "attach" menu where you can select your local files(s)&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;Mark&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Nov 2019 18:41:43 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-do-you-write-to-flash-on-a-K64f-What-am-I-doing-wrong/m-p/995866#M55788</guid>
      <dc:creator>mjbcswitzerland</dc:creator>
      <dc:date>2019-11-08T18:41:43Z</dc:date>
    </item>
    <item>
      <title>Re: How do you write to flash on a K64f? What am I doing wrong?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-do-you-write-to-flash-on-a-K64f-What-am-I-doing-wrong/m-p/995867#M55789</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;loader.bin and .map as requested.&amp;nbsp; &lt;/P&gt;&lt;P&gt;I cant tell now if my troubles are the jlink edu, the target or my own incompetence :/&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 09 Nov 2019 21:52:03 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-do-you-write-to-flash-on-a-K64f-What-am-I-doing-wrong/m-p/995867#M55789</guid>
      <dc:creator>mark4th</dc:creator>
      <dc:date>2019-11-09T21:52:03Z</dc:date>
    </item>
    <item>
      <title>Re: How do you write to flash on a K64f? What am I doing wrong?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-do-you-write-to-flash-on-a-K64f-What-am-I-doing-wrong/m-p/995868#M55790</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. The bin file doesn't match the map file - it is much too small. Post the .elf instead so that I can convert it to a bin file.&lt;/P&gt;&lt;P&gt;2. You have no flash configuration in your project. You should have 16 bytes at 0x400 to configure the security and other options. Your m_foo should start at 0x410 instead since it would otherwise give a random flash configuration which could, in the worst case, brick the processor forever.&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;Mark&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 Nov 2019 02:21:16 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-do-you-write-to-flash-on-a-K64f-What-am-I-doing-wrong/m-p/995868#M55790</guid>
      <dc:creator>mjbcswitzerland</dc:creator>
      <dc:date>2019-11-11T02:21:16Z</dc:date>
    </item>
    <item>
      <title>Re: How do you write to flash on a K64f? What am I doing wrong?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-do-you-write-to-flash-on-a-K64f-What-am-I-doing-wrong/m-p/995869#M55791</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sorry, when you asked for a bin file only i assumed you wanted only the .text section and thats what I posted, if you load that in at 0x8000 and set the program counter to 0x8000 that would give you my setup almost identically (other than you would need a sane flash config field of course : )&lt;/P&gt;&lt;P&gt;Anyway, see attached elf as requested, and again, tyvm, im going nuts here :smileyhappy:&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 Nov 2019 14:36:18 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-do-you-write-to-flash-on-a-K64f-What-am-I-doing-wrong/m-p/995869#M55791</guid>
      <dc:creator>mark4th</dc:creator>
      <dc:date>2019-11-11T14:36:18Z</dc:date>
    </item>
    <item>
      <title>Re: How do you write to flash on a K64f? What am I doing wrong?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-do-you-write-to-flash-on-a-K64f-What-am-I-doing-wrong/m-p/995870#M55792</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I tried generating the complete content from the .elf but it seems like there is nothing more than the .text section in the .elf as well.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So I added a reset vector and flash config and loaded the code to 0x8000, starting with PC set to 0x8000.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However this code cannot operate since it uses un-initialised registers and so crashes after a few instructions and doesn't get as far as trying to work with flashing code.&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 code that I see is (with my comments):&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new, courier, monospace;"&gt;LDR R2, [R4, #0x4] // load R2 with unitialise R4 (assume 0) + 4, which is the initial program counter if this were the reset vector in Flash - assume loads 0x8000.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new, courier, monospace;"&gt;LDR R3, [SP, 0x10] // load R3 with Spack pointer + 0x10. Value of SP is unknown and SRAM hasn't been initialied so the value in R3 is random (assume SP is at top of SRAM 0x20003000)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new, courier, monospace;"&gt;CMP R2, R3 // compare the initial program address with random value&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new, courier, monospace;"&gt;BEQ.N 0x8016 // possibly initialisation that allows flash or SRAM based initialisation&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new, courier, monospace;"&gt;MOVS R3, #16&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new, courier, monospace;"&gt;STRB.W R3, [R4, 0x22] //&amp;nbsp; store the random value in R3 to a flash address (PC + 0x22) - always provokes crash&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I expect that the entry point is not 0x8000 but somewhere else, whereby I find _start [0x80dc] in the map.&lt;/P&gt;&lt;P&gt;After trying this as entry point I also find code that uses random pointers and so crashes after a few instructions.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Do you have any more information about what needs to be done to allow the code to be used (eg. priming RAM or SP - which is the actual entry point?) or is there missing code?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It may be easiest in this case to post the complete project so nothing is missing.&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;Mark&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 Nov 2019 19:05:04 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-do-you-write-to-flash-on-a-K64f-What-am-I-doing-wrong/m-p/995870#M55792</guid>
      <dc:creator>mjbcswitzerland</dc:creator>
      <dc:date>2019-11-11T19:05:04Z</dc:date>
    </item>
    <item>
      <title>Re: How do you write to flash on a K64f? What am I doing wrong?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-do-you-write-to-flash-on-a-K64f-What-am-I-doing-wrong/m-p/995871#M55793</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;ok, now im very confused, the code you have at 0x8000 is not whats supposed to be there, do you have the debuggerr set to expect ARM object code or thumb2? the code is all thumb2&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;0x8000 should start wtih....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; cpsid i&lt;BR /&gt;&amp;nbsp; movw r1, #0x2000&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @ *** get rid of magic numbers&lt;BR /&gt;&amp;nbsp; movt r1, #0x4005&lt;BR /&gt;&amp;nbsp; movw r0, 0xc520&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @ disable watchdog timer&lt;BR /&gt;&amp;nbsp; strh r0, [r1, #14]&lt;BR /&gt;&amp;nbsp; movw r0, 0xd928&lt;BR /&gt;&amp;nbsp; strh r0, [r2, #14]&lt;BR /&gt;&amp;nbsp; movw r0, #0x1d2&lt;BR /&gt;&amp;nbsp; strh r0, [r2]&lt;BR /&gt;&amp;nbsp; b _start&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;or something very similar, i think i have done edits on that code since I sent it to you and this is what i have now.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;edit: just verified the elf I sent you by doing "arm-linux-eabi-objdum -D loader" and scrolling to the disassembly of 0x8000, I think you are interpreting thumb2 object code as though it were 32 bit arm code... (just a guess, not sure why your tools would do this though)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;edi2: attached zip with project sources and linker script and makefile&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 Nov 2019 19:21:02 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-do-you-write-to-flash-on-a-K64f-What-am-I-doing-wrong/m-p/995871#M55793</guid>
      <dc:creator>mark4th</dc:creator>
      <dc:date>2019-11-11T19:21:02Z</dc:date>
    </item>
    <item>
      <title>Re: How do you write to flash on a K64f? What am I doing wrong?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-do-you-write-to-flash-on-a-K64f-What-am-I-doing-wrong/m-p/995872#M55794</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I took a look and see various problems with the project that need to be solved to make it easily testable.&lt;BR /&gt;1. Concerning your watchdog unlock difficulties please read the start of page 34 of &lt;A href="http://www.utasker.com/docs/KINETIS/uTaskerV1.4_Kinetis_demo.pdf" target="test_blank"&gt;http://www.utasker.com/docs/KINETIS/uTaskerV1.4_Kinetis_demo.pdf&lt;/A&gt;&lt;BR /&gt;2. I get no main() in the binary and I think it is because your reset vector and flash parameters are being optimised out by the linker since they are not referenced by any other code. You need to ensure they are not optimised away by using the KEEP attribute. Eg.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new, courier, monospace;"&gt;&amp;nbsp; .vectors ALIGN(__Vector_segment_start__ , 4) :&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new, courier, monospace;"&gt;&amp;nbsp; {&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new, courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; __vector_table = .;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new, courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;KEEP(*(.vectors .vectors.*))&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new, courier, monospace;"&gt;&amp;nbsp; }&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This also explains why I don't have the code that you expect to be the first to run.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;3. I don't think you are putting the flash config anywhere so you need to ensure that they are in a similar sector at 0x400 that is not optimised out&lt;BR /&gt;4. I get no main code in the binary and that is why I can't start testing anything. If you solve the vector table being in the code it will also solve main being optimised out (since this will be referenced by the vector table).&lt;BR /&gt;5. As far as I see you need to load both code to the flash and also load code to SRAM so that the ram code can operate. This is possible using the debugger but is impractical for general testing and can't operate in a real situation. You need to put the RAM code into the source and then copy it to the SRAM location during run time for the main program.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Presently I can't actually test any operation.&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;Mark&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 Nov 2019 23:48:49 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-do-you-write-to-flash-on-a-K64f-What-am-I-doing-wrong/m-p/995872#M55794</guid>
      <dc:creator>mjbcswitzerland</dc:creator>
      <dc:date>2019-11-11T23:48:49Z</dc:date>
    </item>
    <item>
      <title>Re: How do you write to flash on a K64f? What am I doing wrong?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-do-you-write-to-flash-on-a-K64f-What-am-I-doing-wrong/m-p/995873#M55795</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;the problem is NOT that there are sections missing, i have a .vectors section and my flash config field IS at address 0x400.&amp;nbsp; The problem i believe is the crippled development tools I am forced to use.&amp;nbsp; My elf file contains a .text section with a load address of 0x400.&amp;nbsp; At this address is the flash config field.&amp;nbsp; This is followed by a bunch of 0xff bytes all the way up till 0x8000 where my actual code starts.&amp;nbsp; Following the .text section within the elf file is the .vectors section with a load address of 0x00. (out of order linking!)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Problem is these asinine tools REFUSE to backtrack in memory and burn .vectors AFTER .text has already been flashed so... .vectors is simply discarded silently.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have attached a new loader elf file with NO .vectors section but a .text section that starts at 0x00.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would ask here for an NXP representative to explain to me exactly why their tools refuse to flash out of order elf sections when NOBODY has ANY CONTROL what so ever over the LINK ORDER of any section but I doubt any representatives from NXP ever bother to chime in here when they have someone as helpful as you doing all their work for them for free :smileysad:&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 13 Nov 2019 05:35:20 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-do-you-write-to-flash-on-a-K64f-What-am-I-doing-wrong/m-p/995873#M55795</guid>
      <dc:creator>mark4th</dc:creator>
      <dc:date>2019-11-13T05:35:20Z</dc:date>
    </item>
    <item>
      <title>Re: How do you write to flash on a K64f? What am I doing wrong?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-do-you-write-to-flash-on-a-K64f-What-am-I-doing-wrong/m-p/995874#M55796</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi &lt;SPAN class=""&gt;&lt;A _jive_internal="true" data-content-finding="Community" data-userid="348429" data-username="mark4th@gmail.com" href="https://community.nxp.com/people/mark4th@gmail.com"&gt;Mark Manning&lt;/A&gt;&lt;/SPAN&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; So you meet the flash operation problem in the K64 chip?&lt;/P&gt;&lt;P&gt;&amp;nbsp; What's the detail K64 part number you are using now? Do you have tried the official SDK flash project which can be downloaded from this link:&lt;/P&gt;&lt;P&gt;&lt;A class="link-titled" href="https://mcuxpresso.nxp.com/en/welcome" title="https://mcuxpresso.nxp.com/en/welcome"&gt;Welcome | MCUXpresso SDK Builder&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I suggest you try the official SDK project at first, I don't recommend you use the PE tool, as I know, the PE tool won't updated in the future.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Have a great day,&lt;BR /&gt;Kerry&lt;/P&gt;&lt;P style="min- padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-------------------------------------------------------------------------------&lt;BR /&gt;Note:&lt;BR /&gt;- If this post answers your question, please click the "Mark Correct" button. Thank you!&lt;/P&gt;&lt;P style="min- padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;- We are following threads for 7 weeks after the last post, later replies are ignored&lt;BR /&gt; Please open a new thread and refer to the closed one, if you have a related question at a later point in time.&lt;BR /&gt;-------------------------------------------------------------------------------&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 13 Nov 2019 07:50:02 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-do-you-write-to-flash-on-a-K64f-What-am-I-doing-wrong/m-p/995874#M55796</guid>
      <dc:creator>kerryzhou</dc:creator>
      <dc:date>2019-11-13T07:50:02Z</dc:date>
    </item>
  </channel>
</rss>

