Wednesday, July 27, 2011

Data read from Kinetis K60 Flash is inconsistent

Problem:
When data is written to the Flash in the Kinetis K60 controller and the data is read through the program, the read data differs from the actual data written to the Flash. But, the data is intact when reading through the debugger. The contents of the flash memory seems to be corrupted/inconsistent.

Solution:
Though there is no separate cache in Kinetis K60, the Flash alone has prefetch functionality enabled and caching enabled. This causes this problem. To make sure, disable all cache, prefetch and single entry buffer as follows:


    uint32 temp_reg;

    temp_reg = FMC_PFAPR;    /* store present value of FMC_PFAPR */
    FMC_PFAPR = 0x00ff0000; /* Disable prefetch temporarily */

    FMC_PFB0CR &= ~0x00080000;
    FMC_PFB1CR &=  ~0x00080000;

    FMC_PFB0CR &= ~0x0000001f;
    FMC_PFB1CR &= ~0x0000001f;

    FMC_PFAPR = temp_reg;    /* re-store original value of FMC_PFAPR */

Have great embedded computing!

No comments: