ram assy emulation code to page erase byte write flash

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

ram assy emulation code to page erase byte write flash

1,654 Views
jah
Contributor I
does anyone have one for the mc9s08rd32dwe
i know people are doing this, what code is working for them, chime in please
i looked at a few but most of them are w/o documentation
-where is the flash command loaded
-the varriable to page erase and or write flash byte
-the data to be written to flash is declared where what

i tried this code:
#pragma DATA_SEG _RAMROUTINE
unsigned char Ram_Routine[] = {
0xc6,0x18,0x25,0xa5,0x10,0x27,0x07,0x45,0x18,
//address 1 //address 2
0x25,0xf6,0xaa,0x10,0xf7,0x32,0x06,0xA0,0xc6,0x06,0xA2,
0xf7,0xa6,0x40,0x45,0x18,0x25,0xe7,0x01,0xf6,0xaa,0x80,
0xf7,0x9d,0x9d,0x9d,0x9d,0xc6,0x18,0x25,0xc6,0x18,0x25,
0xa5,0x40,0x27,0xf9,0x81};
#pragma DATA_SEG DEFAULT

#pragma DATA_SEG _FLASHVARS
unsigned int FixedAddres; //by the code this seems to it should be 0x60 abouts
unsigned char DataToWrite;
#pragma DATA_SEG DEFAULT

//this is how the above is used:
//looking through my example DataToWrite is at 0x7e2 and FixedAddres at 0x7E0, but //looking at teh Ram_Routine code i think its 0x6e2 and 0x6e0. in most of the ram
//based flash erase write code not alot of documentation.
void Flash_Program(Byte data){
DataToWrite = data;
Ram_Routine[22] = 0x20;
__asm jsr Ram_Routine;
}
Labels (1)
0 Kudos
2 Replies

397 Views
J2MEJediMaster
Specialist I
Try searching for flash programming in these forums. The topic has been discussed repeatedly. Also, check out the Flash Programming FAQ, reference # 26240, in the Freescale FAQ system. It's the mother of all Flash programming documents, and has pointers to a variety of application notes on Flash programming. Many of the referenced notes have example code.

---Tom
0 Kudos

397 Views
jah
Contributor I
sometimes these forums can be more or less useful but it really depends on the attitude of all of us.

reference: mc9s08rd32dwe processor CodeWarrior hc(s)08 3.1

anyway(s) flash page erase byte write problemo resolved. basically assembly code interface had two errors, well lets say three.
-the assembly code required an unsigned int of address and a Byte of data to be written to and the c language program was writting this data to the wrong address
-some interrupt, possibly due to my dwn rev version of CW, seemed to over wite the data even if it were written to the correct locations.
-no documentation, especially the assembly code. the stuff i saw looked very odd, tho i am sure it was working when submitted. i actuall saw somethig like this:
((unsigned char (*) (int, unsigned char))(Ram_Routine)))

//the assembly routine express as a initilized array, not the lack of any comments except the address locations address 1 = (unsigned int)address address2 = (Byte)data
#pragma DATA_SEG _RAMROUTINE. Note here because something was over writting address 1&2 i moved these to the end of the array, see locations three locations 0x00,0x00,0x00. by the way Ram_Routine[] was linker located top of ram in the *.prn file. so note address 1&2 address&data are set to 0x0843 and 0x0845 and 0x845 is the last byte of ram.
unsigned char [] = {
0xc6,0x18,0x25,0xa5,0x10,0x27,0x07,0x45,0x18,
//address 1 //address 2
0x25,0xf6,0xaa,0x10,0xf7,0x32,0x08,0x43,0xc6,0x08,0x45,
0xf7,0xa6,0x40,0x45,0x18,0x25,0xe7,0x01,0xf6,0xaa,0x80,
0xf7,0x9d,0x9d,0x9d,0x9d,0xc6,0x18,0x25,0xc6,0x18,0x25,
0xa5,0x40,0x27,0xf9,0x81,0x00,0x00,0x00};
#pragma DATA_SEG DEFAULT

//usage of the above assembly code is at 2 levels, a C language interface and code in main.c
//C language interafce
//*************>>> erase Flash page at the the given address ********
void Flash_Erase (unsigned int FlashAddress){
*(unsigned int*)0x843 = 0xE001; //test code i elected to set address immediate because
*(Byte*)0x845 = 0x55; //of the over write problem.
Ram_Routine[22] = 0x40;//flash command
_asm jsr Ram_Routine;}
//*******>>> stores a byte of data onto the Flash at the given address ******
void Flash_Program(Byte data){
*(Byte*)0x845=data;
Ram_Routine[22] = 0x20;
_asm jsr Ram_Routine;}
//************************

//main.c calles everything like this:
Flash_Erase ((unsigned int)0xE001) //must page erase first
*(unsigned int*)0x843=0xE001; //now able to write once to any byte in page
Flash_Program((Byte)0xCD);

//linker command file settings, see the section RAMROUTINE
SEGMENTS
Z_RAM = READ_WRITE 0x0046 TO 0x00FF;
RAM = READ_WRITE 0x0100 TO 0x04FF;
PATCH_RAM = READ_WRITE 0x0500 TO 0x06FF;
XBITTOGGLE= NO_INIT 0x07C8 TO 0x07CF;
TEMP = NO_INIT 0x07D0 TO 0x07DF;
FLASHVAR = NO_INIT 0x07E0 TO 0x07E9;
RAM2 = READ_WRITE 0x07EA TO 0x0816;
RAMROUTINE= READ_WRITE 0x0814 TO 0x0845;
PLACEMENT
DEFAULT_ROM INTO ROM;
DEFAULT_RAM INTO RAM, RAM2;
_PATCH_RAM INTO PATCH_RAM;
_FLASHSECURITY INTO NV_REG;
_ROM_VARIABLES INTO MYROM;
_TABLE INTO KBTABLE;
_FLASHVARS INTO FLASHVAR;
_RAMROUTINE INTO RAMROUTINE;
_DATA_ZEROPAGE, MY_ZEROPAGE INTO Z_RAM;
_TV_TABLE INTO TV_DATA;
_TEMP INTO TEMP;
_XBITTOGGLE INTO XBITTOGGLE;
END

Message Edited by jah on 2006-09-2910:36 AM

0 Kudos