Details:
nRF52832
SDK 14.1 with matching SD
Compiling with GCC
I am trying to solve the following problem:
My device is powered by a coin cell (Manganese dioxide). When these cells reach their capacity their internal resistance increases.
If my device attempts a Bluetooth communication this may cause the battery voltage to dip below the brownout voltage - triggering a system reset.
It is then possible that during startup the device draws too much current and dies again, thereby creating a loop of power cycling which will continue to drain the battery until dead, but also potentially corrupt flash memory in the process.
My current methodology is to somehow keep a count of the number of resets that gets set to zero after startup, if the device resets 5 times without finishing the startup process, kill the startup and go into system off mode.
Unfortunately, no registers are retained on a brownout reset, so I cannot use them to store information on the reset.
I could use flash, but there is a risk of corrupting all of the flash data in the startup sequence as the power could die during initialisation or mid-write.
The solution that seems to be the most elegant is to simply store a variable in RAM, and create a "noinit" section as described here: noinit example
This seems to work for watchdog resets and software resets, but doesn't seem to work for pin resets or brownout resets. On a pin reset (easier to do), the values on reset are pretty consistent, which leads me to believe that some other part of the program that I'm not aware of it writing to that memory?
Are there any other methodologies I could try here? What is the Nordic best practice around this?