Memory Addresses

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

I'm trying to understand the memory address I see returned when I do something like &testVariable. In this case I'm using an ATSAMD21 with 256K flash and 32K SRAM. testVariable was defined as an integer, and it will use 4 bytes, since this is a SAMD cpu. I stored a 2 in testVariable. &testVariable returns 536871116. If I set up a pointer to return the contents of that address, I get 2 as expected. Addresses 536871117, 536871118, and 536871119 return 0 as expected.

 

The part I don't understand is the magnitude of those memory addresses, 536,871,116 thru 536,871,119. I was expecting flash to range from 0 to 262,144 bytes and SRAM to range from 262,145 to 294,913. In any case, not addresses in the range of hundreds of millions. Obviously, I'm not understanding something very basic about this. 

 

Last Edited: Fri. Feb 28, 2020 - 02:01 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


You posted in the wrong forum - this one is for AVR not ARM. While I don't know much about ARM I do know that  536871116 (rather meaningless decimal number) is 200000CC which seems to make a lot more sense. So I guess in the 4GB memory space of an ARM the RAM in SAMD21 starts at 0x20000000 and this particular variable is offset by 0x00CC from that base address (presumably there are other variables or "housekeeping" using the stuff between 20000000 and 200000CC ?

 

Anyway I'll move this thread to the ARM forums and I'm sure one of the ARM experts will add detail.

 

Moderator(AVR)



EDIT: I was interested so I downloaded a SAMD21 datasheet and this diagram:

 

 

and this table:

 

 

confirm my suspicions about SRAm starting at 0x20000000. The only "mystery" that remains had your example been the only variable in the entire program is why 0x200000CC and not simply 0x20000000 ?

 

(Oh and when printing &something I would recommend %08X in printf() to make more sense of what you are seeing!)

Last Edited: Fri. Feb 28, 2020 - 02:12 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

For more detail check the datasheet "10.2 Physical Memory Map".

Edit: wow I was really late pressing Post there.

/Lars

 

Last Edited: Fri. Feb 28, 2020 - 02:17 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks! Excellent job interpreting my poorly written question. Yes, there were some other variables involved. My question was more or less a generic one to understand actual memory address mapping, which those tables clarify for me. I still don't get why SRAM starts at 0x20000000, but now I understand that's just the way it is.