K10 FlexNVM data flash write failure

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

K10 FlexNVM data flash write failure

Jump to solution
807 Views
michaelkonieczn
Contributor II

Chip in question: MK10DX256VLL7, mask 3N36B.

I have the following application: bootloader resides in bottom sectors of program flash, and these sectors are protected. All remaining program flash is used for downloadable firmware. All is working fine and dandy, proven in field, tested in battles.
I've previously configured FlexNVM/Flex RAM for EEPROM functionality, and used that quite successfully. It works, except one minor quirk regarding the initial value of FCFG1.EESIZE field (coverede here: K10 FlexMemory FCFG1 EESIZE initial value ). But my needs changed, and now I need to write bulk data to NVS, quite atomically, with versioning, etc. So the built-in EEPROM functionality isn't optimal anymore, and I roll my own, based on pages of FLASH.

But when trying to erase/write any data flash address, I get FSTAT.FPVIOL error. Looks like protection violation, but it's not protected - FDPROT is certainly all 1s. Both at special location in program FLASH @ 0x0_040F, and confirmed by FDPROT register readout. I also set FPROT and FEPROT to all 1s, just to be sure.

But nothing helps - still FPVIOL error. Using the same functions to erase/write flash that I use for bootloader/firmware programming. When I use data flash address = 0x1000_0000, I get the error. When I use any address within program flash, it executes properly. Temporarily I allocated 2 sectors of program flash for my configuraion data, but that's not optimal solution, as I shrink the firmware area, and there's dedicated unused data flash for this purpose.
I tried: chip out of mass erase - DEPART by default allocates all FlexNVM for data flash. I also tried explicitly calling Program Partition Command - partitioning it this or that way, it changes nothing.

My flash command routine executes from RAM, and includes: disabling interrupts, setting CCIF, waiting for CCIF, enabling interrupts. It works properly for all different calls, except when address lies within data flash. It still works, just returns FPVIOL. When using FLASH address that is not present (between program flash and data flash), it just hangs until watchdog kicks in. Program flash area - works fine. Data flash area - PFVIOL. So the behaviour is consistent.

Looks like some protection gets in the way, but what's wrong? All protection bits in Flash Configuration Field are disabled. When I selectively set some protection bits for program flash area, then write attempt fails as expected, for protected area.

What am I missing?

Labels (1)
0 Kudos
1 Solution
602 Views
michaelkonieczn
Contributor II

Problem solved.
Reading the manual for the N-th time, there's one sentence: "When required by the command, address bit 23 selects between program/data flash block". On earlier reading, I assumed that this bit just matches different base addresses for program/data flash blocks. As it seems, it's yet another bit in address that must be set when accessing data flash area, independent of all real address bits. Quite an odd requirement, but no one to blame, it's in the manual.

View solution in original post

0 Kudos
1 Reply
603 Views
michaelkonieczn
Contributor II

Problem solved.
Reading the manual for the N-th time, there's one sentence: "When required by the command, address bit 23 selects between program/data flash block". On earlier reading, I assumed that this bit just matches different base addresses for program/data flash blocks. As it seems, it's yet another bit in address that must be set when accessing data flash area, independent of all real address bits. Quite an odd requirement, but no one to blame, it's in the manual.

0 Kudos