Issue in Erasing flash for MC9S0SG16

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

Issue in Erasing flash for MC9S0SG16

Jump to solution
1,145 Views
girichavana
Contributor II

Hi,

 

I have implemented the flash erase routine in C to erase the 3 pages of flash form 0xFA00 tp 0xFFFF. The routine is erasing the First page only (i.e the page 0xFA00). If i keep the brake point at the last line of the erase routine, then i am able to erase the three pages. But with out brake point i am unable to erase all the three pages. below is the algorithm of main and erase routines.

 

Main routine:

1. Load FCDIV for to set the clock 200KHz

2. Disable interrupts

3. Call the Erase routine to erase the page starting at 0xFA00

4. Call the Erase routine to erase the page starting at 0xFC00

5. Call the Erase routine to erase the page starting at 0xFE00

 

Erase Routine:

1.Wait for last Command to complete

2. Load FSTAT to clear the error flags

3. Load the address in page with dummy data

4. Set FCBEF

5. Check FSTAT for errors

6. Wait for FSTAT_FCCF for command completion

 

The main and erase routines are running in the flash starting from location 0xC000.

I am using CodeWarrior for MCU Version: 10.1

Labels (1)
0 Kudos
1 Solution
841 Views
kef
Specialist I

The problem is your flash routine executes in flash. And flash is not readable while it is being erased or programed. Code from 4. to 6. has to be moved to and execute from RAM.

You can check FSTAT for errors before 4.


View solution in original post

0 Kudos
8 Replies
842 Views
kef
Specialist I

The problem is your flash routine executes in flash. And flash is not readable while it is being erased or programed. Code from 4. to 6. has to be moved to and execute from RAM.

You can check FSTAT for errors before 4.


0 Kudos
841 Views
girichavana
Contributor II

Hello Edward,

Thanks for the clarification.

With your reply, I came to a conclusion that, the entire flash is not readable if we erase a single page in the flash. Please confirm this.

If it is so, Please clarify, how it is erasing if I keep a break point with the debugger in the erase routine.

Thanks&Regards

Giri Chavana

0 Kudos
841 Views
kef
Specialist I
  • With your reply, I came to a conclusion that, the entire flash is not readable if we erase a single page in the flash. Please confirm this.

That's usually is true. Parts with lots of flash (128k or more) may have 2 or more flash banks. One bank is readable while other is being programmed/erased.

  • If it is so, Please clarify, how it is erasing if I keep a break point with the debugger in the erase routine.

You may stop CPU just before flash gets unreadable, but flash command isn't stopped and you see erased/programmed bytes as expected. But just remove breakpoint, run you code, and CPU will jump into the weeds.

0 Kudos
841 Views
girichavana
Contributor II

Hello Edward,

Thanks for the clarifications,

Could you please explain a simple way to run my erase/program routine from RAM. I have the routine that is compiling in Flash.

Thanks&Regards

Giri Chavana

0 Kudos
841 Views
kef
Specialist I

You didn't say whether you need it for C or for asm, also what version are you using. Code in RAM was discussed many times already. Use search. My favorite method is this https://community.freescale.com/thread/69468

0 Kudos
841 Views
girichavana
Contributor II

Hi,

I am working with CW V10.1 in C language

0 Kudos
841 Views
bigmac
Specialist III

Hello,

There are two basic methods of executing code within RAM -

  1. Placing code on the stack, and executing from there - commonly known as the "doonstack" method.
  2. Making use of a fixed block of RAM at a defined location, maybe at the bottom of a specific stack segment.

I would consider the second method to be the simpler one.  I have attached some code that uses this method.

Regards,

Mac

841 Views
girichavana
Contributor II

Hello,

Thanks for the support and helpful information.

Regards

Giri

0 Kudos