another eeprom emulation thread.

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

another eeprom emulation thread.

3,330 Views
malcolor
Contributor I
 
hi everybody. first at all, sorry for my poor english, but i hope you can understand me.
 
i'm trying to use a page from flash for eeprom emulation, but i can't and i have read the posts i have found about this topic, but i have triple checked every detail and no bytes written on my flash.
 
i modify the .prm file for a eeprom emulation page (from 0xe000 to 0xe1ff); althought i dont use the relocate instruction. i use a "#define const" for write the right value on the security registers (NVPROT = 0xff and NVOPT = 0x7e). i have selected de FCDIV value for a166KHz flash clock.
 
i don't use the P&M debugger in my test code for avoid secure troubles from the debug mode. i have a code that writes a value in the first flash page, then i read that value and if it's 0xff, i blink a led in a way, and if it isn't i blink that led in another.
cause always get the "0xff value led blinking", i have try to erase the flash page before writting, but my uC resets when execute the erasing routine.
 
if you need more information about my tests and code, please, say it. thanks a lot.. i'm going crazy with the flash.
thanks again.


Message Edited by malcolor on 2008-03-04 04:33 PM
Labels (1)
0 Kudos
10 Replies

739 Views
malcolor
Contributor I
ok. thanks denn and bigmac. i'm writting on flash using the c routines that copies flash code into ram (copyprogram(), runprogram()...); i don't remember the name of the zip file (qg eeprom 6 or something like that).
 
i'd like to study all the alternatives and optimize my code if i had more time, but i need the eeprom emulation, and i will use this solution by the moment.
when i'll have time, i will read all the possibilities and i'll try to use the asm code.
 
thanks a lot again. i wouldn't do it without your help.
see you.
0 Kudos

739 Views
malcolor
Contributor I
right. now i know that i need to execute the flash programing from ram, but how can i do it? a asm do_on_stack code?
 
i will try to execute from ram using the do_on_stack and spsub code. i'll say you..


Message Edited by malcolor on 2008-03-06 11:37 AM
0 Kudos

739 Views
bigmac
Specialist III
Hello,
 
There are two possibilities.  One method is to copy the RAM based code to the stack, and execute from
there.  The other method is to use a fixed block of RAM.  The latter method is the simpler of the two, and
is used within the following recent thread.
 
Later in this thread, alternatives are given that are more suited to devices such as the 'QG8, with limited
RAM capacity.  These alternatives do not allow for burst mode programming, but result in less RAM
being used.  For the examples I refer to, the RAM based code is copied to the lower reaches of the RAM
segment occupied by the stack, but always to a fixed address.  A separate function is provided to copy
the code into RAM, which must be called prior to flash erase and programming operations.
 
Finally, I don't believe it is necessary to use far pointers for the 'QG8, since addresses do not exceed
16-bit values.
 
Regards,
Mac
 


Message Edited by bigmac on 2008-03-07 03:22 AM
0 Kudos

739 Views
Denn
Contributor I
Hello Malcolor,
 
Also check this posting.Very interesting way of reducing RAM relacatable code!!!
 
Regards,
Denn
0 Kudos

739 Views
malcolor
Contributor I
i know that in 16bits freescale family, is necesary to execute the flash routines from ram rather tan flash, but i have  double read the datasheet of hcs8 family and i haven't found any reference to this matter. somebody can tell me if the relocate code in .prm file is for execute the flash routines from ram?
 
thanks a lot. i will say you my steps..
0 Kudos

739 Views
Denn
Contributor I
Hi Malcolor,
 
Please Refer HCS08 Family Reference Manual, Rev. 2
 

4.8.2 Erase One 512-Byte Page in FLASH- Page 60
Program and erase operations for the FLASH memory are a little more complicated compared to many
application programs because it is not possible to execute a program out of FLASH during FLASH
program and erase operations.
 
If we access flash during erase/programming results in the undesired behaviour.
 
Regards,
Denn.
0 Kudos

739 Views
malcolor
Contributor I

well. thanks for your replys.

