AnsweredAssumed Answered

I want to use 4096 bytes of EEPROM for one purpose, as well as 32768 bytes of DFLASH

Question asked by Wade Whitehorn on Jul 29, 2016
Latest reply on Aug 1, 2016 by Radek Sestak

I am using the MC9s12xeq384 micro.

I am using the Cosmic compiler.

I want to use 4096 bytes of EEPROM for one purpose, as well as

  32768 bytes of DFLASH for another purpose.

  I purely need this memory for non-volatile storage and I use the EEPROM for its small sector erase size.

  I previously had the DFLASH programming with no EEPROM working.

  The code below gets the EEPROM into the memory map but the DFLASH does not program data now.

 

//*******************************

// set value of DFPART and ERPART

#define DFPART__    0

#define ERPART__   16

// {0,16} means that whole Buffer RAM and whole D-Flash is used for Emulated EEPROM

//*******************************

 

#define OK    0

#define ERROR 1

#define EEPROM_EMULATION_QUERY (unsigned char) 0x15 // - EEPROM

 

//==============================================================================

// EEE_Enable

//==============================================================================

void EEE_Enable(void)

{

  while ((FSTAT & CCIF) == 0) ;    // wait if command in progress

  FSTAT = 0x30;                            // clear ACCERR and PVIOL

 

  FCCOBIX = 0x00;

  FCCOB   = 0x1300;                   // ENABLE_EEPROM enable EEPROM Emulation Command

 

  FSTAT   = 0x80;                         // launch command

  while ((FSTAT & CCIF) == 0) ;  // wait for done

}

 

//==============================================================================

// DFLASH_Full_Partition

//==============================================================================

 

unsigned char DFLASH_Full_Partition(unsigned int set_DFPART, unsigned int set_ERPART)

{

  while ((FSTAT & CCIF) == 0) ;       // wait if command in progress

  FSTAT = 0x30;                                // clear ACCERR and PVIOL

 

  FCCOBIX = 0x00;

  FCCOB = 0x0F00;                         // Full Partition D-Flash Command

  FCCOBIX = 0x01;

  FCCOB = set_DFPART;               // DFPART = No of 256 byte sectors for DFlash == 32786

  FCCOBIX = 0x02;

  FCCOB = set_ERPART;              // ERPART = No of 256 byte sectors in buffer RAM == 4096

 

  FSTAT   = 0x80;                           // launch command

  while ((FSTAT & CCIF) == 0) ;    // wait for done

 

  if ((FSTAT & ACCERR) == 0)     // Check if an error occured

   return OK;

  else

   return ERROR;

}

 

@far

void Set_EEPROM_Status (void)                          // Emulation query - page 884

{

UINT8 err;

@far @gpage UINT16 DF @0x120000;               // Address of DFPART

@far @gpage UINT16 ER @0x120004;              // Address of ERPART

 

  if ((*&DF != DFPART__) ||                                  // Check if these DWORDS are correct value

     (*&ER != ERPART__))

   {

     if ((*&DF == 0xFFFF) &&                                 // Check if this is in erased state

         (*&ER == 0xFFFF))

       err = DFLASH_Full_Partition(DFPART__,ERPART__); //first startup of MCU - set the partition

   }

 

  EEE_Enable();                                                        // Make the EEPROM visible in map

 

// -----------------  EEPROM Emulation Query Needs to be done after Setup or returns constants

 

  FCCOBIX = 0x00;                                                       // Start command index

  FCCOB   = EEPROM_EMULATION_QUERY << 8; // EEPROM emulation query

  FSTAT   = 0x80;                                                           // launch command

 

  while((FSTAT & CCIF) == 0) ;                                       // wait for done

 

  FCCOBIX = 0x01;

  DFPART  = FCCOB;                                       // Read DFPART = 0 = No of 256 byte sectors in DFlash

  FCCOBIX = 0x02;

  ERPART  = FCCOB;                                       // Read ERPART = 16 = No of 256 byte sectors in buffer RAM

  FCCOBIX = 0x03;

  ECOUNT  = FCCOB;                                      // Read ECOUNT = 0

  FCCOBIX = 0x04;

  SEC_COUNT = FCCOB;                                // Read Dead SECtor COUNT = 4

 

 

  FSTAT   = 0x30;                                               // clear ACCERR and FPVIOL

}

Outcomes