title: How to use external memory on a microcontroller
body: <p>In the past, I've worked a lot with 8 bit AVR's and MSP430's where both the RAM and flash were stored on the chip directly.  When you compile and download your program, it sort of "just works" and you don't need to worry about where and how variables are actually stored.</p>
  
  <p>Now I'm starting a project where I'd like to be able to add some external memory to a microcontroller (a TI Stellaris LM3S9D92 if that matters) but I'm not entirely sure how you get your code to use the external RAM.  I can see how you configure the external bus pretty much like any other peripheral but what confuses me is how the processor keeps track of when to talk to the external memory and when to talk to the internal one.</p>
  
  <p>From what I can tell, the external RAM is mapped to the same address space as the internal SRAM (internal starts at 0x20000000 and external starts at 0x60000000).  Does that mean if I wrote something like this:</p>
  
  <pre><code>int* x= 0x20000000;
  int* y= 0x60000000;
  </code></pre>
  
  <p>Would x and y would point to the first 4 bytes (assuming 32 bit ints) of internal and external RAM respectively?  If so, what if I did something like this:</p>
  
  <pre><code>int x[999999999999]; //some super big array that uses all the internal ram
  int y[999999999999]; //this would have to be in external ram or it wouldn't fit
  </code></pre>
  
  <p>I imagine that I'd need to tell <em>something</em> about the boundaries of where each type of memory is or do I have it all wrong and the hardware figures it out on its own?  Do linker scripts deal with this?  I know they have something to do with memory mapping but I don't know what exactly.  After reading about how to set up an ARM cross compiler I get the feeling that something like winavr (avr-gcc) was doing a lot of stuff like this for me behind the scenes so I wouldn't have to deal with it.</p>
  
  <p>Sorry for rambling a bit but I'd really appreciate it if someone could tell me if I'm on the right track with this stuff.</p>
  
  <p><strong>Update</strong></p>
  
  <p>For any future readers I found this after another few hours of googling <a href="http://www.bravegnu.org/gnu-eprog/index.html" rel="noreferrer">http://www.bravegnu.org/gnu-eprog/index.html</a>.  Combined with answers here it helped me a lot.</p>