Attempt to partition results in reset

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

Attempt to partition results in reset

Jump to solution
1,246 Views
Hab
Contributor III

Greetings everyone,

I am stuck - On a partitioning problem that continually resets.

TARGET HARDWARE: MK12DX256VLF5

TOOL: IAR (J-Link Debugger)

I use the following code which I got directly from Freescale:

main()

{

...

  printf("  Checking For *NV Memory Partition...\r\n");

  if (partition_flash(EEPROM_128_128, DFLASH_SIZE_0)) // passed values are 0x36 and 0x08

    printf("  **New Flex Memory Partition\r\n");

  else

    printf("  >>Device Already Partitioned\r\n");

...

}

bool_t partition_flash(uint8_t EEProm_size, uint8_t 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(0x0F)) != 0x00000F00)
    return(FALSE);

  /* Write the FCCOB registers */
  FTFL_FCCOB0 = FTFL_FCCOB0_CCOBn(0x80); // Selects the PGMPART command
  FTFL_FCCOB1 = 0x00;
  FTFL_FCCOB2 = 0x00;
  FTFL_FCCOB3 = 0x00;

  /* FCCOB4 is written with the code for the subsystem sizes (eeprom_size define) */
  FTFL_FCCOB4 = EEProm_size;

  /* FFCOB5 is written with the code for the Dflash size (dflash_size define) */
  FTFL_FCCOB5 = DFlash_size;

  /* All required FCCOBx registers are written, so launch the command */
  FTFL_FSTAT = FTFL_FSTAT_CCIF_MASK;

  /* Wait for the command to complete */
  while((FTFL_FSTAT & FTFL_FSTAT_CCIF_MASK) == 0x00);
  return(TRUE);
}

If the device is blank and I run the partition code it resets (Core Lockup Event) at the execute partiton command (bold line) every time.  If I set a break point at that line (bold line) then run it resets, but if I set a break point (at the bold line) then step one line it works.  the registers before the execution of the command look (I think) as they should...

FTFL_FSTAT: 0x80

FTFL_FCNFG: 0x02

FTFL_FSEC: 0xFE

FTFL_FOPT: 0xFF

FTFL_FCCOB0: 0x80

FTFL_FCCOB1: 0x00

FTFL_FCCOB2: 0x00

FTFL_FCCOB3: 0x00

FTFL_FCCOB4: 0x36

FTFL_FCCOB5: 0x08

FTFL_FCCOB6: 0x00

FTFL_FCCOB7: 0x00

FTFL_FCCOB8: 0x00

FTFL_FCCOB9: 0x00

FTFL_FCCOBA: 0x00

FTFL_FCCOBB: 0x00

FTFL_FPROT0: 0xFF

FTFL_FPROT1: 0xFF

FTFL_FPROT2: 0xFF

FTFL_FPROT3: 0xFF

FTFL_FEPROT: 0xFF

FTFL_FDPROT: 0xFF

I have also insered delays before the command execution (upto 1s) thinking it was timing related with no change of result.  Thinking it was unique to the J-Link debugger I loaded the code to the target and there it also resets. 

Any help on this would be great...

Thanks,

Hab

Labels (1)
Tags (2)
0 Kudos
Reply
1 Solution
840 Views
Hab
Contributor III

SOLUTION... FUNCTION NOTES ARE IMPORTANT

