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;
}
Hi
I am also struggling with the flexNVM.
Do you have any core optimization enabled? I.e. -O compile flag?
I have managed to "destroy" a K10DX device when trying to block erase the flash from code, to be able to repartition the memory. I am not sure why it happen, but I think it is because an errata issue, or I did something very wrong....
I ran into an other problem when trying to write to an already partitioned EEEPROM, but I got a hard_fault problem when writing to other flexRAM address than 0x1400 0000. Do not know why. Something you have experienced?
BR
Daniel
I had to add the code
asm("cpsid.n i"); //disable interrupts
before the first FCCOB write
and the enable interrupts
asm("cpsie.n i "); // enable interrupts
after the wait for the commands to complete.
This fixed the lock-up problems with MQX.
I use optimization level 1, and do not try block erase from code. I have no seen any problems in the flexRAM, and use addresses past 0x14000200. But depending on how its partitioned, you may get the hard_fault if you used flexRAM address outside the partitioned area.
Ok. Perhaps the partitioning went bad due to lack of interrupt disabling. That might explain why I couldn't access addresses > 0x1400 0000 without hard_fault.
Yes I did use the block erase command from inside code... That seems to have corrupted the flash so I cannot program in via JTAG anymore. As according to errata e3854 described in KINETIS_0M33Z.pdf.I guess I shall use Erase Flash Sector command instead to prepare flexNVM for re-partitioning, have you tried it?
Do you know any workarounds to make it "come back from the dead"? Or shall I consider it scrap....
BR
Daniel
The dflash always gets erased by codewarrior, so I don't have to worry about erasing prior to partitioning. According to the datasheets, the app should only partition once for the lifetime of the device.