2018-05-09 03:28 AM
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.
2018-05-09 03:35 AM
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
Application note.-Nesrine-
2018-05-09 04:00 AM
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.
2018-05-09 06:29 AM
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?2018-05-09 07:32 AM
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.
2018-05-09 05:41 PM
in my project i've found this file: STM32L476RG_FLASH.ld
where i can read this lines:MEMORY
{RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 96KRAM2 (xrw) : ORIGIN = 0x10000000, LENGTH = 32KFLASH (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?