{"id":1053,"date":"2015-10-21T13:41:04","date_gmt":"2015-10-21T20:41:04","guid":{"rendered":"http:\/\/internetofhomethings.com\/homethings\/?p=1053"},"modified":"2015-10-21T16:47:33","modified_gmt":"2015-10-21T23:47:33","slug":"esp8266-free-space-assessment","status":"publish","type":"post","link":"https:\/\/internetofhomethings.com\/homethings\/?p=1053","title":{"rendered":"ESP8266 Free Space Assessment"},"content":{"rendered":"<p><a href=\"http:\/\/internetofhomethings.com\/homethings\/wp-content\/uploads\/2015\/10\/percentage.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1058\" src=\"http:\/\/internetofhomethings.com\/homethings\/wp-content\/uploads\/2015\/10\/percentage.png\" alt=\"percentage\" width=\"400\" height=\"300\" srcset=\"https:\/\/internetofhomethings.com\/homethings\/wp-content\/uploads\/2015\/10\/percentage.png 400w, https:\/\/internetofhomethings.com\/homethings\/wp-content\/uploads\/2015\/10\/percentage-300x225.png 300w\" sizes=\"auto, (max-width: 400px) 100vw, 400px\" \/><\/a><\/p>\n<p>Have you ever used the EspressIf SDK to compile code and wondered how much free space you have? How much more code you can add before running out of memory?<\/p>\n<p>That\u00a0information is very useful when developing code, and is readily available when using the Arduino IDE. So why is it missing from the SDK console output when you execute a build?<\/p>\n<p>That used to bug me, until I figured out how to include it. Read on if you want a better view of the free space available\u00a0after building your ESP8266 code.<\/p>\n<p>Here is how I did it&#8230;<\/p>\n<h4 style=\"text-align: center;\"><strong>Evaluating Solution Options<\/strong><\/h4>\n<p>First thing I did was review the Makefile that was provided with the SDK examples. I thought it might be a simple matter of adding a few lines to output the desired information. After all, the current Makefile outputs the number of byte used. And we know how much memory is available. A simple calculation and boom, you got the answer.<\/p>\n<p>Wrong!<\/p>\n<p>What I found was that the current memory statistics are generated by the\u00a0utility &#8220;MemAnalyzer.exe&#8221; . This tool is included with the EspressIf SDK. So I figured all that it would take was a few changes to this utility to format the memory statistics in the format I wanted. Problem is, the source code for this utility is nowhere to be found. At least I had no luck finding it.<\/p>\n<p>So what I decided to do was create another utility. One that would format the information provided by MemAnalyzer.exe and include it in the build Console output.<\/p>\n<h4 style=\"text-align: center;\"><strong>The\u00a0Solution<\/strong><\/h4>\n<p>Obviously, this requires some changes to the project&#8217;s &#8220;Make&#8221; file. The current information, while I find it inadequate, is produced by the following Makefile file line:<\/p>\n<pre class=\"easycode; title:;lang:;\"> \u00a0$(Q)\u00a0$(SDK_TOOLS)\/memanalyzer.exe\u00a0$(OBJDUMP).exe\u00a0$@<\/pre>\n<p>And the output from the memanalyzer\u00a0tool is displayed\u00a0like this example:<\/p>\n<pre class=\"easycode; title:;lang:;\"> \u00a0\u00a0\u00a0Section|\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Description|\u00a0Start\u00a0(hex)|\u00a0End\u00a0(hex)|Used\u00a0space\r\n------------------------------------------------------------------------------\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0data|\u00a0\u00a0\u00a0Initialized\u00a0Data\u00a0(RAM)|\u00a0\u00a0\u00a0\u00a03FFE8000|\u00a0\u00a03FFE8D8C|\u00a0\u00a0\u00a0\u00a03468\r\n\u00a0\u00a0\u00a0\u00a0rodata|\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0ReadOnly\u00a0Data\u00a0(RAM)|\u00a0\u00a0\u00a0\u00a03FFE8D90|\u00a0\u00a03FFEA3F4|\u00a0\u00a0\u00a0\u00a05732\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0bss|\u00a0Uninitialized\u00a0Data\u00a0(RAM)|\u00a0\u00a0\u00a0\u00a03FFEA3F8|\u00a0\u00a03FFF4C08|\u00a0\u00a0\u00a043024\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0text|\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Cached\u00a0Code\u00a0(IRAM)|\u00a0\u00a0\u00a0\u00a040100000|\u00a0\u00a04010782C|\u00a0\u00a0\u00a030764\r\nirom0_text|\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Uncached\u00a0Code\u00a0(SPI)|\u00a0\u00a0\u00a0\u00a040240000|\u00a0\u00a04026F574|\u00a0\u00a0193908\r\nTotal\u00a0Used\u00a0RAM\u00a0:\u00a052224\r\nFree\u00a0RAM\u00a0:\u00a029696\r\nFree\u00a0IRam\u00a0:\u00a02022<\/pre>\n<p>In order to access this information, it was redirected to a text file (mem.txt) by adding a new line to the MakeFile:<\/p>\n<pre class=\"easycode; title:;lang:;\">$(Q)\u00a0$(SDK_TOOLS)\/memanalyzer.exe\u00a0$(OBJDUMP).exe\u00a0$@\r\n<strong><span style=\"color: red;\">$(Q)\u00a0$(SDK_TOOLS)\/memanalyzer.exe\u00a0$(OBJDUMP).exe\u00a0$@\u00a0&gt;mem.txt<\/span><\/strong><\/pre>\n<p>My new utility reads the mem.txt file and outputs the re-formatted memory statistics to the build Console. The utility is named &#8220;EspMemUsage.exe&#8221; and is called in the Makefile with the addition of a second line:<\/p>\n<pre class=\"easycode; title:;lang:;\">$(Q)\u00a0$(SDK_TOOLS)\/memanalyzer.exe\u00a0$(OBJDUMP).exe\u00a0$@\r\n$(Q)\u00a0$(SDK_TOOLS)\/memanalyzer.exe\u00a0$(OBJDUMP).exe\u00a0$@\u00a0&gt;mem.txt\r\n<strong><font style=\"color: red;\">$(Q)\u00a0$(SDK_TOOLS)\/EspMemUsage.exe\u00a0$(OBJDUMP).exe\u00a0$@<\/font><\/strong><\/pre>\n<p>And here is what the added Console output information looks like:<\/p>\n<pre class=\"easycode; title:;lang:;\"> ------------------------------------------------------------------------------\r\nResource\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0|Size(bytes)|\u00a0\u00a0\u00a0\u00a0Used|\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0%Used|\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Free|\u00a0\u00a0\u00a0%Free\r\n--------------------|-----------|--------|------------|------------|----------\r\nIRAM\u00a0-\u00a0Cached\u00a0Code\u00a0\u00a0|\u00a0\u00a0\u00a0\u00a0\u00a0\u00a032768|\u00a0\u00a0\u00a030746|\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a094|\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a02022|\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a06\r\nSPI\u00a0-\u00a0Uncached\u00a0Code\u00a0|\u00a0\u00a0\u00a0\u00a0\u00a0253952|\u00a0\u00a0193908|\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a076|\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a060044|\u00a0\u00a0\u00a0\u00a0\u00a0\u00a024\r\nRAM\u00a0-\u00a0Data\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0|\u00a0\u00a0\u00a0\u00a0\u00a0\u00a081920|\u00a0\u00a0\u00a052224|\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a063|\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a029696|\u00a0\u00a0\u00a0\u00a0\u00a0\u00a037\r\n------------------------------------------------------------------------------<\/pre>\n<p>It help me a lot to see the memory usage in this format. I hope you find it useful too.<\/p>\n<p>The utility, makefile, and source code are available on <a href=\"https:\/\/github.com\/internetofhomethings\/Esp8266-SDK-Code-Memory-Statistics\" target=\"_blank\">Github here<\/a>. Installation instructions are provided in the readme file. It was developed using the free Microsoft code development \u00a0tool <a href=\"https:\/\/www.visualstudio.com\/en-us\/downloads\/download-visual-studio-vs.aspx\" target=\"_blank\">Visual Studio 2015 Community<\/a>. Customize as you see fit to meet your specific needs and wants.<\/p>\n<h4 style=\"text-align: center;\"><strong>What It Does<\/strong><\/h4>\n<p>The utility code is written using the c# programming language. The Program class is structured into\u00a03 static functions.<\/p>\n<ol>\n<li>Main &#8211; This console application executes Main upon entry.\u00a0\u00a0Main opens the file &#8220;mem.txt&#8221; and reads each line separately. If the line contains a memory value of interest, the information is extracted and formatted for output by calling the function &#8220;MemStat&#8221;. After completing the evaluation of the file &#8220;mem.txt&#8221;, the formatted results are output to the console.<\/li>\n<li>MemStat &#8211; This function extracts the value from the line read. Any spaces in the extracted value are removed by calling the 3rd and final function, &#8220;RemoveSpaces&#8221;. The memory used and free statistics are then calculated and formatted. The formatted string is returned to the function caller.<\/li>\n<li>RemoveSpaces &#8211; Removes spaces from a string.<\/li>\n<\/ol>\n<h4 style=\"text-align: center;\"><strong>In Closing<\/strong><\/h4>\n<p>The utility presented here provides clarity to the ESP8266 code developer using the EspressIf SDK. So you know exactly how much memory is available for expansion, delineated by memory resource. Once installed, all you need to do is use the modified Makefile in your new projects to\u00a0get the information displayed in the console output.<\/p>\n<p>I hope you find this information useful.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Have you ever used the EspressIf SDK to compile code and wondered how much free space you have? How much more code you can add before running out of memory? &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,10,19,3],"tags":[80,81,82],"class_list":["post-1053","post","type-post","status-publish","format-standard","hentry","category-alltheposts","category-esp8266","category-internet-of-things","category-web-coding-tips","tag-esp8266-memory-usage","tag-espressif-sdk-tools","tag-espressif-sdk-utility"],"_links":{"self":[{"href":"https:\/\/internetofhomethings.com\/homethings\/index.php?rest_route=\/wp\/v2\/posts\/1053","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/internetofhomethings.com\/homethings\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/internetofhomethings.com\/homethings\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/internetofhomethings.com\/homethings\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/internetofhomethings.com\/homethings\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1053"}],"version-history":[{"count":14,"href":"https:\/\/internetofhomethings.com\/homethings\/index.php?rest_route=\/wp\/v2\/posts\/1053\/revisions"}],"predecessor-version":[{"id":1068,"href":"https:\/\/internetofhomethings.com\/homethings\/index.php?rest_route=\/wp\/v2\/posts\/1053\/revisions\/1068"}],"wp:attachment":[{"href":"https:\/\/internetofhomethings.com\/homethings\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1053"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/internetofhomethings.com\/homethings\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1053"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/internetofhomethings.com\/homethings\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1053"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}