The Freedom-K64F is an ultra-low-cost development platform for Kinetis K64, K63, and K24 MCUs.

Anyone know how to K64F Flash programming ?

29 Sep 2014

Hi there

I am looking for a way to write the flash memory of K64F from the program.

FlexRAM seems to good but I can not find out good sample and application note.

Anyone know application notes or sample programs?

29 Sep 2014
29 Sep 2014

I haven't checked it on the K64F, but this should work on it too to write to the flash memory: https://mbed.org/users/Sissors/code/FreescaleIAP/

29 Sep 2014

I believe Erik is right, his library should work for K64F. Please share if yo utest it. Thanks.

Regards,
0xc0170

29 Sep 2014

Thank you everyone.

Erik - wrote:

I haven't checked it on the K64F, but this should work on it too to write to the flash memory: https://mbed.org/users/Sissors/code/FreescaleIAP/

It is very good. I will try immediately.

Martin Kojtal wrote:

I believe Erik is right, his library should work for K64F. Please share if yo utest it. Thanks.

yes. I will report test result.

Thanks

30 Sep 2014

I was successful in writing in the flash in K64F.

However, modifications were needed.

1.Define FTFE

K64F has not FTFA and FTFL. Must use the FTFE.

#ifdef TARGET_K64F
#   include "MK64F12.h"
#   define FTFA                        FTFE
#   define FTFA_FSTAT_FPVIOL_MASK      FTFE_FSTAT_FPVIOL_MASK 
#   define FTFA_FSTAT_ACCERR_MASK      FTFE_FSTAT_ACCERR_MASK
#   define FTFA_FSTAT_RDCOLERR_MASK    FTFE_FSTAT_RDCOLERR_MASK
#   define FTFA_FSTAT_CCIF_MASK        FTFE_FSTAT_CCIF_MASK
#   define FTFA_FSTAT_MGSTAT0_MASK     FTFE_FSTAT_MGSTAT0_MASK
#else
//Different names used on at least the K20:
#   ifndef FTFA_FSTAT_FPVIOL_MASK
#       define FTFA                        FTFL
#       define FTFA_FSTAT_FPVIOL_MASK      FTFL_FSTAT_FPVIOL_MASK 
#       define FTFA_FSTAT_ACCERR_MASK      FTFL_FSTAT_ACCERR_MASK
#       define FTFA_FSTAT_RDCOLERR_MASK    FTFL_FSTAT_RDCOLERR_MASK
#       define FTFA_FSTAT_CCIF_MASK        FTFL_FSTAT_CCIF_MASK
#       define FTFA_FSTAT_MGSTAT0_MASK     FTFL_FSTAT_MGSTAT0_MASK
#   endif
#endif

2.Add "ProgramPhrase" command and change the code to 64 bit unit.

K64F has not ProgramLongword. It is necessary to use the ProgramPhrase instead.

enum FCMD
{
    Read1s = 0x01,
    ProgramCheck = 0x02,
    ReadResource = 0x03,
    ProgramLongword = 0x06,
    ProgramPhrase = 0x07,
    EraseSector = 0x09,
    Read1sBlock = 0x40,
    ReadOnce = 0x41,
    ProgramOnce = 0x43,
    EraseAll = 0x44,
    VerifyBackdoor = 0x45
};

IAPCode program_flash(int address, char *data, unsigned int length) {
    #ifdef IAPDEBUG
    printf("IAP: Programming flash at %x with length %d\r\n", address, length);
    #endif
    if (check_align(address))
        return AlignError;
        
    IAPCode eraseCheck = verify_erased(address, length);
    if (eraseCheck != Success)
        return eraseCheck;
    
    IAPCode progResult;
#ifdef TARGET_K64F
    for (int i = 0; i < length; i+=8) {
        progResult = program_word(address + i, data + i);
        if (progResult != Success)
            return progResult;
    }
#else
    for (int i = 0; i < length; i+=4) {
        progResult = program_word(address + i, data + i);
        if (progResult != Success)
            return progResult;
    }
#endif
    
    return Success;
}

IAPCode program_word(int address, char *data) {
    #ifdef IAPDEBUG
    printf("IAP: Programming word at %x, %d - %d - %d - %d\r\n", address, data[0], data[1], data[2], data[3]);
    #endif
    if (check_align(address))
        return AlignError;
    
    //Setup command
#ifdef TARGET_K64F
    FTFA->FCCOB0 = ProgramPhrase;
    FTFA->FCCOB1 = (address >> 16) & 0xFF;
    FTFA->FCCOB2 = (address >> 8) & 0xFF;
    FTFA->FCCOB3 = address & 0xFF;
    FTFA->FCCOB4 = data[3];
    FTFA->FCCOB5 = data[2];
    FTFA->FCCOB6 = data[1];
    FTFA->FCCOB7 = data[0];
    FTFA->FCCOB8 = data[7];
    FTFA->FCCOB9 = data[6];
    FTFA->FCCOBA = data[5];
    FTFA->FCCOBB = data[4];
#else
    FTFA->FCCOB0 = ProgramLongword;
    FTFA->FCCOB1 = (address >> 16) & 0xFF;
    FTFA->FCCOB2 = (address >> 8) & 0xFF;
    FTFA->FCCOB3 = address & 0xFF;
    FTFA->FCCOB4 = data[3];
    FTFA->FCCOB5 = data[2];
    FTFA->FCCOB6 = data[1];
    FTFA->FCCOB7 = data[0];
#endif
    
    run_command();
    
    return check_error();
}

Write size is 64bit, but FreescaleIAP worked by this patch.

30 Sep 2014

Why can't Freescale stick to their names for once :/. They just insist on changing it all the time.

Anyway nice you figured it out, I will also have another look at it later.

Edit: So I assumed the KSDK targets (K22F and K64F currently for mbed), would have the same flash module. I was wrong. According to the reference manual the K22F should work fine with the current code since it does have program longword, but indeed the K64F does not have it.

I am going to add you to the developers of the library. That way can you commit your changes, and then publish them? (It will ask if you want to fork, and that should not be needed, you can directly modify them).

30 Sep 2014

Well the K22F looks to be fairly similar to the K20, at least same sector size and they both support ProgramLongword. Sadly my K22F is refusing to do anything besides returning access errors. So got to figure out why it hates me.

30 Sep 2014

Erik Olieman-san,

Thank you for add me to developer. I published patched code. I could not test other board so I do not have a non-K64F board.

My product is in C language, so I want to convert it to C and import it to the program. I want to use IAP source code with apache2 license.Would you allow it?

I was not able to make the base code of the IPA of Freescale.

Thank you for the making the library.

30 Sep 2014

Hey,

Your patch looks good, shouldn't affect other targets. And since it is effectively just C code, converting it to that should be easy enough.

You (and others) may use it for your product freely. I enabled the tickbox for Apache license in for the library. I believe technically I should put it on every document of my code, but I consider that too much work :).

02 Oct 2014

Erik-san,

Thank you for reply.

Thanks to you, My program was able to support the FRDM-K64F.

Import programmbedJS

This is a Json-RPC/2.0 server with websocket and httpd. You can control mbed(s) by Javascript, processing, Java. LPCXpresso1769/LPC1768/FRDM-K64F/LPC4088

This is a single-chip high speed WebsocketRPC server. Please try it if you will get K64F board.

02 Oct 2014

Hey Ryo Iizuka,

That seems like an impressive piece of code. I will certainly check it out once I got a K64F (which is in the pipeline).

Erik

12 Feb 2015

Anyone know how to read from internal flash? Sorry I have no idea how can implement it.

-deleted-
26 Mar 2015