I"m having problems getting my MK10 to set the Partition information correclty .
I've created code that has worked perfectly on a MK70FX512 system and am porting this code to the MK10FX512 system.
I've modified the code slightly to add the EEERST bit to the partition information. When running this code it actully completes the SetPartitionInfo command with success = 1, but when it tries to Printf the message that it was sucessful the system prints out part of the message.. and then begins spitting out garbage. If I put an incorrect value for EEESPLIT the
SetPartitionInfo command does fail with success = 0, and the printf failure message prints as expected.
#define EEESIZE_VALUE 0x03 //Size of EEPROM is 2K
#define EEESPLIT_VALUE 0x00 //Read Only (Always read as a one)
#define DEPART_VALUE 0x04 // 64K of Backup EEPROM bytes.
#define EEERST_VALUE 1 //Flex Ram is Loaded with valid data after reset
//*****************This is the code I'm calling when I want to partition the device. The triggerFCCOBinRAM has been setup appropriately and copied to RAM to run. This exact code functions perfectly in an MK70FX512 system.
// Partition the memory now.
if (SetPartitionInfo(EEERST_VALUE,EEESIZE_VALUE, EEESPLIT_VALUE, DEPART_VALUE, triggerFCCOBinRAM))
printf("FlexNVM_Init() Device partitioning successful.\r\n");
else
printf("FlexNVM_Init() Device partitioning FAILED.\r\n");
//***********************This is the SetPartitionInfo Subrotine
// Set new partition information.
static boolean SetPartitionInfo(uint8 eeerst, uint8 eeesize, uint8 eeesplit, uint8 depart, TriggerFn_t triggerFn)
{
// To set a new partition scheme, use the Program Partition command.
boolean success = false;
// First step of any command sequence is wait for ready, then clear faults.
while (!(FTFE_FSTAT & FTFE_FSTAT_CCIF_MASK))
{
// Do nothing as long as the CCIF flag is clear.
}
// If flash protection violation is set, clear it by writing 1 to the bit
if (FTFE_FSTAT & FTFE_FSTAT_FPVIOL_MASK)
FTFE_FSTAT |= FTFE_FSTAT_FPVIOL_MASK;
// If access error is set, clear it by writing 1 to the bit
if (FTFE_FSTAT & FTFE_FSTAT_ACCERR_MASK)
FTFE_FSTAT |= FTFE_FSTAT_ACCERR_MASK;
// If read collision error is set, clear it by writing 1 to the bit
if (FTFE_FSTAT & FTFE_FSTAT_RDCOLERR_MASK)
FTFE_FSTAT |= FTFE_FSTAT_RDCOLERR_MASK;
// Housekeeping done, set up command structure.
FTFE_FCCOB0 = PROGRAM_PARTITION_CMD;
FTFE_FCCOB1 = 0x00; // Address 23-16 not used
FTFE_FCCOB2 = 0x00; // Address 15- 8 not used
FTFE_FCCOB3 = 0x00; // Address 7- 0 not used
FTFE_FCCOB4 = ( ((eeerst & 0x01) << 6) | (eeesplit & 0x03) << 4) | (eeesize & 0x0f);
FTFE_FCCOB5 = (depart & 0x0f);
// Trigger the function and wait for it to complete.
// Trigger/wait code must run from RAM.
// Don't allow interrupts to run, they could access flash.
Enter_Critical_Section(); //MACRO that turns off interrupts - Defination below
triggerFn(&FTFE_FSTAT);
Leave_Critical_Section(); //MACRO that restores interrupts. - Defination below
// Operation is successful if there are no errors.
success = (!(FTFE_FSTAT & (FTFE_FSTAT_FPVIOL_MASK | FTFE_FSTAT_ACCERR_MASK | FTFE_FSTAT_RDCOLERR_MASK | FTFE_FSTAT_MGSTAT0_MASK)));
return success;
}
#define Enter_Critical_Section() \
{ /* Begin local code block */ \
static unsigned char saveFAULTMASK; /* Local storage for FAULTMASK */ \
asm(PUSH {R0,R1}); /* Save registers that will be used */ \
asm(MRS R0, FAULTMASK); /* Move FAULTMASK to temp regiser */ \
asm(CPSID f); /* Disable all interrupts but NMI */ \
asm(LDA R1, saveFAULTMASK); /* Get address of local storage */ \
asm(STRB R0, [R1]); /* Save original FAULTMASK value */ \
asm(POP {R0,R1}); /* Restore original register values */
#define Leave_Critical_Section() \
asm(PUSH {R0,R1}); /* Save registers that will be used */ \
asm(LDA R1, saveFAULTMASK); /* Get address of local storage */ \
asm(LDRB R0, [R1]); /* Get original FAULTMASK value */ \
asm(MSR FAULTMASK,R0;); /* Restore original FAULTMASK value */ \
asm(POP {R0,R1}); /* Restore original register values */ \
} /* End local code block */