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

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

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

991 Views
dastek
Contributor III

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

}

Labels (1)
0 Kudos
1 Reply

661 Views
RadekS
NXP Employee
NXP Employee

Hi Wade,

I am afraid that it is not possible.

The EEPROM at S12XE is emulated, therefore we typically use term EEE or EEEPROM.

The emulated EEPROM at S12XE consist from RAM, non-volatile storage (= D-Flash) and hardware state machine which manages updates of D-Flash in the background.

By the (Full) Partitioning command you may set how big part from D-Flash will be used for emulated EEPROM. The extreme configuration are:

  1. ERPART=16, DFPART=0 where whole D-Flash is used for emulating 4kB of EEEPROM.
  2. ERPART=0, DFPART=128 where whole D-Flash is used as DATA flash with no EEEPROM. The appropriate buffer RAM could be used as standard RAM.

See, attached table with examples of ERPART/DFPART configurations.

Idea: You may emulate EEPROM by software on P-Flash. However, currently, I do not see any advantage in compare with the solution where we use whole D-Flash for EEE and save data into P-Flash. The simplest solution is partitioning just part of D-Flash for EEE. For example:

ERPART=8, DFPART=64 where 16kB D-Flash is used for emulating 2kB of EEEPROM and the next 16kB could be used as D-Flash.

Anyway, the software for emulating of EEPROM is described in AN4483 Emulated EEPROM Routines for the S12P Family

http://www.nxp.com/files/microcontrollers/doc/app_note/AN4483.pdf

http://www.nxp.com/files/microcontrollers/doc/app_note/AN4483SW.zip

and in AN2302 EEPROM Emulation for the MC9S12C32

http://www.nxp.com/files/microcontrollers/doc/app_note/AN2302.pdf

https://www.nxp.com/webapp/Download?colCode=AN2302SW

with AN3961 EEPROM Emulation for the MC9S12XS and MC9S12P Families Using AN2302 as a Reference

http://www.nxp.com/files/microcontrollers/doc/app_note/AN3961.pdf

http://www.nxp.com/files/microcontrollers/doc/app_note/AN3961SW.zip

You could use also EEPROM Emulation Driver for Flash in S12XS, S12P, S12HY and S12XHY:

http://www.nxp.com/files/microcontrollers/software/device_drivers/S12XS_P_HY_XHY_EEE.exe

and Standard Software Driver (SSD) for Flash in S12XS, S12P, S12HY and S12XHY:

http://www.nxp.com/files/microcontrollers/software/device_drivers/S12XS_P_HY_XHY_SSD.exe

Additionally, the PE EEE S12XE driver could be also configured for software emulation at P-Flash. However, I don’t have experience with that solution.

I hope it helps you.

Have a great day,
Radek

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

EDIT: I forgot on attachment.