The location of the variable at the specified address.

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

Hi all. I need to place the variables (structures) in the external memory.

How can I do that?

In the IAR compiler this is done using the @ operator.

How to implement it in GCC?

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

MYA333 wrote:
I need (sic?) to place the variables (structures) in the external memory

Why do you "need" to do that?

 

Assigning addresses is, properly, the Linker's job - so you should do it in the Linker script.

https://www.math.utah.edu/docs/i...

 

GCC has an attribute to put variable in a specific section; you then get the Linker to locate that section at the required address.

 

https://gcc.gnu.org/onlinedocs/gcc-3.2/gcc/Variable-Attributes.html

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

For some reason I can't figure out how to format code for this forum properly, seems like the "Add Code" button is broken but anyway you can do something like this:

#define  externalMemoryLocation 0x03000000 // whatever the address is for your external memory

typedef struct {

int variable1;

int variable2;

}myStruct;

 

void myFunction(void)

{

myStruct *StructPointer = (myStruct *)externalMemoryLocation ;

StructPointer->variable1 = 1;

StructPointer->variable2 = 2;

}

 

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

For some reason I can't figure out how to format code for this forum properly

Somewhere around the top of your browser there is an indicator that this website "tries to load scripts from an unauthenticated source" (or whatever your browser calls it).

To work around this: Click that "indicator" and select to "Load unsafe scripts" (or whatever your browser calls it).

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

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

In the standard flash file.ld, I added a section of sdram.

/* Memory Spaces Definitions */
MEMORY
{
  rom (rx)  : ORIGIN = 0x00400000, LENGTH = 0x00200000
  ram (rwx) : ORIGIN = 0x20400000, LENGTH = 0x00060000
  sdram (rwxa) : ORIGIN = 0x70000000, LENGTH = 0x00200000
}

//............

/* Section Definitions */
SECTIONS
{
//............
 .data_sdram ORIGIN(sdram) :
 {
  . = ALIGN(4);
  PROVIDE(_data_sdram = .);
  *(.data_sdram)
  . = ALIGN(8);
  PROVIDE(_edata_sdram = .);
 } >sdram
}

Wrote a test program:

#define array_size 32
__attribute__((__section__(".data_sdram"))) int16_t array[array_size];

//.............

int main(void)
{
 /* Initialize the system */
 sysclk_init();
 board_init();
 sleepmgr_init();

 /* Configure the console uart */
 configure_console();

 /* Enable SDRAMC peripheral clock */
 pmc_enable_periph_clk(ID_SDRAMC);

 /* Complete SDRAM configuration */
 sdramc_init((sdramc_memory_dev_t *)&SDRAM_ISSI_IS42S16100E,
   sysclk_get_cpu_hz());
 sdram_enable_unaligned_support();

 /* Test external SDRAM access */
 puts("Test external SDRAM access. \r");
 
 SCB_CleanInvalidateDCache();

 for(int16_t i=0;i<array_size;i++)
 {
  array[i]=i;
 }

 for(int16_t i=0;i<array_size;i++)
 {
  if(array[i]==i)
   {
    puts("SDRAM access is ok.\n\r");
   }
  else
   {
     puts("SDRAM access is failed.\r");
   }
 }
  

 for (;;) {
  sleepmgr_enter_sleep();
 }
}

As a result, all elements of the array were read as zero.

What did I do wrong?

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

Somewhere around the top of your browser there is an indicator that this website "tries to load scripts from an unauthenticated source" (or whatever your browser calls it).

To work around this: Click that "indicator" and select to "Load unsafe scripts" (or whatever your browser calls it).

 

Where???

 

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

westfw wrote:
Where???

I don't know that browser, but you do seem to have a little 'alert' symbol, and an 'i' (for 'info'?) at the start of the URL box:

 

#SAMCodeEditorBroken

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I use the browser microsoft internet exploer. Where it has the option "Load unsafe scripts" I do not know. Text in the PBCKCODE window is formatted. The text is displayed in green on the forum.

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

Let's return to the topic "The location of the variable at the specified address".

Without using the cache my example works. What do I need to do to use external memory when using the cache?

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

MYA333 wrote:
Let's return to the topic "The location of the variable at the specified address".

So how about an answer to the question in the very first reply?

the cache

What cache?

If we're onto specific details of particular chips, then you need to say what chip!

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Chip is ATSAME70Q21 (SAME70-XPLD). Enable ICache and DCache.

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

@MYA333 said:

Let's return to the topic "The location of the variable at the specified address".

 Isn't the "location" of a specified address the specified address?

Greg Muth

Portland, OR, US

Xplained/Pro/Mini Boards mostly

 

Make Xmega Great Again!