Save cumulative counter value to a flash/permanent storage

I totally agree with @philip Now that we have a better grip on what you are looking to do, it sounds perfect for persistent variable use.
(Don’t forget to use OptoTagPerserve when you do your firmware updates and you should maintain that data for many years seamlessly).