Empty backup ram on larger OTA updates

What’s the best way to empty retained memory/backup ram on just after OTA update? Basically I’m thinking scenarios where we have to do bigger firmware update and changes to the backup ram functions are significant. In these scenarios it would be good to be able to fully reset the backup ram.

One idea for workaround I have is have first retained variable a “retained memory version”, some number. If it doesn’t matches whatever you hardcoded in the firmware, it is either update or there is nothing stored (after losing power) [update: and then you reset all variables].

@tuxie, you could use system events to detect when a firmware update is about to occur or has occurred and clear the backup RAM accordingly.

@lami and @peekay123 Thanks. I think I was a bit unclear. How can I actually clear the whole memory block so that there’s nothing left? Just to be sure I’m always starting from “blank slate” and that there’s no weird problems due to leftover bytes…

@peekay123 also I tried that but for some reason didn’t work. I did something like this but it didn’t really work:

void reset_handler(system_event_t event) {
    if (event == firmware_update_complete) {
    //run initializer function

void setup()
    // register the reset handler
    System.on(firmware_update, reset_handler);

@tuxie, you are missing the event parameter in your handler. The event is firmware_update and the parameter has a value representing one of 4 states.

@tuxie have you had any more luck getting this functionality to work?

Next on my todo list currently. I think I’d fix my code based on peekays comment and then do some kind of loop which would clear the whole backup ram block.