MC9S12Q96 / MC9S12C96 FLASH Module - Reg.

cancel
Showing results for 
Search instead for 
Did you mean: 

MC9S12Q96 / MC9S12C96 FLASH Module - Reg.

2,657 Views
Pramodkorti
Contributor I
I have used Freescale Codewarrior ver 4.5 for programming Flash in MC9S12C96. The problem that I am facing is as follows
 
1. I am not able to write more than two bytes at once. After writing two bytes, I am getting access error and the flash program is comming out.
2. If the program is executed using single step (F11) option in debugger mode, the required amount of data is written on to the flash locations as desired.
3. If the program is run in a single strech (F5), then only two bytes are written and the program hangs.
 
Flash programming was done with all interrupts disabled while write operation was in progress.
 
Please suggest some alternative method for programming flash or a sample code for writing and reading would be very useful.
 
Regards,
 
Pramod Korti
Labels (1)
0 Kudos
6 Replies

70 Views
J2MEJediMaster
Specialist I

Have you studied app note 2548 (AN2548.pdf) yet? It covers some of the basics of Flash programming.

 

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

Message Edited by t.dowe on 2009-09-10 12:35 PM
0 Kudos

70 Views
Pramodkorti
Contributor I
Yes, I have gone through it and still I am not able to resolve my problem.
 
When the code for writing into Flash is run using single stepping in Code warrior, the debugger shows that required amount of data is written properly into the hardware. But the same is not the case when we run the whole application at once. I wanted to now if debugger issues any stop command to the microcontroller in between the write function of FLASH.
 
The required data to be written into flash was kept in RAM first and then the write operation was carried out. Here I was not able to write more than two bytes. Second time the data to be written was kept in a seperate FLASH memory space and the same was tried, but I was not able to write more than two bytes.
 
Every time after writing first two bytes, I have ACCERR Flag set in FSTAT register.
0 Kudos

70 Views
kef
Specialist I
Pramodkorti,
 
do you know that while programming/erasing/backdoor unsecuring/"data compress"ing the flash module memory is NOT READABLE. This means that MCU executing flash programming/erasing/etc code from flash will suddenly loose the read access to program memory and will hang. What you are experiencing (single stepping through flash programming code works but at full speed doesn't etc) are the signs that you run flash programming code from flash. Move it to RAM and I believe it will start working
 
Regards
0 Kudos

70 Views
Pramodkorti
Contributor I
Yes, I had tried to write Flash memory from RAM as said in my previous message, but this also fails after writing first two bytes.
 
Please let me know if anything other than this can be tried.
 
Regards,
 
Pramod
0 Kudos

70 Views
kef
Specialist I
You wrote previously:


Pramodkorti wrote:
The required data to be written into flash was kept in RAM first and then the write operation was carried out. Here I was not able to write more than two bytes. Second time the data to be written was kept in a seperate FLASH memory space and the same was tried, but I was not able to write more than two bytes.


Your programming routine fails not because source data is in bad place, but because flash programming routine itself is in bad place.

 


0 Kudos

70 Views
Pramodkorti
Contributor I
I agree to your statement, I had followed below method for placing the flash
programming routine in RAM:-
#pragma CODE_SEG __PIC_SEG __NEAR_SEG PIC_CODE
void __far Function(void) {
}
void __far NextFun(void) {}
#pragma CODE_SEG DEFAULT
char RamBuf[100];
void Test(void) {
  void (*__far startFunPtr)(void)= Function;
  void (*__far endFunPtr)(void)= NextFun;
  void (*__far bufferFunPtr)(void);
  char *__far startDataPtr;
  char *__far endDataPtr;
  char *__far bufferDataPtr= RamBuf;
  int i=0;
  CONV_FAR_FUN_TO_DATA_PTR(startDataPtr, startFunPtr);
  CONV_FAR_FUN_TO_DATA_PTR(endDataPtr, endFunPtr);
  CONV_FAR_DATA_TO_FUN_PTR(bufferFunPtr, bufferDataPtr);
  while (startDataPtr != endDataPtr) {
    RamBuf[i++]= *(startDataPtr++);
  }
  bufferFunPtr();
}
Please let me know if something is wrong here.
Regards,
Pramod
0 Kudos