2021-03-02 05:48 AM
Hello,
We have currently moved on to the STM32G4 series, and we are now looking at a project where data will be occasionally written to flash under control of our own code. Of course, this exposes us to flash memory corruption during unforeseen power loss events. To protect against this, I intend to use the internal Power Supply Supervisor block of the microcontroller.
I am tempted to directly use the BOR threshold to protect us, so that the microcontroller gets reset as soon as the voltage drops under some 2.9V. This will still give us some time (based on on-board capacitance discharge time) until the voltage drops below the 1.7V minimum operating voltage so that the eventual flash memory write operation would have time to finish. We plan to write a maximum One row (32 double word) at a time, so the micro power supply has to be able to remain above the 1.7V threshold for 2.7ms, which is the maximum t_prog_row value. Whereas I can ensure such a low decay of voltage, with sufficient on-board capacitance, it is unclear to me if already started flash write operations are allowed to finish in case a BOR occurs. Do you know if this is the case?
I have seen in other documents indications that the PVD (Programmable Voltage Threshold) must be used to detect a falling supply voltage and to trigger an interrupt, which would then allow the micro to not initiate any other flash writes. But this would take som considerable time, I suppose.
Best regards,
Cristian
2021-04-14 07:50 AM
Hi brumbarchris (Community Member),
The setting of BOR level to higher level causes the situation worse. The BOR reset performs complete MCU reset (like you press reset button) - and therefore the ongoing programming of Flash is immediately interrupted: programming is stopped immediately at BOR reset (high voltage charge pump used for programming is stopped, all logic is reset, ... ).
We suggest to use PVD detector for such usage - the additional time (entering the interrupt routine) is very small (some microseconds) comparing to programming time of Flash (milliseconds range). You must take care if Flash programming is done from the same Flash bank - then the code execution is stopped and any interrupt cannot run from the same Flash bank. I suggest to:
If the MCU doesn't need to run the main code during Flash programming - I prefer solution 1.
Regards
Igor