Storing variable in Flash memory

Discussions concerning TrueSTUDIO for STM32 9.0.0 and later versions.

Moderators: Markus Girdland, Mattias Norlander

mani
Posts: 1
Joined: Fri Feb 08, 2019 6:13 am

Storing variable in Flash memory

Postby mani » Fri Feb 08, 2019 6:57 am

I can store variables in flash memory location successfully but what is happening is updating that variable in main.c file not happening.I'm posted code what i have done below.
Linker script file :
MEMORY
{
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 320K
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 153

MY_VARS (xrw) : ORIGIN = 0x08005000, LENGTH = 1K // storing in flash memory
}


.my_vars :
{
*(.MY_VARS*);

} >MY_VARS

In main.c file :

__attribute__((section(".MY_VARS"),myvars)) uint32_t *value=8;


int main()
{
int a =sum(); //i have a sum function of two numbers and storing in variable 'a'
value =&a; // value should updated to sum but it is not updating

readaddress=(const volatile uint32_t *)0x08005000;// reading flash memory
printf("Read flash address %lu\n",*readaddress);// printing the data which is stored in value ,it is printing everytime 8 but it should print variable data which stored in 'a'.
}
int sum(int a)
{
int a=1, b= 34 ;
a=a+b;
return a;
}

Can anybody help me to figure this out,i hope u understood what im asking.

Thank you

frank_ee
Posts: 94
Joined: Wed Apr 05, 2017 5:08 pm
Location: USA

Re: Storing variable in Flash memory

Postby frank_ee » Sun Feb 10, 2019 8:10 pm

Hello,

The variable "value" cannot be loaded the address of "a" because "value" is constant. Data in flash has to be erased and reprogrammed which can be done using the HAL flash library. From the debugger, do you get the initial value of 8 for the "value"?

frank_ee
Posts: 94
Joined: Wed Apr 05, 2017 5:08 pm
Location: USA

Re: Storing variable in Flash memory

Postby frank_ee » Mon Feb 11, 2019 11:01 pm

Hello,

See my post about constant tables in flash.


Return to “TrueSTUDIO for STM32 discussions”

Who is online

Users browsing this forum: No registered users and 3 guests