Hello,
I have a problem when erasing the internal memory block on an XC167CS-32F microcontroller.
I can erase sectors 0, 1, 2, and 3 OK. Sector 4 fails to erase, but then sectors 5, 6, and 7 erase OK.
I can write to all of the sectors (with the exception of sector 3).
The Keil uVision 'Flash->Erase' instruction DOES manage to do the erase correctly, so I know that my device is OK - it is just down to something that I am doing wrong.
Is it possible that one of the sectors (sector 4) has become 'protected', and if so, how do I go about reseting things so that the sector is no longer protected !
Thanks for you help,
Simon May
If you think the sector is protected have you examined the value in the PROCON ro confirm this?
In addition you can check the Flash Status Register (FSR) as you try to program or erase to help you understand if any errors are occurring.
Chris,
Firstly, thanks for getting back to me, and thanks for the steer. This forum is definitely the most effective way of getting problems resolved.
As for the actual issues, as a result of your post, I have run the code again - through the debugger - and have looked at the PROCON register (at address 0xFF'F004). The data at that address is 0x00 - and remains that for each loop through the execution.
As for the FSR. The code that I have written carries out the erase instructions and then calls a function 'FSR_test' before returning to the calling function. The function FSR_test is as follows :
static __inline bool FSR_test ( void ) { union fsreg fsr ; do { fsr.v = FSR_read() ; /* read the flash status register */ } while ( fsr.b.busy ) ; /* wait whilst Flash is Busy */ if ( fsr.b.oper || fsr.b.sqer || fsr.b.proer ) { /* we've read the status register, and it tells us that there's been an error */ /* reset the flash ROM module to read mode */ XC167Flash_reset_to_read() ; /* ... failure */ return ( FALSE ) ; } if ( fsr.b.prog || fsr.b.erase ) { FSR_clear() ; /* clear the flash status register */ } return ( TRUE ) ; } /* FSR_test */
Thanks again, Chris. Any further thoughts, much appreciated.
Hi Simon,
Do you still have a problem to erase?
If I were to write it, assuming this is an in-system reprogramming. I would do the following:
1) Load the erase/write routines into PSRAM (from my boot code) 2) Perform a Reset-To-Read command sequence 3) Perform a Clear-Status command sequence 4) Call the erase function in the PSRAM 5) Perform an Erase command sequence (passing the SLOC which is the first (lowest) location within the target sector, e.g. C0'6000H for sector 3) 6) Check for any errors and make sure both FSR.ERASE and FSR.BUSY are true 7) Use a hardware timer to set a timeout that exceeds the maximum erase time 8) Enter a loop waiting for both FSR.ERASE and FSR.BUSY to clear or if a timeout occurs 9) Return from the erase routine with the status 10) Repeat as needed or take error actions
Just one other comment, I don't think there is anything wrong with using "C" for the flash routines as this is a user preference but I usually choose to write them in assembly and provide a "C" wrapper.
-Chris
Just wanted to say thanks - you've given me some things to think about and try out.
I will post back if I have any more insight into the problem.
Simon
View all questions in Keil forum