You have a choice depending on your compiler:
- You can declare a pointer to a structure and initialize a pointer to a region.
- Tell the compiler where the variable should be
Flash Pointer
Declare a structure pointer.
Assign a pointer to the correct address in Flash.
Access to variables by dereferencing a pointer.
A pointer must be declared and assigned as a constant pointer to persistent data.
Specifies the address of the variable compiler.
Some compilers allow you to put a variable in a specific area of memory. The first step is to create a region in the linker command file. The next step is to tell the compiler that the variable is in this region.
Again, the variable should be declared as a "static constant". "Static" because there is only one instance. "Const" because flash memory is read-only for most of the time.
Flash Memory: Volatile or Const
In most cases, flash memory, however, is programmed, read-only. In fact, the only way to read data in Flash is to block it, aka make it read-only. In general, it will not be changed without consensus of the program.
Most flash memories are programmed by software. This is usually your program. If your program is about to reprogram Flash, it knows that the values have been changed. This is similar to writing to RAM. The program changed the value, not the hardware. Therefore, Flash is not volatile.
My experience is that Flash can be programmed in a different way, usually when your program is not running. In this case, it is still unstable because your program does not work. The flash is still read-only.
A flash will be volatile if and only if another task or thread of executable programs starts while your thread is executing. I still do not consider this case unstable. This will be a case of synchronization - if the flash is changed, then some listeners should be notified.
Summary
Flash memory is best viewed as read-only memory. Variables in Flash are accessible via a pointer for better portability, although some compilers and linkers allow you to declare variables at certain hard-coded addresses. Variables must be declared as const static so that the compiler can emit code for direct access to the variables, as well as for copying onto the stack. If Flash is programmed by another task or thread of execution, this is a synchronization problem, not a mutable one. In rare cases, Flash is programmed by an external source during the execution of your program.
Your program should provide checksums or other methods to determine if the content has changed since the last time it was checked.
DO NOT USE THE INITIALIZING CONNECTION OF VARIABLES FROM FLASH.
It is not very portable. It is best for your initialization code to load a variable from a flash drive. Creating a compiler to load a variable from another segment requires a lot of work with the internal components of the compiler and linker; much more than initializing a pointer to an address in Flash.