I have a well running application and now I am planning to enhance the code by saving user settings in the MCU's internal flash, using the flash utility provided via Atmel Start (hal_flash.c).
I have a couple of questions where I'd appreciate some help from the community here:
- My linker script samv71q21b_flash.ld says the following about the memory:
rom (rx) : ORIGIN = 0x00400000, LENGTH = 0x00200000 /* rom, 2097152K */
ram (rwx) : ORIGIN = 0x20400000, LENGTH = 0x00060000 /* ram, 393216K */
When I build my project, I get the following information about my memory footprint:
Program Memory Usage : 391388 bytes 18.7 % Full
Data Memory Usage : 153052 bytes 38.9 % Full
My intent is to use the upper half of my flash for storing the configuration. However, when I change LENGTH of the ROM to 0x00100000, the footprint doesn't seem to change and after recompiling it still says that the Program Memory Usage is 18.7%. Is this to be expected? What may I be doing wrong here?
- I want to store my configuration data starting with address 0x00410000 by using code something like this:
#define FLASH_MEMORY 0x00410000UL
#define example_A (*(volatile int16_t*) (FLASH_MEMORY + 0UL))
#define example_B (*(volatile int16_t*) (FLASH_MEMORY + 2UL))
Somewhere else in my code I can then conveniently access the contents of the variables by something like
int16_t = example_A * example_B;
However, it is not clear to me how to initialize my variable during the build. In other words, when I flash my MCU, these addresses are initialized with an arbitrary value but I need these addresses initialized with specific values during flashing my firmware. How is this properly done? In more general terms, I need to have a default configuration available in flash upon the first start of the application after the MCU was flashed and I am not sure how to do this best.
I am using Atmel Studio 7 (version 7.0.2389) on a Windows 10 computer.