/*************************************************************************
* Function Name: partition_flash
* Parameters: uint8_t, uint8_t
* Return: bool_t
* NOTE: This function should be called before IRQs (espcially timers) are set to run 
* as the partitioning process must not be interuppted
* NOTE: Flex NV Memory can be divided into EFlash (EE NV), DFlash Space or a combination
* of the two.  The max EE space is 4KB.  The smaller the DFlash the longer the life of the EE NV
* See Freescale App Note AN4282 for more information
*
* Description:  Partition flash routine. This function can be used to setup
* the flash for enhanced EEPROM operation. In order to guarantee
* the eEE endurance the partition command should only be used one
* time (re-partitioning in a different configuration will erase
* wear-leveling data, so endurance can no longer be guaranteed).
* This function will test to make sure the flash has not been
* partitioned already.
*
* Why: The very first time firmware runs it must partition the memory for use.
* By partitioning the memory NV EE memory is created within the micro. 
*
* STEP 1: Check if the device was previously partitioned
* STEP 2: Clear Status Register Flags and Load for the FCMD Program Partition Command
* STEP 3: Execute the command and return when done
*************************************************************************/  
bool_t partition_flash(uint8_t EEPROM_Size, uint8_t DFlash_Size)
{

  // STEP 1:
  // CHECK FOR PREVIOUS PARTITION AND RETURN FALSE IF IT WAS
  if ((SIM_FCFG1 & SIM_FCFG1_DEPART(0x0F)) != 0x00000F00)
    return(FALSE);

  // STEP 2:
  // CLEAR RDCOLERR, ACCERR AND FPVIOL FLAGS OF THE STATUS REGISTER
  FTFL_FSTAT = (FTFL_FSTAT_RDCOLERR_MASK | FTFL_FSTAT_ACCERR_MASK | FTFL_FSTAT_FPVIOL_MASK);
  // WRITE THE VALUES TO LOAD THE FCMD FOR PROGRAM PARTITION
  FTFL_FCCOB0 = FTFL_FCCOB0_CCOBn(FCMD_PROGRAM_PARTITION);
  FTFL_FCCOB1 = 0x00;
  FTFL_FCCOB2 = 0x00;
  FTFL_FCCOB3 = 0x00;
  FTFL_FCCOB4 = EEPROM_Size;
  FTFL_FCCOB5 = DFlash_Size;

  // STEP 3:
  // EXECUTE THE FCMD COMMAND AND RETURN WHEN DONE
  FTFL_FSTAT = FTFL_FSTAT_CCIF_MASK;
  while((FTFL_FSTAT & FTFL_FSTAT_CCIF_MASK) == 0x00);
  return(TRUE);
 
} // END OF partition_flash

View solution in original post

2 Replies
841 Views
Hab
Contributor III

SOLUTION... FUNCTION NOTES ARE IMPORTANT

/*************************************************************************
* Function Name: partition_flash
* Parameters: uint8_t, uint8_t
* Return: bool_t
* NOTE: This function should be called before IRQs (espcially timers) are set to run 
* as the partitioning process must not be interuppted
* NOTE: Flex NV Memory can be divided into EFlash (EE NV), DFlash Space or a combination
* of the two.  The max EE space is 4KB.  The smaller the DFlash the longer the life of the EE NV
* See Freescale App Note AN4282 for more information
*
* Description:  Partition flash routine. This function can be used to setup
* the flash for enhanced EEPROM operation. In order to guarantee
* the eEE endurance the partition command should only be used one
* time (re-partitioning in a different configuration will erase
* wear-leveling data, so endurance can no longer be guaranteed).
* This function will test to make sure the flash has not been
* partitioned already.
*
* Why: The very first time firmware runs it must partition the memory for use.
* By partitioning the memory NV EE memory is created within the micro. 
*
* STEP 1: Check if the device was previously partitioned
* STEP 2: Clear Status Register Flags and Load for the FCMD Program Partition Command
* STEP 3: Execute the command and return when done
*************************************************************************/  
bool_t partition_flash(uint8_t EEPROM_Size, uint8_t DFlash_Size)
{

  // STEP 1:
  // CHECK FOR PREVIOUS PARTITION AND RETURN FALSE IF IT WAS
  if ((SIM_FCFG1 & SIM_FCFG1_DEPART(0x0F)) != 0x00000F00)
    return(FALSE);

  // STEP 2:
  // CLEAR RDCOLERR, ACCERR AND FPVIOL FLAGS OF THE STATUS REGISTER
  FTFL_FSTAT = (FTFL_FSTAT_RDCOLERR_MASK | FTFL_FSTAT_ACCERR_MASK | FTFL_FSTAT_FPVIOL_MASK);
  // WRITE THE VALUES TO LOAD THE FCMD FOR PROGRAM PARTITION
  FTFL_FCCOB0 = FTFL_FCCOB0_CCOBn(FCMD_PROGRAM_PARTITION);
  FTFL_FCCOB1 = 0x00;
  FTFL_FCCOB2 = 0x00;
  FTFL_FCCOB3 = 0x00;
  FTFL_FCCOB4 = EEPROM_Size;
  FTFL_FCCOB5 = DFlash_Size;

  // STEP 3:
  // EXECUTE THE FCMD COMMAND AND RETURN WHEN DONE
  FTFL_FSTAT = FTFL_FSTAT_CCIF_MASK;
  while((FTFL_FSTAT & FTFL_FSTAT_CCIF_MASK) == 0x00);
  return(TRUE);
 
} // END OF partition_flash

840 Views
sudarshankumar
Contributor II

Hi,

Are you able to fix reset issue.

Can you tell me how to overcome reset issue.

I am using SK32K144/SK32K148

Regards,

Sudarshan

0 Kudos
Reply