Black Lives Matter - Action and Equality. ... Adafruit is open and shipping.
0

arduino data memory requirements
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

arduino data memory requirements

by mtbf0 on Sun Jun 15, 2008 7:07 pm

recently, i was being lazy and leaving large arrays of constant data in sram and found myself bit on the butt by apparently random alterations to my data. of course my data were randomly altered in identical fashion every time i ran my sketch. it took me a ridiculously long time to suss the root of my problems.

so i was wondering if there was a way to extract information about ram usage from the arduino environment. also, conincidentally, was wondering about the stack location. my stack use shouldn't be too great. just the main(), loop(), one subroutine, and an isr max, so it might be fun to do something scary like play with the sp initialization.
User avatar
mtbf0
 
Posts: 1645
Joined: Sat Nov 10, 2007 12:59 am
Location: oakland ca

by mtbf0 on Mon Jun 16, 2008 8:03 am

ok, via avrfreaks i learned that there are a couple of symbols defined by the linker.

_end is the last location allocated for your program's data. use the declaration
Code: Select all | TOGGLE FULL SIZE
extern uint8_t _end;


i dumped it to the serial console using...
Code: Select all | TOGGLE FULL SIZE
  USARTHex ((uint8_t)((uint16_t)&_end >> 8));
  USARTHex ((uint8_t)((uint16_t)&_end & 0xff));
you'll just have to trust me that USARTHex spits a byte formatted as two hex digits out the USART.

__stack is the beginning value of the stack pointer, but it's always going to be 0x04ff, the highest address in sram.
User avatar
mtbf0
 
Posts: 1645
Joined: Sat Nov 10, 2007 12:59 am
Location: oakland ca

Please be positive and constructive with your questions and comments.