Defining and working with external memory

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

I'm considering moving an 8051 based project to a new design with a Mega1281 and AVR Studio 6.2.  Up till now my "C" exposure has been simple projects, but now I have a design with external RAM and a lot of mapped I/O hardware.

Using a Keil compiler with an 8051 target, I would declare variables into different memory areas using BIT, DATA, or XDATA as part of the variables declaration.  As part of the project setup, you told it how much (if any) external RAM you have, and what the address range is.

 

I don't see anything like this in AS 6.2, am I just missing something obvious?

 

How do I tell the compiler/linker I have external RAM and what variables to put there?

For the external hardware mapping, I assume I can just use pointers to access those specific areas of memory.

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

__attribute__((section(".sectname"))) in the code

 

Later -Wl,-section-start=.sectname=0xnnnn given to the linker to set the base address. 

 

You can assign a number of objects to any section. To save typing that tortuous attribute for each object, #define it with some easily typed name such as EEMEM, PROGMEM, DATAMEM, EXTMEM or whatever you want to call it. 

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

I saw similar responses in older threads as well.  Where do you add the -WI linker command?  Is that in the project properties on the build events tab?

 

 

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

That is -Wl. The second character there is a lower case lima not India.

 

You have to options for placing this if you use Studio:

 

1) in the project options under GNU/Linker there is a "miscellaneous" and that has a free entry text box. You can just put it there. If you do I think you don't need the leading "-Wl," as I think Studio will add that prefix anyway as it means "this is a linker option"

 

2) Also under GNU/Linker there is a "Memories" section. You can just put something like ".sectname=0x1234" there and Studio will convert that to a -section-start for you.

 

Note two further things if you put the section under "flash" then Studio doubles the 0x1234 to be 0x2468 because it converts the given address from WORDS to BYTES. Also note that for a RAM section you must add 0x800000 to the address you want to use. So for 0x1234 in RAM use 0x801234 but if you use option (2) then ignore this as Studio adds the 0x800000 for you.