11 years, 2 months ago.

Variable value after watchdog reset

Hi, How can I keep variable value (RAM) after a watchdog reset in mbed? Thankyou

2 Answers

11 years, 2 months ago.

Easiest would be simply writing it to the local filesystem. There is a bit in a register set after a watchdog reset also, which can help (see the lpc1768 user manual).

I am not even sure if ram is cleared during watchdog reset, but it probably wont be the savest place to store data. The RTC has a few general purpose registers which shouldnt be cleared during a watchdog reset.

11 years, 2 months ago.

The startup generated by the compiler initializes all "normal" variables so you need to use something else. I see two options:

1) place your variable into a different RAM area which is not touched by the compiler. For example, on LPC1768 you can use the "AHBSRAM1" area which is intended to be used by Ethernet code but available for other uses too:

unsigned int myvar __attribute__((section("AHBSRAM1")));

2) use RTC registers to store your state. This has an additional advantage that they will remain even after full reset or power-down, as long as Vbat is powered.

LPC_RTC->GPREG0 = my_var;
...
my_var = LPC_RTC->GPREG0;