Is there a way to generate falling and rising events on the reset pin of STM32L0xx? The idea is to do a regular hw reset it when quick pressed when pressed and hold to load the factory settings. Thank you!
The falling edge "event" is that your software stops running and all the volatile registers (apart from in the backup domain) return to their default value. DRAM may also be corrupted but SRAM should retain its contents as long as power is not interrupted.
The rising edge "event" is that your software starts running again from the reset handler function in the interrupt vector.
If you want to time how long the reset was, then you need a clock that carries on counting through the reset. The RTC meets this requirement.
You can read the value of the RTC at startup, and compare it to the value it had before reset.
The hard part is how to know after reset what the value of the RTC was before reset, when the reset clears or corrupts various memory and comes when you aren't expecting it.
One approach would be that while your application is running, you copy the RTC clock value to the RTC backup registers on a regular basis, for example from the SysTick interrupt. The backup registers behave just like normal RAM except that they retain their value when the main regulator is turned off. This means the value in them after reset will be the RTC value of the last time the systick interrupt ran before the reset.