cancel
Showing results for 
Search instead for 
Did you mean: 

Reserve Flash for user data

federico.massimi
Associate III
Posted on May 09, 2018 at 12:28

Hello,

    I would like to save some data in the internal flash memory of an STM32L476. I found examples and guides and I was able to write and read data from flash. But I have a question: is the internal flash memory the same used to store the program? if yes, how can I be sure that my data will not overwrite the program? Are there any flash locations reserved for user data? Is there a way to compiler (Use Atolic Truestudio) without put the program in some areas of the flash?

Thanks in advance.

5 REPLIES 5
Nesrine M_O
Lead II
Posted on May 09, 2018 at 12:35

Hi

Massimi.Federico

,

you can protect your memory area using Proprietary Code Read-Out Protection (PCROP): protection against read and write operations on Flash and SRAM memories.

For more details about PCROB, I rocommend you to have a look to

http://www.st.com/content/ccc/resource/technical/document/application_note/group0/1f/99/ef/d6/24/8d/44/08/DM00226247/files/DM00226pdf/jcr:content/translations/en.DM00226pdf

Application note.

-Nesrine-

AvaTar
Lead
Posted on May 09, 2018 at 13:00

is the internal flash memory the same used to store the program?

Yes.

if yes, how can I be sure that my data will not overwrite the program?

Totally up to you.

Are there any flash locations reserved for user data?

Check the memory map and the Datasheet/Reference Manual. I don't know your MCU variant, but I guess not.

Such 'user data locations' use to be implemented with byte erase/program capabilities, and named 'EEPROM'.

Is there a way to compiler (Use Atolic Truestudio) without put the program in some areas of the flash?

Yes.

Create a separate linker section with your desired size, while you 'carve' it out of the code section (Flash).

You might want to consult the Atollic manuals/help for details about it, I don't work with this toolchain.

Be aware that 'normal' code Flash is not designed for frequent erase/programm, and will wear out quicky (e.g. weeks or month). Consider an external NV memory option.

Posted on May 09, 2018 at 13:29

I dont have to do frequent write/read cycles, I just have to be able to load parameters at startup.

so what I should do is choose a flash page to use (maybe the last one) and set the compiler to not use that page.

Do you know how I can do it with Atolic Truestudio?
Posted on May 09, 2018 at 14:32

Do you know how I can do it with Atolic Truestudio?

Not really, sorry. Just tried Atollic a bit a few month ago.

You would have modify the linker script for your project.

As said, reduce the size of the code segment, and declare the carved-out segment as a new section.

The Atollic IDE help should cover this, else try a search here or elsewhere - this method is specific for Atollic, but not STM32.

I dont have to do frequent write/read cycles, I just have to be able to load parameters at startup.

That would be ok.

I have witnessed over-zealous project managers forcing periodic write functionality into code Flash, to reduce BOM costs.

This cost reduction was more then compensated by broken field returns.

Posted on May 10, 2018 at 00:41

in my project i've found this file: STM32L476RG_FLASH.ld

where i can read this lines:

MEMORY

{

RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 96K

RAM2 (xrw) : ORIGIN = 0x10000000, LENGTH = 32K

FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 1024K

}

from the reference manual i know that every memory page have a size of 2k,so i can simply modify the flash memory lenght from 1024K to 1022K in this file to avoid that compiler/linker use the last page of the flash? It's that simple?