Tag Archives: ESP8266 Address Mapping

My thanks to Richard Burton for some updates. This entry which started out as guesswork (but with a practical aim) turns out to have been not that far off – I’ve amended the text and it’s now hopefully a decent guide to memory use in the ESP8266 etc… (bear in mind not ALL of these board have the same amount of FLASH – some of the ESP12s have way more than other boards (sadly, no more RAM but there you are).

As you’ll know from the previous blog I was having issues with the SDK which are now resolved thanks to some helpful types to whom I am eternally grateful. My code generally starts off using TuamPMs MQTT C code and expands on that (a lot), using MQTT as the base for communications. Well, as time goes on my code gets bigger and bigger – and I was starting to run out of both FLASH and RAM. The latter was easy to mitigate by using compiler directives to keep as much in Flash as possible – hence freeing up some RAM – but before long I was hitting limits. One kind chap made a mod to the MAKEFILE to move the FLASH around a bit but it’s only today that it has all really started to sink in – so here’s my attempt at explaining what I THINK is happening and how I THINK I’ve made a lot of improvement.

The ESP contains a 32 bit xtensa core processor which has a MASSIVE potential for address spaces. Hence, our programs which appear to start at 0x00000 i.e. 0, actually sit at 0x40200000. As you will know if you’ve been compiling code, you’ll see binary files at 0x00000 and 0x40000… and my code was heading up to the limit of 0x80000. Well, actually the limit is lower than that because it seems that Espressif have reserved some space up at 0x7c000 in our mapped area.

So the map on the LEFT shows how most programs seem to be laid out. In the case of TuanPMs code, some bits of the SDK, program data and any code not marked “icache_flash_attr” start at the bottom in the pink section – then there’s a big gap and TuanPM stores his non-vol variables at 3c000. He actually stores the lot in a struct and replicated it using 3 blocks – 3c000, 3d000 and 3e000. The first two are mirror images of each other and the third block has a byte that says which one was last updated. It’s a mechanism to ensure no loss of data if a block is being updated during a power failure… you just keep using the last one! And that’s fine but hey, I’m running out of room in the top half.

So I discovered by trial and error that you can’t use 7c000, well, you can but the program won’t work – so I moved his vars up to 78000. That left a honking great gap between the top of the SDK and the bottom of the area at 0x4000 which contains all the program material marked “icache_flash_attr AND the actual SDK (irom section) – as both your code and the SDK is in there – you want as much room for that block as poss. Well, it turns out that with 2 simple modifications, one to the Makefile and a corresponding change to the eagle.app.v6.ld file – you can move things about. That bit of dark blue at the top changes position depending on which chip you are using – but it is usually the top 4 sectors – so they are essentially verboten.

So now – see the second picture, my non-volatile info is up at the top, my program space is moved down – and there is a TON of FLASH space left to move into!

I may or may not have the description right – but I can tell you that it all works.I tried fitting the (red) non-vol storage just under 10000 and that survived power cycling but did not survive re-flashing the chip – where it is now DOES survive a re-flash.

And so there it is – I’m not confident enough to start telling people how to do this but I can say that (after backing EVERYTHING up) if you take a look at your makefile and find references to 0x40000 – and change to 0x10000 - and then look around line 8 in the eagle.app.v6.ld file and you’ll see there that you can change the base address and the length of the segment called irom0_0_seg.. if all of that is available in your installation – then you may just find you can move everything around.

Ok, those who know more than me – what did I get wrong? oh and I’m now running this no problem with version 1.11 of the SDK – AND am about to take out TuanPMs saving mechanism as they’ve built that into the SDK – no point in re-inventing the wheel.

Welcome to the Blog

Hi - I'm Pete and this is my technology blog. It is BIG. It is also the home of "ESP-GO". "The Script", Node-Red-Contrib-Bigtimer and many other useful toys. Use the search box below or check out the archives and other links below - be sure to SHARE what you like using the social media buttons and please subscribe to my YouTube channel http://www.youtube.com/PeterScargill

Please register or log in - the top menu changes a lot when you are part of the party... and once in, don't forget to tick the box so you will get email follow-ups to comments.

If you want to buy me a coffee or help fuel my gadget habit, use the Paypal donate link below.

Disclaimer: Because I have no idea of your level of technical skill or the requirements of your country laws in terms of electricity supply etc., I accept no responsibility for any damage caused through following advice in these pages. When dealing with mains voltages you should satisfy yourself that whatever you are doing is safe and if unsure, seek advice from someone who is sure.

Notice: I'm always happy to offer advice on stuff I've written - and indeed take advice. If I can help in any way just let me know but PLEASE don't ask me how to program in C/PASCAL/NODE/etc. There are many resources out there - if you want to program and can't - there's always Google.

Search for:

Email Newsletter

Enter a name and your real email address if you would like to receive occasional summary emails - sorry but invalid-looking or automated names and email addresses will be removed to help protect others.

Links

EE Times | Electronic Engineering TimesEE Times connects the global electronics community through news, analysis, education, and peer-to-peer discussion around technology, business, products and design