Store data in Flash memory or External RAM memory- SAME54P20A

Go To Last Post
9 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello All, 

 

I want to store some data in the Flash of microcontroller ATSAME54P20A. 

 

Does the syntax as follows works:- 

 

static __attribute__ ((section (".flash"))) signed
    char ARRAY[ ] = "HELLO";

 

My question is does the above syntax to store some data in flash works ?? What will be the syntax for external RAM then ?? Please, help me with this questions.

 

Thanks in advance.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello, 

 

Does anyone have answers to above question then please respond.

 

Thanks.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Store what? Is it constant data or will your program need to update it?

/Lars

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

No, It is a constant data that we are storing in an array, to display any message on to LCD screen.

 

Does, the above syntax correct ??

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Just declare it const, it will end up in flash and only in flash, e.g.

const char ARRAY[] = "HELLO";

/Lars

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

OK, but can i write like this to store the data in flash :- 

 

static __attribute__ ((section (".flash"))) signed
    char ARRAY[ ] = "HELLO";

 

Does the above syntax not works as we intend it to be ??

 

How about storing to other memory say external RAM or static RAM, what is the syntax for that. 

 

The gcc compiler collection document available online uses attribute keyword to store some data into array.

 

I am curious to know , Can I use the above syntax to store it in any memory say flash, SRAM etc.Does the controller store it in the mentioned memory, if we specify the name inside section field. 

 

For what purpose generally we use above method, as I see in various header files using the attribute keyword for SAM microcontroller. 

 

Last Edited: Sat. Jun 29, 2019 - 11:38 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You probably get that in RAM also since it's not const. I don't get the point of specifying a section when there is no need. Non-const data is in RAM (initialized from flash if needed), const data in flash. This is with common default .ld scripts. If you need some special section handling then the first step is understanding the .ld script.

/Lars

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi @Lajon, 

 

I have asked you above question because in our company's product, they have used (__flash) identifier/keyword to store the data in flash. The controller though used in that case is ATMEGA2560. 

 

Now, while migrating to SAM microcontroller, I used to see in several header files which came along while installing the ATMEL STUDIO 7, that they  have used (__attribute__) at many places. 

 

So, I wondered, that to keep the uniformity with the standard  proposed  in SAM microcontroller. I will try to use this (__attribute__) keyword to store data in FLASH. 

 

You said when we use (__attribute__) with section feature,   it is stored in BOTH RAM AND FLASH and you are right also, as I personally checked the program and data memory size gets increased upon building the solution. 

 

One question still remains as what will be then replacement for (__flash) which is used in ATMEGA controllers to store data  in Flash

 

Is there any specific key word in SAM microcontroller to store data in flash  or I need to use the same approach that you have suggested in earlier comments to declare the array variable as constant???

 

Your suggestion in this case will be valuable. 

 

Thanks in advance.

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Some __attribute__ settings can be useful also for SAM, e.g., functions in ram and variables that are not cleared. As mentioned in post #7 __attribute__  is not needed for placing const data in flash.

AVR have a different architecture ( https://en.wikipedia.org/wiki/Harvard_architecture ), it's not surprising that the __flash keyword (or __attribute__) has to be used there.

/Lars