intelligent-agent / Refactor

Linux distro for 3D-printers
https://wiki.iagent.no/wiki/Refactor
GNU Affero General Public License v3.0
28 stars 18 forks source link

Add support for power lost detection #233

Open eliasbakken opened 3 years ago

eliasbakken commented 3 years ago

A decreasing voltage level can be detected by the STM32. This event can be used to save information in the MCU itself and to signal the host SoC (A64) that power has been removed. During normal standstill operation, the time from a voltage drop can be safely detected until power is lost on the 3.3V line has been measured to be about 6 ms.

eliasbakken commented 3 years ago

I've done some tests on the STM32 and with few changes to the mainline Klipper code, it is possible to check the input voltage at a frequency of 0.1 ms which should be sufficient. Further more, I've managed to save the position to Flash in the upper page. Erase size is 1 KB, the code is only about 12K and the total flash size is 16K. The time to store 5 half words to flash is 275 us. If this is going to be a working solution, the host needs to send it's position at regular intervals. That information is not available to the MCU. There is also some work that needs to be done in order to get information back form the MCU once power is reapplied. For testing, this can be done by the stm32flash program to read out a location in flash, but as a part of klipper it can be done with an MCU command. It is important that a page erase is not done automatically on boot of the MCU, that would remove any information stored during shutdown. A cleanup could be done last minute as part of starting a new print. SDS5034X_PNG_5 This picture shows the time it takes to run a "save to flash" operation. The sequence was triggered by shutting off power.