Erease Flash 0n MC9S08QE8

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

Erease Flash 0n MC9S08QE8

1,761 Views
DavidoBG
Contributor II
To erase flash, i use following  code and asm code doonstack.asm
 
#include <hidef.h>        /* for EnableInterrupts macro */
#include "derivative.h"  /* include peripheral declarations */
#include "hcs08.h"        // This is our definition file!
#include <MC9S08QE8.h>
#include "doonstack.h"
 
#define BUSCLK  8000000
#define vFCDIV  (BUSCLK/200000-1)
 
char fdata, operation;
unsigned int faddress;
// Write-protect addresses ranging from 0xE400 up to 0xFFFF
const byte NVPROT_INIT @0x0000FFBD = 0xE2;
// MCU innitialization
void mcu_init(void)
{
  SOPT1 = bBKGDPE;         // Enable debug pin
  ICSSC = NVFTRIM;        // configure FTRIM value
  ICSTRM = NVICSTRM;      // configure TRIM value
  ICSC2 = 0;               // ICSOUT = DCOOUT / 1
  // BUSCLK is now 8 MHz
  FCDIV = 39;//vFCDIV;          // set FCLK divider (FCLK = 200kHz)
}
#pragma inline
// Read the content of a memory address
char flash_read(unsigned int address)
{
  unsigned char *pointer;
  pointer = (char*) address;
  return (*pointer);
}
// Write a byte into the specified FLASH address
char flash_write(unsigned int address, unsigned char data)
{
  unsigned char *pointer;
  pointer = (char*) address;
  FlashProg(pointer,data);   // call the FLASH programming function
  if (FSTAT_FACCERR) data=1; else data=0;
  if (FSTAT_FPVIOL) data|=2;
  return(data);
}
// Erase a sector of the FLASH memory
unsigned char flash_sector_erase(unsigned int address)
{
  unsigned char *pointer, res;
  pointer = (char*) address;
  FlashErase(pointer);
  if (FSTAT_FACCERR) res=1; else res=0;
  if (FSTAT_FPVIOL) res|=2;
  return(res);
}
void main(void)
{
  mcu_init();
  fdata = 0;
  faddress = 0xE200;
  operation = 1;
  while (1)
  {
    switch (operation)
    {
      case 1: // sector erase
        fdata = flash_sector_erase(faddress);
        operation = 2;     
        break;
      case 2: // write operation
        faddress = 0xE200;
        fdata = 'D';
        fdata = flash_write(faddress,fdata);
        operation = 3;
        break;
      case 3: // read operation
        faddress = 0xE200;
        fdata = flash_read(faddress);
        operation = 0;
        break;
    }
  }
}
If i run full chip simulation and i run code my erase function don't run. I don't kown why?
Do you have any idea about this?
Thanks
david
Labels (1)
0 Kudos
Reply
1 Reply

400 Views
bigmac
Specialist III
Hello David,

Please refer to the following recent thread -
http://forums.freescale.com/freescale/board/message?board.id=CW816COMM&thread.id=5101

Regards,
Mac



Message Edited by bigmac on 2009-02-04 12:10 AM
0 Kudos
Reply