I am working on a project where I would like to use the flexNVM on a MK10DX128VLH7 as flex EEEPROM.
I am testing with the code below on a K20 Tower board, which has a PK20DX256VLL7, also with 32KB of flexNVM that can be used for EEEPROM. My steps are as follows:
------------------------------------------------------------
status_t ret = FLASH_Init(&flashConfig); // This returns kStatus_success
uint32_t currentEESize;
ret = FLASH_GetProperty(&flashConfig,kFLASH_PropertyEepromTotalSize, ¤tEESize); // Returns kStatus_success
uint32_t currentDflashSize;
ret = FLASH_GetProperty(&flashConfig, kFLASH_PropertyDflashTotalSize, ¤tDflashSize); // Returns kStatus_success
// Now, currentEESize==0 and currentDflashSize==32768, and I want to change that.
// First, I read SIM->FCFG1, which should tell me the total flexNVM size and EEPROM size.
uint32_t fcfg1 = SIM->FCFG1;
------------------------------------------------------------
Here, fcfg1 = 0xff03_0f00, which I decode as follows:
NVMSIZE = 0xF, which is not defined in the reference manual
PFSIZE = 0xF, which is not defined in the reference manual
EESIZE = 0x3, which is the code for 2KB (the desired size I want).
DEPART = 0xF, which the FlexNVM Partition code section says means Reserved (32KB data flash, no EEPROM)
Next, I attempt to program the partition:
------------------------------------------------------------
uint32_t eepromDataSizeCode = 0x3;
uint32_t flexnvmPartitionCode = 0x3;
ret = FLASH_ProgramPartition(&m_flashConfig, kFLASH_PartitionFlexramLoadOptionLoadedWithValidEepromData, eepromDataSizeCode, flexnvmPartitionCode);
------------------------------------------------------------
This returns error 103, which maps to kStatus_FLASH_AccessError
The following driver code is hit, in flash_command_sequence(&flashConfig); :
------------------------------------------------------------
/* checking access error */
if (registerValue & FTFx_FSTAT_ACCERR_MASK)
{
return kStatus_FLASH_AccessError;
}
------------------------------------------------------------
I don't know why this happens, and I have tried triggering a mass erase at this point, in code. When I reflash my firmware and debug, the same thing happens.
How do I get the flexNVM set up as EEEPROM? I'd love any input/sugggestions/sample code.
Thanks,
Collin