cancel
Showing results for 
Search instead for 
Did you mean: 

Memory questions

hervett
Associate II
Posted on May 29, 2009 at 19:43

Memory questions

16 REPLIES 16
hervett
Associate II
Posted on May 17, 2011 at 12:54

Hello,

I'm using STM32 and I have questions about memories. I have keyboard and a LCD on my STM32 and so, an user interface. I would like save on the STM32, informations entered by me by the keyboard. Example : I push a button so I put in an integer 45, so after the push I=45. I would like to keep I=45 after the power down of the STM32. I know that I can use the Register but I have a lot of Value to save.

So I would like to know if I can do that with STM32 without externel memory, and How much byte I have in internal memories...or if I have to use exernal memory.

Thanks a lot...

And a little question. My code is in the Flash and I thought that the flash will be erase if there was no power...!!??!! but I have still my program after my power down ...why ? :o :o :o .

Thanks thanks a lot.

hervett
Associate II
Posted on May 17, 2011 at 12:54

And Do you think it will be OK if I create a variable in the SRAM and read the value, modify the value and write it in the SRAM, like the example 1 of the Cortex M3 library, the read-modify-write value ....

giles
Associate II
Posted on May 17, 2011 at 12:54

You just want to save data?

Ok firstly flash is non-volatile it doesn't lose what it's got stored when its turned off, ram and sram does.

IIRC the flash can only be written to approximately 10000 times (please correct me if i'm wrong someone)

flash is divided into banks of 1K (2k banks in the >128K devices iirc) when you write to flash you can only write 1 bits to 0 bits, to Reset the flash back to all 1's you need to erase the bank. banks can be erased individually but bytes and words can't you need to do the whole bank at once.

How much flash depends on which stm32 you're using.

st3
Associate II
Posted on May 17, 2011 at 12:54

Quote:

I thought that the flash will be erase if there was no power

No - it is quite the opposite!

Flash is non-volatile - that means that it does retain data when the power is removed;

SRAM is volatile - that means that it does not retain data when the power is removed.

hervett
Associate II
Posted on May 17, 2011 at 12:54

Ok, so If I put my code in the flash, it will be always in the flash after my switch off but if the program is in the SRAM, it will be lose.

So for the moment it's ok because my program is in Flash. But when during my program run, I change a value by pressing a key on the keyboard and TestValue=69, after the switch off, my value is egal to 0 and I want that the value stay at 69. How can I do that ..? I've declared int TestValue; in my main.c. Maybe I have to declar with somethingelse..?

giles
Associate II
Posted on May 17, 2011 at 12:54

Thats because your variables go in to ram (volatile memory) which is lost whenever you power off or reset.

If you want to keep the values you need to save them to flash check the flash programming manual:

http://www.st.com/stonline/products/literature/pm/13259.pdf

and also check out the st examples there is an example on writing flash, erasing and reading it.

giles
Associate II
Posted on May 17, 2011 at 12:54

Just remember not to erase and write to the same banks that your codes in 😉

hervett
Associate II
Posted on May 17, 2011 at 12:54

Ok, thanks gilles, i will read that. It's strange that my variable go in RAM because I've never tell in my code thatthey have to go there. In my NVIC configuration I just specify Flash, but I will try that and if you tell me that a variable can be saved after a power off, so I will try ..

Thanks and I keep you informed.

st3
Associate II
Posted on May 17, 2011 at 12:54

Quote:

It's strange that my variable go in RAM because I've never tell in my code thatthey have to go there.

No, it's not strange at all - it is perfectly normal and to be expected!

Flash is not only non-volatile, it is also essentially read-only;

To be precise, you cannot directly write to it - you have to go through a procedure of erasing it, and them programming it.

Variables, by definition, require read+write access - so they will naturally be placed in RAM!

Your issues here are not specifically to do with the STM32, but with embedded programming in general - so it will probably pay you to study some books on embedded programming before proceeding with this...

Keil have a book list here:

http://www.keil.com/books/

ST also have at ''MCU Learning Corner'' -

http://www.st.com/mcu/inchtml-pages-mcu_train.html

[ This message was edited by: st7 on 01-12-2008 14:07 ]

[ This message was edited by: st7 on 01-12-2008 14:08 ]