Rodney McGee

D-Flash on MC9S12XE

Discussion created by Rodney McGee on Jun 2, 2012
Latest reply on Jun 4, 2012 by kef

I am trying to program from D-Flash on the MC9S12XET256. I want to use the 1st page (256 bytes worth) of the 1K non-paged eeprom/D-flash memory. Located at 0x0C00  -  0x1000
(the below code isn’t trying to use the fixed window, but we tried for a while)

For some addresses, this code ran without error, but when we looked at the position in memory it did not seem cleared after erasing, nor to contain 0xA5A5 after writing. (I believe this is the case for x10_0100, the address being attempted in the above code).  For some other addresses we attempted (there were several- x00_0C00, perhaps? 1F_0C00? x1F_0000?) this resulted in a memory access error (shown by a 1 in the ACCERR bit of the FSTAT register), but I’m fairly sure I am were attempting to read/write areas that weren’t actually DFlash.


If my values are wrong. what are the correct values FCCOBLO FCCOB vto access the 0xC00-0x100 page. Erase it and write to it. Also is it possible to use the other 3 pages in the 1K fixed page as eeprom in the same code?


I appreciate any help with this issue. I have been trying many things to no avail. 

Other Info:
Thought perhaps we needed to unprotect flash, tried:
FPROT |= 0xA4;     // FPOPEN=1, FPHDIS=1, FPLDIS=1
EPROT |= 0x88;     // EPOPEN=1, EPDIS=1

to no avail. (I don’t think this is valid/neccesary, but we tried it because in some derivatives you have to set DFPROT before writing to DFlash)


Code:

// Function to erase Dflash

static void eraseDflash(){

    DisableInterrupts;

    if ((FSTAT & 0x30) != 0) {

         FSTAT |= 0x30;         // clear ACCERR or FPVIOL if set

    }


    FCCOBIX = 0;

    FCCOBHI = 0x12;         // erase D-flash command

    FCCOBLO = 0x10;        // global address


    FCCOBIX = 1;

    FCCOB = 0x0100;        // address within sector


    FSTAT = 0x80;              // initiate flash command

    while(!FSTAT_CCIF);   // wait for command to complete

    EnableInterrupts;

}


// Function to write Dflash

static void writeDflash(UINT16 word_to_write){

    DisableInterrupts;

    if ((FSTAT & 0x30) != 0) {

         FSTAT |= 0x30;        // clear ACCERR or FPVIOL if set

    }

 

    FCCOBIX = 0;

    FCCOBHI = 0x11;         // program D-flash command

    FCCOBLO = 0x10;       // global address


    FCCOBIX = 1;

    FCCOB = 0x0100;        // address within sector

    FCCOBIX = 2;

    FCCOB = word_to_write;


    FSTAT = 0x80;              // initiate flash command

    while(!FSTAT_CCIF);   // wait for command to complete

    EnableInterrupts;

}


// Called from main:

eraseDflash();

writeDflash(0xA5A5);


Relevant websites/forum posts:
http://www.freescale.com/files/microcontrollers/doc/data_sheet/MC9S12XEP100RMV1.pdf

https://community.freescale.com/thread/51749

http://www.freescale.com/files/microcontrollers/doc/app_note/AN3743.pdf

http://www.freescale.com/files/microcontrollers/doc/app_note/AN3490.pdf

http://forums.freescale.com/t5/16-Bit-Microcontrollers/Problem-in-using-D-Flash-for-XS128-Need-help/td-p/34416

Outcomes