Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
save RAM content overridden by bootloader magic
and restore it in case of aborted reboot use RAMEND-1 as suggested by @yyyc514 in PR arduino#2474 of course it's not a real solution but we cannot force everyone to update the bootloader using an external programmer
- Loading branch information
95b1550
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, this is a neat trick, and an improvement, but not a real solution as you mention.
Is the USB stuff not interrupt driven? Is there a reason we can't just delay(125) after the watchdog? Freezing the running program would prevent the memory corruption from being seen while we're not sure if a reboot is going to happen... if we could swap the memory in and out + delay I think that would be a pretty solid fix.
95b1550
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would mean you need to re-enable interrupts inside an interrupt handler, which is possible but might make things more complex than you'd want (if the host quickly toggles the baudrate or dtr, the stack could overflow, I think).
95b1550
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, because we need the timer for delay.
95b1550
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And because you want to allow cancelling the reset again, which needs an interrupt?
95b1550
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems you could pair this fix with a user-space pause inside
loop
that was something like this (pseudo code):This would effectively "pause" user space while a reboot was possibly happening and prevent bad behavior or memory corruption. Would this be a reasonable recommendation for someone who wanted absolute stability and who was compiling with a patched CDC that was preserving memory?
95b1550
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Obviously this would be program specific... but all my issues stem from that location being active memory... and either it's value MATTERS, or it's being changed too rapidly by user space and the reboot never even happens because by the time the WDT fires the memory location is no longer 7777.