Hello iRob,
Further to Alban's suggestion to monitor when the vector erasure occurs in relation to the operation of your program, in order to help diagnose the problem, here is a suggestion -
Should the vectors become erased, normal operation of your program should continue up to the point where an interrupt event occurs, or there is a reset. I am suggesting to allocate an additional byte, within the flash page that holds your non-volatile data, for the purpose of writing an error code. Then implement the following sequence within the portion of code that handles the writing of data -
Disable interrupts
Initialise a test counter
Vector test routine - just in case there is some other cause
Increment test counter
Erase flash page
Vector test routine
Increment test counter
Write flash data
Vector test routine
Repeat for other flash pages to be erased and written.
Re-enable interrupts, as required.
The vector test routine would simply test the byte value at address $FFFF, and if found to contain the value $FF, write the current test count value as an error code, and then cause an immediate reset (perhaps by the illegal instruction method).
Subsequent examination of the flash contents would enable you to identify the position in code where the vector had become corrupt.
A while back I did disassemble part of the ROM code of a QY device from my existing stock ( of more recent manufacture), and found it corelated to the code listing given in AN1831.
Incidently, I have been using the ROM routines, without apparent problem, in a mature product of at least three years. I erase the first page of flash, and then program the first two bytes only. However, this will generally occur only a few times during the product lifetime - perhaps I have been lucky. Long COP timeout is enabled, and I reset the COP timer a few instructions prior to the ERARNGE sub-routine being called.
Regards,
Mac