How to construct any variable retention like PLC systems?

When the power supply shutting down, value of some variables  is important and need to retention. How to construct it?

I used static ,extern, to define this variable, but fail.

Chip board:STM32F0Discovery

More questions in this forum