Read/Write S12G Flash

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

Read/Write S12G Flash

522 Views
paulung
Contributor I

Hi there

 

Is it possible to execute code at one memory range (say 0xC000 to 0xFFFF) to read or write flash at another memory range (say 0x4000 to 0x8000) on S12G?

 

Also, is it possible to execute code at one memory range to read flash from the same memory range on S12G?

 

Many thanks.

 

Paul.

Labels (1)
0 Kudos
1 Reply

312 Views
lama
NXP TechSupport
NXP TechSupport

Hi,

The S12G contains only one memory block so it is not possible to perform read while write code on the flash block. The code must be stored in other type of memory. Reading while not writing is not any problem anytime.

 

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

//PFLASH Send_Command – the routine placed in the RAM to perform safe write to a flash

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

//this function is stored in RAM memory

//in C language:

//  {

//    FSTAT_CCIF = 1;         //launch command

//    while(FSTAT_CCIF == 0); //wait for done

//  }

static unsigned char Send_Command[]=

{

  0x1C, 0x01, 0x06, 0x80, 0x1F, 0x01, 0x06, 0x80, 0xFB, 0x3D

};

 

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

//PFLASH_Program - the parameter MUST be global address

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

unsigned char PFLASH_Program(unsigned long int address, unsigned int *ptr)

{

  unsigned char i;

 

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

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

    return MISALIGNED_ADDRESS;

 

  //check if the phrase is erased   

  if((PFLASH_Erase_Verify_Section(address, 1)) == NON_ERASED)

    return NON_ERASED; 

   

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

  FSTAT = 0x30;             //clear ACCERR and PVIOL   

 

  FCCOBIX = 0x00;

  FCCOB = 0x0600 | ((address & 0x00030000)>>16);

 

  FCCOBIX = 0x01;

  FCCOB = (address & 0x0000FFFF);

 

  for(i=2; i<6; i++)  //fill data (4 words) to FCCOB register

  {

    FCCOBIX = i;

    FCCOB = *ptr;

    ptr++; 

  }

     

  asm JSR Send_Command;   

 

  if((FSTAT & (FSTAT_ACCERR_MASK | FSTAT_FPVIOL_MASK)) != 0)

    return ACCESS_ERROR;

  else   

    return OK;

}

Best regards,

Ladislav

0 Kudos