cancel
Showing results for 
Search instead for 
Did you mean: 

STM32G4 Flash writes at BOR

brumbarchris
Associate

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

1 REPLY 1
Igor Cesko
ST Employee

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:

  1. Simple solution: Do not use interrupts from PVD detector but during Flash programming run code in SRAM and this code will check in a loop the PVD detector state. If PVD event occur then perform required safe operation (stop next programming and prepare MCU to power down reset).
  2. Solution with interrupts: Move interrupt vector table into SRAM, move interrupt service routine from PVD into SRAM. Then if PVD interrupt occurs during Flash programming the interrupt is invoked and the interrupt service routine for PVD will be performed (same actions: prepare MCU for power down reset).

If the MCU doesn't need to run the main code during Flash programming - I prefer solution 1.

Regards

Igor