Watchdog timer reset and MCUCSR register flag WDRF always se to zero

I started using the watchdog timer (functions wdt_enable() and wdt_reset()). I hoped that after the watchdog timer generates the reset I would be able to read the Watchdog Reset Flag (WDRF) from the MCUCSR register (ATmega8A Data Sheet).

However I found that all MSUSR bits are always set to zero after the reset. My understanding from various threads on this forum is that this is the standard behavior of the Arduino bootloader. I guess it is implemented that way for a reason and there is no way I can check the WDRF value?

Note:

I seem to recall that newer builds of Optiboot software didn't zero out that register. Installing a newer bootloader may fix the issue for you.

That's correct. If you install AVRDude's MegaCore, it includes a version of Optiboot that has features to better preserve the content of MCUCSR for the application. You will need to burn the new bootloader onto your Mega (getting back 7k of flash space in the process!)

@westfw | @markd833 Thanks for the advices.

I have never replaced (burned) the bootloader, so that's something to learn first. I will check some articles how to do that.

Meanwhile I looked into the boards.txt from Arduino IDE subfolder to see what 's there and among other information I found that for Arduino Mega 2560 board there is defined the current bootloader file as mega.menu.cpu.atmega2560.bootloader.file=stk500v2/stk500boot_v2_mega2560.hex. So I guess that's the file I will be replacing? But I need to read about the whole process first.

No need to replace the file (and it wouldn't be enough.) Once you install the MegaCore boards, they'll have their own copy of the newer bootloader.