Skip to main content
federico.massimi
Associate III
May 9, 2018
Question

Reserve Flash for user data

  • May 9, 2018
  • 2 replies
  • 1678 views
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.

    This topic has been closed for replies.

    2 replies

    Nesrine M_O
    Associate
    May 9, 2018
    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
    Senior III
    May 9, 2018
    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.

    federico.massimi
    Associate III
    May 9, 2018
    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?
    AvaTar
    Senior III
    May 9, 2018
    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.