MC9S12NE Problem to programming part of flash with

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

MC9S12NE Problem to programming part of flash with

2,295 Views
JACOBO
Contributor I
Hello

I read AN2720 and AN2400 to change the content of memory flash. I made the following
code, i placed flags to know if the program work. The flags noted that the program it's ok.
and that the sector of memory flash it's erased, but when i read the address of memory
the content is the same before that i erased it.

Do you know when there a error?.

The sector is 0x4E00.
The xtal of DEMO9S12NE64 is 25Mhz.
The Software is TCP OPEN and CW is 3.1.

/******call to Function to initiate of memory flash to erase it******/
 Flash_Init();
/****************************************************************/

/*********Function to initiate memory flash to erase it*********/
void Flash_Init(void)
  {
    FCLKDIV = 0x4F;
    FPROT = 0xFF;
    FSTAT = FSTAT | 0x30;
  }
/*************************************************************/

/**********call to Function to erase memory flash ***********/
 erase_sector(0x4E00);
/*************************************************************/

/***************Function to erase memory flash **************/

erase_sector(unsigned int direccion)
  {
    unsigned int* localidad;
    localidad = (unsigned int*)direccion;
        
    if((unsigned int)localidad & 0x0001)
      {
          //flag
      }
    if(((unsigned int)localidad % 0x200) != 0x00)
      {
            //flag
      }
      
    FSTAT = FSTAT | 0x30;  
      
    if(FSTAT_CBEIF==0x01)
      {
        (*localidad)=0xFFFF;  
        FCMD=0x40;
        if((FSTAT_ACCERR==0x01)||(FSTAT_PVIOL==0x01))
          {
               //flag
          }
        while(FSTAT_CCIF != 0x01)
          {
               //flag
          }
      }
    else
      {
             //flag
      }
      
        //flag
  }
Labels (1)
0 Kudos
5 Replies

475 Views
kef
Specialist I
What Lundin said +
 
erase didn't work because JACOBO didn't clear CBEIF flag, he only wrote erase command to FCMD. Some more thoughts:
 
1) FPROT=0xFF doesn't make sense in normal modes. You can protect flash, but can't unprotect it.
 
2)     FSTAT = FSTAT | 0x30;  <-- this is wrong. It clears not only ACCERR and PVIOL, but also all flags that are set! FSTAT flags are clearable by writing '1' to them. Use either
 
  FSTAT = 0x30;
 
or
 
  FSTAT &= 0x30; // note the difference between FSTAT &=0x30 and clearing
                              // bits in regular RAM variable,  x &= ~0x30;
To clear CBEIF either use
 
FSTAT = 0x80
 
or
 
FSTAT &= 0x80;
0 Kudos

475 Views
Lundin
Senior Contributor IV
Is the code running from flash? In that case it won't work, since the flash code can't be executed from the same bank which is to be programmed, and NE64 has only got one bank.

You will need to execute the code from RAM or to upgrade to a mcu with more than one bank, ie one with more than 64k flash.
0 Kudos

475 Views
JACOBO
Contributor I
Hello Lundin

I tried the advice of Kef and so the result is the same.

I think try your advice but i don't know how placed my code in RAM.

Do you know how do it?

Thank You.
0 Kudos

475 Views
Lundin
Senior Contributor IV
There is an app note with source code describing how to do it on the Freescale HCS12 site (I think it is AN2302 but I could be wrong).
0 Kudos

475 Views
J2MEJediMaster
Specialist I
The app note 1828 (AN1828.pdf) describes how to program the HCS12's Flash memory via the CAN.

The app note 2548 (AN2548.pdf) describes a serial boot monitor that can be used to program Flash on the HCS12.

The Technical Note 228 (TN228.pdf) describes a technique for copying code to memory and executing it.

HTH.

---Tom
0 Kudos