S12G128 Write to EEPROM outside BDM

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

S12G128 Write to EEPROM outside BDM

Jump to solution
3,578 Views
rayhall
Contributor V

I can write to EEPROM when using the BDM to program/debug. I cannot write in normal mode.

 

The datasheet lists the register EEPROT and DPOPEN, DPS. This register is rejected by the complier and is not in the mc9s12g128.h file.

 

As there is no EEPROT I have tried using this without success,

 

DFPROT_DPOPEN = 0x01;

DFPROT_DPS = 0x05;

 

Ray.

Labels (1)
0 Kudos
Reply
1 Solution
3,270 Views
kef2
Senior Contributor V

Looks like there's an error in erase function

byte EEPROM_Erase_Sector(word address)

{

  //size of sector is 4B

  //check if address is aligned (global address [0] != 0)

  if((address & 0x00000001) != 0)

    return MISALIGNED_ADDRESS;

  

  while(FSTAT_CCIF == 0);   //wait if command in progress

  FSTAT = 0x30;             //clear ACCERR and PVIOL

  FCCOBIX = 0x00;

  FCCOB   = 0x12;

Should be 0x1200. Is erase function working in special single chip mode (with BDM debugger connected)?

View solution in original post

8 Replies
3,269 Views
rayhall
Contributor V

This is part of the code that writes to the EEPROM if the EEPROM has not been written, Also when the PC software sends changes it writes the new information to the EEPROM. My problem is it ignores the WriteStructureToEEprom() function when new information is sent via the PC,

I also have attached a file with the other functions used in this code,

Ray.

void main(void) {

  uint8_t writeEeprom = FALSE;

  if( (*(word*)(0x000400)) != 0x2430) {

    LoadStructData();

    writeEeprom = TRUE;

  } else {  

    ReadStructureFromEEprom((uint8_t *)&ecu, 0x000400, sizeof(ecu)); // Read struct data from EEPROM

  }

  EnableInterrupts;

  for(;;) {

    if (writeEeprom == TRUE) {

        WriteStructureToEEprom((uint8_t *)&ecu, 0x000400, sizeof(ecu)); // Write struct to EEPROM

        writeEeprom = FALSE;

    }

    if (gotRx == TRUE) {  // PC Data received

        cmd = RxData[2];  // Read the third byte which is the command

      

        switch (cmd) {

            case 0x01 : receiveWholeMap();

                              writeEeprom = TRUE;

                              break;

            case 0x02 : sendRealTimeData();

                                break;

            case 0x03 : sendWholeMap();

                                break;                          

        }

            gotRx = FALSE;

      } // End GotRX

    

  _FEED_COP(); /* feeds the dog */

  } /* loop forever */

  /* please make sure that you never leave main */

}

0 Kudos
Reply
3,269 Views
RadekS
NXP Employee
NXP Employee

Hi Ray,

You are right. There is small inconsistence between CW header file and S12G reference manual.

Anyway, EEPROT and DFPROT are just different names for the same register.

Could you please explain connection between DFPROT settings and your code?

I shortly checked your code, but I do not see any write into DFPROT in your code.

I do not see also any initialization for flash module. According reference manual: “If the FCLKDIV register has not been written, any Flash program or erase command loaded during a command write sequence will not execute and the ACCERR bit in the FSTAT register will set.”

Please initialize flash module prior you start with erasing or programming EEPROM.


I hope it helps you.

Have a great day,
RadekS

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

0 Kudos
Reply
3,269 Views
rayhall
Contributor V

RadekS,

Attached is the whole project.

Ray.

0 Kudos
Reply
3,271 Views
kef2
Senior Contributor V

Looks like there's an error in erase function

byte EEPROM_Erase_Sector(word address)

{

  //size of sector is 4B

  //check if address is aligned (global address [0] != 0)

  if((address & 0x00000001) != 0)

    return MISALIGNED_ADDRESS;

  

  while(FSTAT_CCIF == 0);   //wait if command in progress

  FSTAT = 0x30;             //clear ACCERR and PVIOL

  FCCOBIX = 0x00;

  FCCOB   = 0x12;

Should be 0x1200. Is erase function working in special single chip mode (with BDM debugger connected)?

3,269 Views
rayhall
Contributor V

Edward,

That fixed the problem.

Thank you

Ray.

0 Kudos
Reply
3,269 Views
RadekS
NXP Employee
NXP Employee

Wow, thanks Ed.

I missed that point.

In fact, I just remember that it was error in one of first versions of our S12G EEPROM example.

It seems that Ray used old version of this example.

In attachment is newer version of this example (version 1.2).


I hope it helps you.

Have a great day,
RadekS

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

3,269 Views
RadekS
NXP Employee
NXP Employee

Hi Ray,

Note about PLL clock:

You selected fVCO=26MHz, unfortunately this is out of any valid ranges.

For 13MHz bus clock, please use these values:

CPMUSYNR=0x59; //SYNDIV=0x19, VCOFRQ=0x01

CPMUREFDIV=0x00;

CPMUPOSTDIV=0x01;

For 16MHz bus clock, please use these values:

CPMUSYNR=0x0F; //SYNDIV=0x0F, VCOFRQ=0x00

CPMUREFDIV=0x00;

CPMUPOSTDIV=0x00;

For 25MHz bus clock, please use these values:

CPMUSYNR=0x58; //SYNDIV=0x18, VCOFRQ=0x01

CPMUREFDIV=0x00;

CPMUPOSTDIV=0x00;

In attachment you can find PLL calculator. Please select S12P (it has also CPMU module), input clock frequency and requested bus clock.

I would like to note that you can use PLL (based on IRC oscillator) as clock for CAN module only for debugging purposes. In most of cases, PLL accuracy isn’t sufficient for CAN communication.

About programming:

EEPROM_Program() function calls EEPROM_Erase_Verify_Section() function. EEPROM_Erase_Verify_Section() function has critical part which has to be executed from RAM. Any interruption (when interrupt routine is located in P-flash) could cause that EEPROM will be not read correctly.  Therefore I would like to recommend disable interrupts prior this critical section and enable after that. For example:

DisableInterrupts;

asm JSR Send_Command;

EnableInterrupts;

Except this I do not see any reason why it should not work in normal mode.


I hope it helps you.

Have a great day,
RadekS

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

3,269 Views
rayhall
Contributor V

RadekS,

The PPL calculator version 1.03 will not accept 1 Mhz as the Oscillator.

I have the clock on an external pin and my oscilloscope reads 13 Mhz as the frequency. Also the SCI is set up for 57600 baud based on 13 Mhz and the communication with the PC at 57600 is perfect. Based on this I believe I am running at 13 Mhz. Am I missing something ?.

Ray.

0 Kudos
Reply