Ruth Hendrix

PART 1: Flash write gt60

Discussion created by Ruth Hendrix Employee on Jan 24, 2006
This message contains an entire topic ported from a separate forum. The original message and all replies are in this single message. We have seeded this new forum with selected information that we expect will be of value to you as you search for answers to your questions.
 
 
Posted: Mon May 09, 2005 1:41 pm    
 
Hello, i need help...
I write an application that need to write a byte
in flash memory for MC9S08GT60.
I'Have setting the FCDIV with

Code:
void InitFlash(void){
  FSTAT_FACCERR=1;
  FSTAT_FPVIOL=1; 
  FCDIV = 39; 
}


and the function for write the parameter

Code:
void Flash_Byte_Write(byte Dato,unsigned int Address){ 
  //write to flash 
  unsigned int tmp = 0;
  byte * ADD; 
  ADD = (byte *)Address;       
  //se c'è un errore cancello l'errore 
  FSTAT_FACCERR=1; 
  FSTAT_FPVIOL=1; 
  //carico il dato nel buffer della flash
  * ADD = Dato;     
  //mando il comando di programmazione byte singolo
  FCMD = 0x20;            
  //lancio il comando
  FSTAT_FCBEF = 1;
  while(!FSTAT_FCCF){   
  }       
}


with Codewarrior as developer tool, when i launch the debugger and
i use step by step debug, all is ok.
When I don't use the debugger (program run normaly in the target board), the application is not run properly.

I have set the external crystal (36.Khz) and the Bus clock is 7.34 Mhz.
What is wrong ?

Thank in advance
Posted: Fri May 13, 2005 9:26 am    
 
I am having exactly the same problem with a GT32.
 
Posted: Mon May 16, 2005 7:19 am    
 
My flash writing problem appears as follows:

FCDIV=22;

FSTAT=0xFF;
flash_test=0x3c; /* arbitrary byte */
FCMD=0x20; /* program byte command */
FSTAT_FCBEF=1;
asm nop
asm nop /* breakpoint 1 */
asm nop
asm nop /* breakpoint 2 */

If I stop the program at breakpoint 1, the flash memory has been correcly programmed. If I disable breakpoint 1, the program never reaches breakpoint 2. No interrupts are enabled.

Any help will be much appreciated. Thanks in advance.
 
Posted: Mon May 16, 2005 7:47 am    
 
It's really the same problem,
in the freescale bootloader for the GT60 (Gt32..)

AN2295.pdf

The function that write and erase the flash memory is load
in the stack and then is execute from the stack. Shocked

I think that this is the problem (maybe....).
Now I try to do this.... Confused

Posted: Mon May 16, 2005 3:55 pm    
 
Hi user 1,
You can execute code from anywhere, even from registers if not careful. And I would hope the AN author checked his soft...
Are you certain of your clock init routine ?
I'm thinking you could have a different clock between your two modes.

Hi user 2,
Have you tried to break the execution when you never get to breakpoint 2.
It should give status of the MCU and tell you where you are, just to put aside any code runaway situation.

Both,
May you forward the internal bus clock to a pin (via a TIMER or anything) so we can check at which speed it's running and if anything goes wrong Question

Cheers,

Posted: Tue May 17, 2005 6:06 am    

The init clock is created by Codewarrior....

/****************/
SOPT = 2;
SPMSC1 = 28;
SPMSC2 = 0;
ICGC1 = 60;
ICGC2 = 81;
ICGTRM = 128;
while(!ICGS1_LOCK);
/****************/

I check the instruction and is all ok.

Posted: Tue May 17, 2005 7:57 am    

OK, It's Right,
I use the stack for execute the function
that write-erase flash and it's ok.

Posted: Tue May 17, 2005 11:55 am   

Hi,

 

Code:
ICGC1 = 60;
ICGC2 = 81;



means that you get low speed speed (range=P=64), Multiplier of 14 (MFD=101) and divider of 2 (RFD=001). Therefore bus frequency is:

 

datasheet wrote:
fext * P * N / R



You get, from a 36kHz osc => 16.128MHz
I don't see how you get 7MHz bus.

Also

 

 

Code:
ICGTRM = 128;


looks like a default value and that the internal oscillator is not really trimed.

What am I missing ?
Cheers, 

Posted: Tue May 17, 2005 12:52 pm    

Yes, but the crystal is 32768 Hz and then
the FBus is FCLK /2, where

FCLK = P *N/R *FCRYSTAL

using P=64 N=14, R=2

so the FBus = 7340032 Hz

Page 109 of datasheet GT60 and example 7.4.2 page 112

Posted: Tue May 17, 2005 1:17 pm    

Oki, I get it. Coz my 16...MHz divided by two were far from 7MHz.
But the reference was different!

And about the trim? Are you sure you stay within specified time for Flash timing. Anyway, even slightly out, it should not be an issue.

Posted: Tue May 17, 2005 1:21 pm    

It's not important,
you can cut the line TRIM=128,
it's only because i have make cut and paste from
another project and i forgot to eliminate the line Embarassed

Posted: Wed May 18, 2005 8:40 am    

Thanks for the input. Could you please give me an example of executing the commands from the stack.

Posted: Wed May 18, 2005 9:18 am    

OK,
You Can Download from freescale the Software

AN2295SW.zip of the application AN2295

It's the Bootloader for the GT family.
If You search inside zip, You will find the file

slfprg-s08gbgt.asm

in this file you can cut and paste the function ERASE_COM and WR_DATA_COM, cut the part of the serial port.
Use this functions and call from another asm routine or c function.

Ok ?

Posted: Thu May 19, 2005 8:16 am    

you are a champ. Many thanks

Posted: Tue Sep 20, 2005 6:59 pm    

any other guru:

I am pretty new to f/w programming and not really familiar with assembly language

I have been trying max's solution of using code from slfprg-s08gbgt.asm for quite some time now.

Could anyone please print out the exact(independent) assembly code that should be included and code in C calling those assembly functions?

I have trying to pass arguments to assembly functions without much success

Thanks


 


Message Edited by RChapman on 01-24-2006 02:24 PM

Outcomes