MC9S08LC60 - Writing to Flash Area

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

MC9S08LC60 - Writing to Flash Area

2,289 Views
BasePointer
Contributor II
Hi,
I'm using CW 5.1 and MC9S08LC60.
I want to save some area(total 512 bytes) in ram to area 0xFE00-0xFFFF in flash memory.
- How can I reserve this flash area(0xFE00-0xFFFF) ?
- How can I place my FlashWrite, Erase functions to another flash array? The total program is now about 46KB.
I didn't test the routines below yet. I hope it works.
Code:
#define   FLASH_BURST_PROG    0x25          // Byte Program - Burst Mode
#define   FLASH_PAGE_ERASE    0x40          // Page Erase (512 bytes)

#define   FLASH_BACKUP_ADDR   (char*)0xFE00

char FlashPageErase(char *StartAddr)
{
  unsigned char tmp_data;
 
  FSTAT_FACCERR = 0;        // Clear error flags
  FSTAT_FPVIOL = 0;
   
  *StartAddr = tmp_data;
  FCMD = FLASH_PAGE_ERASE;  // Page erase program command, takes 4000cycles
  FSTAT_FCBEF = 1;          // Run the command
 
  _asm NOP;                 // wait four bus cycles
  _asm NOP;
  _asm NOP;
  _asm NOP;
   
  if(FSTAT_FACCERR || FSTAT_FPVIOL) return(0); // error
  
  // is the command in progress?
  while(!FSTAT_FCCF) __RESET_WATCHDOG();
 
  return(1);
}

char FlashWrite(char* StartAddr, char* Data, unsigned int length)
{
  FSTAT_FACCERR = 0;          // Clear error flags
  FSTAT_FPVIOL = 0;
 
  do
  {
    unsigned char tmp_data = *Data++;   
    while(!FSTAT_FCBEF);      // wait if buffer is full
   
    *StartAddr = tmp_data;
    FCMD = FLASH_BURST_PROG;  // Burst Byte program command
    FSTAT_FCBEF = 1;          // Run the command
 
    _asm NOP;                 // wait four bus cycles
    _asm NOP;
    _asm NOP;
    _asm NOP;
   
    if(FSTAT_FACCERR || FSTAT_FPVIOL) return(0); // error
   
    StartAddr++;
   
  } while(--length);
 
  // is the command in progress?
  while(!FSTAT_FCCF) __RESET_WATCHDOG();
 
  return(1);
}

char CreateBackupPoint(void)
{
  if(FlashPageErase(FLASH_BACKUP_ADDR))
    if(FlashWrite(FLASH_BACKUP_ADDR, &NV, sizeof(TNVRAM))) // sizeof(TNVRAM) = 413byte
      return(1);
   
  return(0);
}


Wizard generated prm file is here:
Code:
/* This is a linker parameter file for the mc9s08lc60 */

NAMES END

SEGMENTS     Z_RAM           =  READ_WRITE   0x0060 TO 0x00FF;  // 160 byte
    RAM                      =  READ_WRITE   0x0100 TO 0x085F;  // 1888 byte
    NO_INIT_RAM_SEG          =  NO_INIT      0x0860 TO 0x0C5F;  // 1024 byte
    MY_STK                   =  NO_INIT      0x0C60 TO 0x105F;  // 1024 byte
    ROM1                     =  READ_ONLY    0x1060 TO 0x17FF;
    ROM                      =  READ_ONLY    0x1870 TO 0xFFAF;
    ROM2                     =  READ_ONLY    0xFFC0 TO 0xFFD1;
END

PLACEMENT /* Here all predefined and user segments are placed into the SEGMENTS defined above. */
    _DATA_ZEROPAGE, MY_ZEROPAGE         INTO  Z_RAM;
    DEFAULT_RAM                         INTO  RAM;
    NO_INIT_RAM                         INTO  NO_INIT_RAM_SEG;
    SSTACK                              INTO  MY_STK;
    DEFAULT_ROM, ROM_VAR, STRINGS       INTO  ROM; /* ROM1,ROM2 In case you want to use ROM1,ROM2
                                                      as well, be sure the option -OnB=b
                                                      is passed to the compiler. */
END

STACKSIZE 0x400

VECTOR 0 _Startup /* Reset vector: this is the default entry point for an application. */

I'm new at HCS08 and I don't know what ROM, ROM1 and ROM2 segments generated by wizard are for.
Thank you.


Alban Edit: FSL Part Number in Subject line + split/moved to appropriate location.

Message Edited by Alban on 2007-03-14 11:41 AM

Labels (1)
Tags (1)
0 Kudos
4 Replies

407 Views
peg
Senior Contributor IV
Hi BP,
 
The new AN3404 may be of some assistance here.
 
0 Kudos

407 Views
BasePointer
Contributor II
Peg, thanks for the help.
0 Kudos

407 Views
mylim
Contributor IV
Hi guys, i believe this is applicable to the entire HC(S)08 family? As their flash architecture are the same.
I'm using HC(s)08aw60 & I need to store the devide address into the flash emulated ROM.
Are there any comment on using this method?
Thanks.
 
regards,
my
0 Kudos

407 Views
bigmac
Specialist III
Hello my,
 
The AW60 differs from the LC60 in that the former has only has a single flash array.  So there is no alternative but to use RAM for running  the critical code when flash access is not available.
 
Regards,
Mac
 


Message Edited by bigmac on 2008-03-12 02:26 AM
0 Kudos