I'm currently using the flash module of MPC5748G. In the reference manual, it mentioned that during flash program/erase, after initiating the program/erase action, you need to wait for MCR[DONE] to go high. I'm pasting the whole sequence in below:
1. Change the value in the MCR[ERS] bit from 0 to 1.
2. Select the block or blocks to be erased by writing ones to the appropriate registers in
SEL0, SEL1, SEL2, or SEL3 registers.
Lock and Select are independent. If a block is selected and
locked, no erase occurs.
3. Write to any address in flash memory. This is referred to as an erase interlock write.
An erase interlock write to UTest NVM space is not allowed if sealed (since erase is
not allowed in the UTest NVM space when sealed).
4. Write a logic 1 to the MCR[EHV] bit to start an internal erase sequence or skip to
step 9 to terminate.
5. Wait until the MCR[DONE] bit goes high.
Since MCR[DONE] clears with MCR[EHV] being set, it
may not be possible for software to read MCR[DONE] as a
0 prior to this step, depending on the operation selected.
6. Confirm MCR[PEG] = 1.
7. Write a logic 0 to the MCR[EHV] bit.
8. If more blocks are to be erased, return to step 2.
9. Write a logic 0 to the MCR[ERS] bit to terminate the erase.
The problem I'm running into is that I'm trying to erase a block (4K) at a time, however, it's taking too long. If I do as the reference manual says: to wait for the DONE bit to go high, it's blocking other processes for too long. So I'm trying to figure out: what's the best practice to negate this. I can think of some options:
1. I can try to segment the block and erase them part by part, but this is not very elegant
2. I can skip the waiting part, and just check the DONE bit whenever I have to do another program/erase. But how do I perform the steps afterwards (step 6,7,8,9)? Can you set a software interrupt when the DONE bit goes high? Or do you have to poll the register, say, every second?
Or is there some other more elegant way of doing this?