Hello, and welcome to the forum.
I can see a couple of issues with your sector erase code.
Firstly, you have globally disabled interrupts near the start of the function, and have then incorrectly re-enabled interrups after the command is launched. Interrupts should not be re-enabled until after the FCCF flag is set (or an error exit occurs). The flash cannot be read during the execution of the command, so the interrupts vectors are inaccessible. It is possible that a hardware interrupt, perhaps a timer interrupt, could occur during the 20 millisecond sector erase period.
Are you using the derivative header file associated with the CW installation? If so, you seem to be using the bit identification macros, rather than the bit mask macros required by your expressions. For example,
FSTAT |= FSTAT_FCBEF; should be corrected to the following
FSTAT = FSTAT_FCBEF_MASK; // Launch command
Similarly, for the error flag tests.
while(!(FSTAT & FSTAT_FCCF_MASK)) { }
Personally, I would not bother with a separate test of the FCBEF flag, since the FCCF flag indicates the completion of the command. In fact, for more compact code, I would probably derive a composite mask for the FCCF flag and the two error flags, and then exit the wait loop when any one of the three flags became set.
Note that not all your code needs to reside in RAM, only the code between the launching of the command and the exit from the wait loop.
For the DZ60 device you also have another alternative to running the code from RAM. It should be possible to store and run the code in EEPROM flash, which is separate from the main flash array.
Regards,
Mac