FlexNVM Dflash Read issue on K64FX512

Showing results for 
Search instead for 
Did you mean: 

FlexNVM Dflash Read issue on K64FX512

Contributor II

K64FX family includes a FLEXNVM and FLEXRAM. 

I tried to write and read the FLEXNVM flash, I assessed and programmed  the piece of space of flash, 

Before program it, I erase  a section space and assign it from address 0x1001f00 to 0x10020000.

Writing data values are 1, 2, 3,..., 32 and data size is 32 into flash. 

It should be address 0x1001f00 is 0x01, 0x1001f001 is 0x02,.., 0x1001f07c is 0x1f.

I read the flash directly and code is show below,

destAdrss  = 0x1001f00 ;

/* Verify programming by reading back from flash directly*/
for (uint32_t i = 0; i < 32; i++)
    s_buffer_rbc = *(volatile uint32_t *)(destAdrss + i * 4);

   PRINTF("addr: %x, s_buffer_rb: %x, s_buffer: %x\r\n", (destAdrss + i * 4), s_buffer_rbc, s_buffer[i]);

Unfortunately, I get wrong reading back ..... The top 8 bytes is correct, after  8rd is wrong and the value is 0xffffffff.


What is the wrong in my code?

---- PROGRAM STARTing ----
FLEXNVM Example Start
FlexNMV DFlash Information:
FLEXNVM DflashBlock Base Address: 0x10000000
FLEXNVM Dflash Size: 128 KB (0x20000)

nFLEXNVM Dflash Sector Size: 4 KB (0x1000)
Flash is UNSECURE!
Erase a sector from address: (0x1001f000)
Successfully Erased Sector 0x1001f000 -> 0x10020000
Program a buffer to a sector of flash
addr: 1001f000, s_buffer_rb: 0, s_buffer: 0
addr: 1001f004, s_buffer_rb: 1, s_buffer: 1
addr: 1001f008, s_buffer_rb: 2, s_buffer: 2
addr: 1001f00c, s_buffer_rb: 3, s_buffer: 3
addr: 1001f010, s_buffer_rb: 4, s_buffer: 4
addr: 1001f014, s_buffer_rb: 5, s_buffer: 5
addr: 1001f018, s_buffer_rb: 6, s_buffer: 6
addr: 1001f01c, s_buffer_rb: 7, s_buffer: 7
addr: 1001f020, s_buffer_rb: ffffffff, s_buffer: 8
addr: 1001f024, s_buffer_rb: ffffffff, s_buffer: 9
addr: 1001f028, s_buffer_rb: ffffffff, s_buffer: a
addr: 1001f02c, s_buffer_rb: ffffffff, s_buffer: b
addr: 1001f030, s_buffer_rb: ffffffff, s_buffer: c
addr: 1001f034, s_buffer_rb: ffffffff, s_buffer: d
addr: 1001f038, s_buffer_rb: ffffffff, s_buffer: e
addr: 1001f03c, s_buffer_rb: ffffffff, s_buffer: f
addr: 1001f040, s_buffer_rb: ffffffff, s_buffer: 10
addr: 1001f044, s_buffer_rb: ffffffff, s_buffer: 11
addr: 1001f048, s_buffer_rb: ffffffff, s_buffer: 12
addr: 1001f04c, s_buffer_rb: ffffffff, s_buffer: 13
addr: 1001f050, s_buffer_rb: ffffffff, s_buffer: 14
addr: 1001f054, s_buffer_rb: ffffffff, s_buffer: 15
addr: 1001f058, s_buffer_rb: ffffffff, s_buffer: 16
addr: 1001f05c, s_buffer_rb: ffffffff, s_buffer: 17
addr: 1001f060, s_buffer_rb: ffffffff, s_buffer: 18
addr: 1001f064, s_buffer_rb: ffffffff, s_buffer: 19
addr: 1001f068, s_buffer_rb: ffffffff, s_buffer: 1a
addr: 1001f06c, s_buffer_rb: ffffffff, s_buffer: 1b
addr: 1001f070, s_buffer_rb: ffffffff, s_buffer: 1c
addr: 1001f074, s_buffer_rb: ffffffff, s_buffer: 1d
addr: 1001f078, s_buffer_rb: ffffffff, s_buffer: 1e
addr: 1001f07c, s_buffer_rb: ffffffff, s_buffer: 1f

Labels (1)
0 Kudos
3 Replies

Contributor I

OK, so it looks like I've got to the bottom of this one.

The micro that I'm using (MKE18F512) has L1 cache enabled by default for the FlexNVM. So when reading after a write, the results were from the cache and not from the FlexNVM itself.

There are (at least) 2 ways to get the 'real' data after a write:

  • Disable the cache: I found this needed to be done for both the FlexNVM and Program flash, using the LMEM->PCCRMR register. This may, of course, have a performance impact on the application.
  • Call the L1CACHE_CleanInvalidateDCacheByRange function to force a read of the FlexNVM area rather than the cache.

Both of these methods worked for me.

I don't know if this is the case with your micro, chhsu0229@gmail.com‌, but I hope this helps.

0 Kudos

NXP TechSupport
NXP TechSupport

Hello Andy Hsu 


The core, crossbar switch, and bus masters can be clocked at a higher frequency than the flash clock, in order to read a correct value in the memory, some delays are needed.

I suggest you put a considerable delay between the writing and the reading. Please let me know your findings after putting the delay.


If you have more questions do not hesitate to ask me.

Best regards,


0 Kudos

Contributor I

Hi nxf54944‌,

I'm having a very similar problem with the MKE18F512 (on the TWR-KE18F eval board):

I've loaded and run the DFlash example from the SDK 2.7.0 (boards\twrke18f\driver_examples\flash\flexnvm_dflash) and all appears to run well. But this is only because the data being written to the FlexNVM area is not changing.

When I change the data, the erase, erase-verify, program and program-verify are all successful, but the direct read-back fails. When I read back the data directly from the FlexNVM area, the data still has the old values. But when I reset the processor, the new values are actually there!

As you suggested, I have left a huge delay between the writing and the reading (2000 ms), but this makes no difference.

Am I missing a command or function to 'reload' the FlexNVM area with the new data??

Thanks in advance.

0 Kudos