{"id":870,"date":"2019-05-06T15:54:35","date_gmt":"2019-05-06T22:54:35","guid":{"rendered":"http:\/\/localhost\/imagecraft\/blog\/?p=870"},"modified":"2019-05-06T15:54:35","modified_gmt":"2019-05-06T22:54:35","slug":"how-much-flash-and-sram-does-my-project-use","status":"publish","type":"post","link":"https:\/\/imagecraft.com\/?p=870","title":{"rendered":"How Much Flash and SRAM Does My Project Use?"},"content":{"rendered":"\n<p>When developing firmware for an embedded project, it is important to know how much flash and SRAM the program is using. This allows you to make the best decision on whether the chosen MCU has sufficient resources for your needs.<\/p>\n\n\n\n<p>By default, GCC does not give any information regarding program size. However, GCC does include a utility that can help, sensibly it is called &#8220;size.exe&#8221; (or &#8220;arm-none-eabi-size.exe&#8221; for the embedded GCC version). If you run the program as follows:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">c:\\iccv9cortex\\gnuarm\\bin\\arm-none-eabi-size -A -x bin\\Debug\\Test.elf<\/pre>\n\n\n\n<p>The \/path\/to\/ is as installed by ImageCraft&#8217;s <a href=\"http:\/\/imagecraft.com\/products\/jumpstart-c-tools-menu\/jumpstart-cpp\">JumpStart C++<\/a> program, but any embedded GCC installation will have this program. The last argument is the input file (in default ELF format). &#8220;-A&#8221; means to output in SysV format (Berkeley format is the other option), and &#8220;-x&#8221; is to use hexadecimal output. The above produces something as follows: <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">bin\\Debug\\TestDriver.elf  :<br> section                size         addr<br> .text                0x6720    0x8000000<br> .ARM.extab            0x258    0x8006720<br> .ARM.exidx            0x2f0    0x8006978<br> .ARM.attributes        0x2a    0x8006c68<br> .data                 0x804   0x20000000<br> .bss                  0x9c0   0x20000804<br> ._user_heap_stack    0x2804   0x200011c4<br> .debug_line          0x405a          0x0<br> .debug_info         0x24c75          0x0<br>...<br> .debug_ranges          0x60          0x0<br> .comment               0x75          0x0<br> .debug_frame         0x2dd4          0x0<br> .stab                  0x9c          0x0<br> .stabstr              0x14f          0x0<br> Total               0x3d8f3<\/pre>\n\n\n\n<p>Each line represents a &#8220;region&#8221; in the output file. If a region has an address of 0x0, it means that it is not using any space in the target MCU and most likely only contains debug information, and will be used for debugging only.  The regions&#8217; names and allocations are controlled by the linker script used so your output may look slightly different.<\/p>\n\n\n\n<p>The entries of interest are: <strong>.text<\/strong> this is the size of your program, i.e. flash usage.  In this example, 0x6720 or 26400 bytes of flash is used, plenty left over from the 512K STM32F411RE that I am using.  <\/p>\n\n\n\n<p><strong>.data<\/strong> and <strong>.bss<\/strong> are the static SRAM usage. .data has the global\/static variables that have initialization, and .bss has the global\/static variables that have no initialization (but are initialized to zero per C\/C++ definition). In this case, 4548 bytes are needed, also significantly less than the 128K bytes of SRAM available on the F411RE.<\/p>\n\n\n\n<p>Finally, <strong>._user_heap_stack<\/strong> is the area reserved for memory allocated at runtime, heap is for memory used by malloc\/free, and C++&#8217;s &#8220;new&#8221; etc., and stack is used for mainly for local variables and function context. As the runtime memory size changes as your program is run, this is only the minimum amount set in the linker script. Your program controls how much dynamic memory it uses. Stack usage depends on the call patterns in your program and how much stack space (e.g. local variables) a function uses. A future blog post will describe one way to determine stack usage of a program.<\/p>\n\n\n\n<p>You can write a simple utility program to process the &#8220;size&#8221; output to give a simple summary, which is what we have done with the <a href=\"http:\/\/imagecraft.com\/products\/jumpstart-c-tools-menu\/jumpstart-cpp\">JumpStart C++<\/a> tools. A typical post-build message looks like this:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ELF file output size<br> Code size:        26400 bytes starting at 0x08000000<br> SRAM data:         4548 bytes starting at 0x20000000<br> Heap and Stack:   10244 bytes heap starts 0x200011C4 stack starts 0x200039C8<\/pre>\n\n\n\n<p>With size.exe and some processing, it is simple to see your program&#8217;s flash and SRAM requirements.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When developing firmware for an embedded project, it is important to know how much flash and SRAM the program is using. This allows you to make the best decision on whether the chosen MCU has sufficient resources for your needs. By default, GCC does not give any information regarding program size. However, GCC does include a utility that can help, sensibly it is called &#8220;size.exe&#8221; (or &#8220;arm-none-eabi-size.exe&#8221; for the embedded GCC version). If you run the program as follows: c:\\iccv9cortex\\gnuarm\\bin\\arm-none-eabi-size -A -x bin\\Debug\\Test.elf The \/path\/to\/ is as installed by ImageCraft&#8217;s JumpStart C++ program, but any embedded GCC installation will have [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""}},"footnotes":""},"categories":[1],"tags":[],"class_list":["post-870","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/imagecraft.com\/index.php?rest_route=\/wp\/v2\/posts\/870","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/imagecraft.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/imagecraft.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/imagecraft.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/imagecraft.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=870"}],"version-history":[{"count":0,"href":"https:\/\/imagecraft.com\/index.php?rest_route=\/wp\/v2\/posts\/870\/revisions"}],"wp:attachment":[{"href":"https:\/\/imagecraft.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=870"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/imagecraft.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=870"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/imagecraft.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=870"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}