AnsweredAssumed Answered

Help! Writting to S12XEP100 flash using registers

Question asked by Szymon Mroczek on Oct 8, 2010
Latest reply on Oct 9, 2010 by Szymon Mroczek

Hi All,

 

I am trying to do a simple excersise of writing some example data into specific memory location (flash) of S12XEP100 MCU (onboard DEMO9S12XEP100 kit).

I read MC9S12XEP100RMV1 and S12XCPUV2 documents quite thoroughly and everything seems to be very clear to me.

Anyway I am not able to make that excersise working OK.

 

I suppose the reason lays somewhere in compiler / linker / IDE which I am not too familiar with for now.

There is a .prm file which I somewhat understand (at lest think so).

Then there are datapage.c and Start12.c files which I can hardly follow.

 

Please, find the main routine listed below.

I believe the entire project (with datapage.c and Start12.c files) will be very helpful for investigation so I add it as attachment.

 

void main(void) {
 
  DisableInterrupts;

  /* 1. configure mcu clock: Fosc = 4MHz >> Fbus = 8MHz */
  _SYNR.Byte = 0x03;
  _REFDV.Byte = 0x40;
  _POSTDIV.Byte = 0x01;
 
  /* 2. wait for PLL to lock */
  while(!_CRGFLG.Bits.LOCK) {
  }
 
  /* 3. select PLL as clock source */
  _CLKSEL.Bits.PLLSEL = 1;
 
  /* flash procedure tests: */

  /* 4. clear the illegal address reset flag */
  CRGFLG_ILAF = 1;        
 
  /* 5. initialise the memory controller prior to any  */
  /* commands being launched or EEE data access     */
  while(!FSTAT_CCIF) {
  }
 
  /* 6. load the clock divider before any flash command. Assumes 4MHz XTAL */
  FCLKDIV = 3;   
    
    /* 7. wait for ready state */      
  while(!FSTAT_CCIF) {
  }

  /* 8. no protection */
  FPROT = 0xFF;

  /* 9. wait for ready state */  
  while(!FSTAT_CCIF) {
  }
 
  /* 10. clear flash error flags */
  FSTAT = ( FSTAT_FPVIOL_MASK | FSTAT_ACCERR_MASK );
 
  /* 11. erase sector 0x7F_5000: */
    FCCOBIX = 0;      /* index for command and global address */
    FCCOBHI = 0x0A;   /* command - 0x0A = erase sector */
  FCCOBLO = 0x7F;   /* global address */

    FCCOBIX = 1;      /* index for "local" address */
  FCCOB = 0x5000;   /* "local" address */
 
  /* 12. launch command execution */
  FSTAT_CCIF = FSTAT_CCIF_MASK;

  /* 13. wait for ready state */
  while(!FSTAT_CCIF) {
  }
 
 
  /* 14. program sector 0x7F_5000: */
  FCCOBIX = 0;
    FCCOBHI = 0x06;
  FCCOBLO = 0x7F;

    FCCOBIX = 1;
  FCCOB = 0x5000;
  /* data word 1 */
  FCCOBIX = 2;
  FCCOB = 0x1234;
  /* data word 2 */
  FCCOBIX = 3;
  FCCOB = 0x5678;
  /* data word 3 */
  FCCOBIX = 4;
  FCCOB = 0x9ABC;
  /* data word 4 */
  FCCOBIX = 5;
  FCCOB = 0xDEF0;
 
  /* 15. launch command execution */
  FSTAT_CCIF = FSTAT_CCIF_MASK;

  /* 16. wait for ready state */
  while(!FSTAT_CCIF) {
  }
 
  /* flash tests completed */

 

 

  for(;:smileywink:
  {
    //while(_CAN0RFLG.Bits.RXF == 0) { }
    
  }
  for(;:smileywink: {} /* wait forever */
  /* please make sure that you never leave this function */
}

 

Please help! After feeling so inspired I feel quite desperate now :/


Outcomes