i'm using MC9S08QG8 controller, whit a bus clock of 0,5MHz. The FCDIV value is 2, so the flash clock is 166KHz.
i have solved the reset problem when i erase a page (the dummy byte that i had using was an int), but i can't write my byte in the flash.

my .prm file, is like this:

Code:
NAMES END /* CodeWarrior will pass all the needed files to the linker by command line. But here you may add your own files too. *//* Here all RAM/ROM areas of the device are listed. Used in PLACEMENT below. */SEGMENTS     MIROM                    =  READ_ONLY    0xE000 TO 0xE1FF;  // primera pagina para los valores de frecuencia e id.    ROM                      =  READ_ONLY    0xE200 TO 0xFFAD;    Z_RAM                    =  READ_WRITE   0x0060 TO 0x00FF;    RAM                      =  READ_WRITE   0x0100 TO 0x025F;    ROM1                     =  READ_ONLY    0xFFC0 TO 0xFFCF;//  CODE_RELOC               =  READ_ONLY    0xe200 TO 0xe240 RELOCATE_TO 0x0060; ENDPLACEMENT /* Here all predefined and user segments are placed into the SEGMENTS defined above. */    DEFAULT_RAM                             INTO  RAM;    DEFAULT_ROM, ROM_VAR, STRINGS           INTO  ROM; /* ROM1 In case you want to use ROM1 as well, be sure the option -OnB=b is passed to the compiler. */    _DATA_ZEROPAGE, MY_ZEROPAGE, MIRAM      INTO  Z_RAM;ENDSTACKSIZE 0x50VECTOR 0 _Startup /* Reset vector: this is the default entry point for an application. */


 
and the write function:

Code:
//Escribe un word en la direccion de memoria flash que se le indicaunsigned char escribeWordFlash(unsigned int *far far_address,unsigned char data){     FSTAT = (FSTAT_FACCERR | FSTAT_FPVIOL);                         // clear errors         (*far_address) = data;                                             // Store desired data to address being programmed   FCMD = 0x20;                                                 // Store programming command in FCMD FSTAT_FCBEF = 1;         asm {                nop                nop                nop                nop        };        if (FSTAT_FACCERR)      return Access_Error; if (FSTAT_FPVIOL)      return Protection_Error;         while (!FSTAT_FCCF);            //Wait for all commands to complete return 0;}


 i disable the interrupts before the writes operation, and don't use the premicro debugger while i'm trying to write.

thanks again.

0 Kudos

739 Views
Denn
Contributor I
Hello Malcolor,
 
I think you need to insert a line

while((FSTAT & 0x80)!=0x80); //  Wait till FCBEF is set

before the line       (*far_address) = data;

 

 

Please refer Section 4.5.4 Access Errors in HCS08 Family Reference Manual, Rev. 2 Page 53

->Writing to a FLASH address while FCBEF is not set (A new command cannot be started until the command buffer is empty.)

 

 

 

And make sure the code is running from RAM rather than from FLASH.I have not worked on CodeWarrior IDE so I really cannot comment on the .prm file.

Its a wild guess.I'm not sure.In your .prm file you have commented the relocating part.

 

Regards,

Denn


 

0 Kudos

739 Views
Denn
Contributor I
Helo Malcolor,
 
If you are using HCS08 controller
Check out the document HCS08RMV1 table 4-7 page 54.
 
For more details its better to check that particular controller's datasheet.Also what is the bus clock used??Also value for FCDIV=??? it should be within the range of 150kHz to 200kHz for proper flash operation. Crosscheck this with the value loaded in FCDIV..
 
If you give more details, may be someone here could solve your problem.
 
Good Luck!
 
 
Regards,
Denn
0 Kudos

739 Views
bigmac
Specialist III

Hello, and welcome to the forum.
 
Firstly, you will need to say which MCU part you are using.  Secondly, you will need to detail the code you are using for EEPROM emulation.  If the code is from a thread on this forum, identify the thread, preferably with a link to it.
 
A reset during the page erase process suggests that COP timeout is possibly occurring.  Try disabling the COP timer, and see if the reset still occurs.
 
Regards,
Mac
 
0 Kudos