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
已解决! 转到解答。
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.
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.
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
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.
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.
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
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
Hello,
There are two basic methods of executing code within RAM -
I would consider the second method to be the simpler one. I have attached some code that uses this method.
Regards,
Mac