ajn96/iSensor-SPI-Buffer

Add hardware power loss protection

ajn96 opened this issue · 3 comments

ajn96 commented

SD cards (especially with FAT file system) are very vulnerable to corruption if a file write is not properly terminated (due to power loss).

This vulnerability can be mitigated by placing a high capacitance capacitor on the buffer board supply line (after the 3.3V regulator), and monitoring the input voltage to the cap in software using the STM32 ADC. If the input voltage falls under a low operating threshold, the software can stop any running SD card data logging and safely clean up any open files, before the system loses power.

The STM32F303 can operate with VDD = 2.0V, and SD cards can safely operate with VDD = 2.7V. Powering the buffer board and SD card will require ~50mA of average current. To ensure a consistently safe amount of file cleanup time, VDD must stay above 2.7V for at least 100ms after power is lost.

(3.3V - 2.7V) = 50mA * 100ms / C
C = 8.3 milliFarads to ensure 100ms uptime for SD card + micro

This capacitor (designed as "battery" back up) could work well:
https://www.digikey.com/product-detail/en/seiko-instruments/CPH3225A/728-1127-1-ND/8692445

ajn96 commented

Will probably have to do some bench prototype testing for this feature. May not make it into rev C.

ajn96 commented

This feature might not be needed. Each SD card write syncs immediately, so power loss most of the time will not cause problems

ajn96 commented

Won't do - board does not seem super susceptible to data loss, and button will reduce occurrences of data loss during a script run