RAM SIZES

scargill
Posts: 70
Joined: Sun Nov 02, 2014 8:09 pm

RAM SIZES

Postby scargill » Tue Sep 15, 2015 5:59 pm

Question...

I think I now have it clear in my head (someone please confirm) which type of RAM is used for what!

Here's one of my compiles.

Sections:
Idx Name Size VMA LMA File off Algn
0 .data 00000894 3ffe8000 3ffe8000 000000e0 2**4
CONTENTS, ALLOC, LOAD, DATA
1 .rodata 0000275c 3ffe88a0 3ffe88a0 00000980 2**4
CONTENTS, ALLOC, LOAD, READONLY, DATA
3 .bss 00009a80 3ffeb008 3ffeb008 000030e8 2**4
ALLOC
4 .text 00007786 40100000 40100000 000030e8 2**2
CONTENTS, ALLOC, LOAD, READONLY, CODE
5 .irom0.text 0003ce04 40202010 40202010 0000a870 2**4
CONTENTS, ALLOC, LOAD, READONLY, CODE


So we have DATA which is used for initialised variables - I've used 0x894 - but what is the MAXIMUM?
We have RODATA which is used for read only data (don't understand why that's not in FLASH if it is read only) - I've used 0x275c - but what is the MAXIMUM?
bss for variables which are NOT initialised - I've used 0x9a80 - but what is the MAXIMUM?
text - use for code that is not in FLASH (I assume this should only be used for time-critical functions?) - I've used 0x7786 - I'm assuming the limit is0x8000 ???
irrom0_text - That's FLASH and we know that this would be 512k or more depending on the chip...

Can someone clarify the RAM questions above. Are these different types fixed in size (I'm always near the edge with TEXT)..

Pete.

dkinzer
Posts: 52
Joined: Fri Jul 31, 2015 7:37 am

Re: RAM SIZES

Postby dkinzer » Wed Sep 16, 2015 6:10 am

There are no individual limits for the sizes of .data, .rodata and .bss (but see caveat below). The ESP8266 has 80K of User Ram which is occupied by .data, .rodata, .bss, the stack and the heap. Basically, the space represented by (80K - sizeof(.data) - sizeof(.rodata) - sizeof(.bss)) is used by the heap growing from one end and the stack growing from the other end. If the heap and stack collide bad things will happen (probably an exception, eventually, and a reboot).

The caveat that I mentioned is that the .data and .rodata sections, along with the .text section (itself limited to 32K) must fit in the first 64K of Flash. The sizes of each of these sections is rounded up to an integral multiple of 4 bytes and an additional 8 bytes of overhead are added for each section plus an additional 8 bytes of overhead. Finally, space for the checksum is added (between 1 and 16 bytes) so that the overall size is an integral multiple of 16 bytes. The total of all that must be 64K or less. The image containing all of this data is often called app.v6.flash.bin but the name itself is not important.

As for the limit on the size of .irom0.text, that depends on 1) the size of your Flash chip (commonly 512K but can be 16MB or more), and 2) where you load it into Flash and 3) if you want OTA upgrade or not. For non-OTA upgrade, it is common to load the .irom0.text at 0x40000 but it can be loaded as low as 0x10000. Since the system parameter area exists at 16K from the end of the Flash chip, the size of .irom0.text is limited to sizeof(Flash) - 16K - loadAddress.

If you want to load the (non-OTA) .irom0.text at an address other than 0x40000 you'll need to modify the linker script accordingly.
Don Kinzer
Beaverton, OR, USA

Who is online

Users browsing this forum: Paka01Pr and 1 guest