on K60fx512 when I try to partition flex memory, the code hangs (in debugger) or mcu resets where shown below. Code is based on flexmem_demo.
If I put breakpoint at the hang location and then reset, the flexmem has actually partitioned and works as expected as an eeprom.
Also using MQX 3.8/Codewarrior 10.2 , if this is relevant.
#define DFLASH_SIZE_448 0x04
#define EEPROM_512_512 0x34 // subsystem A = 512 bytes, subsystem B = 512 bytes
void flexinit (void)
{
SCB_SHCSR|=SCB_SHCSR_BUSFAULTENA_MASK|SCB_SHCSR_MEMFAULTENA_MASK|SCB_SHCSR_USGFAULTENA_MASK;
/* Partition the memory to enable FlexMem mode */
if ( partition_flash( EEPROM_512_512, DFLASH_SIZE_448) )
{
/* Wait for the command to complete */
while(!(FTFE_FCNFG & FTFE_FCNFG_EEERDY_MASK))
{
}
}
}
int partition_flash(int eeprom_size, int dflash_size)
{
/* Test to make sure the device is not already partitioned. If it
* is already partitioned, then return with no action performed.
*/
if ((SIM_FCFG1 & SIM_FCFG1_DEPART(0xF)) != 0x00000F00)
{
printf("\nDevice is already partitioned.\n");
return 0;
}
/* Write the FCCOB registers */
FTFE_FCCOB0 = FTFE_FCCOB0_CCOBn(0x80); // Selects the PGMPART command
FTFE_FCCOB1 = 0x00;
FTFE_FCCOB2 = 0x00;
FTFE_FCCOB3 = 0x00;
/* FCCOB4 is written with the code for the subsystem sizes (eeprom_size define) */
FTFE_FCCOB4 = eeprom_size;
/* FFCOB5 is written with the code for the Dflash size (dflash_size define) */
FTFE_FCCOB5 = dflash_size;
/* All required FCCOBx registers are written, so launch the command */
FTFE_FSTAT = FTFE_FSTAT_CCIF_MASK;
/* Wait for the command to complete */
while(!(FTFE_FSTAT & FTFE_FSTAT_CCIF_MASK))
{
// hangs or resets here
}
return 1;
}