I am developing an application to write contents to a Kinetis KL03 microcontroller by using the "write flash" command in bootloader mode via I2C bus. During system tests we have realized that sometimes the write command fails (due to a power-off, or a problem with the I2C bus, for instance), then it is possible to restore the firmware running on the KL03 by using an emulator.
Since our customers do not necessarily have an emulator, or the end devices may be installed in inaccessible environments, we want the flash write process to become self-recovering, even if it has to start over until it succeeds. However, once the write command has failed, we have found no way to recover it and make it start again, or even reset the bootloader.
Therefore I would like to know how it is possible to return the bootloader to a known, consistent state in order to continue with the write process (after re-erasing flash, if needed). Sometimes the bootloader seems to recognize its own slave address, or even to respond correctly to a ping message, but otherwise we have not been able to send any other command.
Thank you very much in advance.