<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How much free RAM do I have? in Kinetis Microcontrollers</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-much-free-RAM-do-I-have/m-p/714483#M43866</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="padding: 0px;"&gt;Hi Mark,&lt;/P&gt;&lt;P style="padding: 0px;"&gt;&lt;/P&gt;&lt;P style="padding: 0px;"&gt;I also attached is the uhk-left.map file above.&lt;/P&gt;&lt;P style="padding: 0px;"&gt;&lt;/P&gt;&lt;P style="padding: 0px;"&gt;It seems to me that I'm using heap and it occupies 0x204 bytes. Is this correct? When should I use heap?&lt;/P&gt;&lt;P style="padding: 0px;"&gt;&lt;/P&gt;&lt;P style="padding: 0px;"&gt;0x20000600 seems to be the highest address. Is this correct? Where does this leave us regarding RAM consumption?&lt;/P&gt;&lt;P style="padding: 0px;"&gt;&lt;/P&gt;&lt;P style="padding: 0px;"&gt;Thanks so much!&lt;/P&gt;&lt;P style="padding: 0px;"&gt;- Laci&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 27 Sep 2017 22:24:23 GMT</pubDate>
    <dc:creator>laszlomonda</dc:creator>
    <dc:date>2017-09-27T22:24:23Z</dc:date>
    <item>
      <title>How much free RAM do I have?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-much-free-RAM-do-I-have/m-p/714481#M43864</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi All,&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I attached uhk-left.elf generated by the "left" project of&amp;nbsp;our open source Ultimate Hacking Keyboard &lt;A _jive_internal="true" href="https://community.nxp.com/external-link.jspa?url=https%3A%2F%2Fgithub.com%2FUltimateHackingKeyboard%2Ffirmware" rel="nofollow" target="_blank"&gt;firmare repo&lt;/A&gt;.&amp;nbsp;I'd like to see how much free RAM do I have, and the results of the arm-none-eabi-size and nm utilities seem to contradict each other.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;$ arm-none-eabi-size --format=berkeley "uhk-left.elf"&lt;/P&gt;&lt;P&gt;text data bss dec hex filename&lt;BR /&gt; 3104 416 1184 4704 1260 uhk-left.elf&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;According to my understanding and based on the above, data (416) + bss (1184) = 1600 bytes are being used out of the 2K RAM of the KL03.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now let's compare this with the output of the nm utility:&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;$ nm --print-size --size-sort uhk-left.elf&lt;BR /&gt;200000b6 00000001 b byteIn.4509&lt;BR /&gt;200001d8 00000001 b prevEvent.4488&lt;BR /&gt;200001cc 00000001 b rxMessagePos.4489&lt;BR /&gt;000006e5 00000002 W __aeabi_idiv0&lt;BR /&gt;000006e5 00000002 W __aeabi_ldiv0&lt;BR /&gt;200001e0 00000002 b crc16data.4497&lt;BR /&gt;00000f0d 00000002 T _exit&lt;BR /&gt;00000541 00000004 W ADC0_IRQHandler&lt;BR /&gt;00000541 00000004 W CMP0_IRQHandler&lt;BR /&gt;00000541 00000004 W DefaultISR&lt;BR /&gt;00000541 00000004 W FTFA_IRQHandler&lt;BR /&gt;00000f1c 00000004 T _global_impure_ptr&lt;BR /&gt;00000549 00000004 W HardFault_Handler&lt;BR /&gt;00000559 00000004 W I2C0_IRQHandler&lt;BR /&gt;200001d0 00000004 b I2C_Watchdog.4507&lt;BR /&gt;200001c8 00000004 b I2C_WatchdogInnerCounter.4487&lt;BR /&gt;200001d4 00000004 b I2C_WatchdogOuterCounter.4506&lt;BR /&gt;00000541 00000004 W LLWU_IRQHandler&lt;BR /&gt;00000541 00000004 W LPUART0_DriverIRQHandler&lt;BR /&gt;00000561 00000004 W LPUART0_IRQHandler&lt;BR /&gt;00000545 00000004 W NMI_Handler&lt;BR /&gt;00000551 00000004 W PendSV_Handler&lt;BR /&gt;00000541 00000004 W PMC_IRQHandler&lt;BR /&gt;00000541 00000004 W PORTA_IRQHandler&lt;BR /&gt;00000541 00000004 W PORTB_IRQHandler&lt;BR /&gt;200001dc 00000004 b prevWatchdogCounter.4128.4486&lt;BR /&gt;00000541 00000004 W Reserved16_IRQHandler&lt;BR /&gt;00000541 00000004 W Reserved17_IRQHandler&lt;BR /&gt;00000541 00000004 W Reserved18_IRQHandler&lt;BR /&gt;00000541 00000004 W Reserved19_IRQHandler&lt;BR /&gt;00000541 00000004 W Reserved20_IRQHandler&lt;BR /&gt;00000541 00000004 W Reserved25_IRQHandler&lt;BR /&gt;00000541 00000004 W Reserved27_IRQHandler&lt;BR /&gt;00000541 00000004 W Reserved29_IRQHandler&lt;BR /&gt;00000541 00000004 W Reserved30_IRQHandler&lt;BR /&gt;00000541 00000004 W Reserved35_IRQHandler&lt;BR /&gt;00000541 00000004 W Reserved38_IRQHandler&lt;BR /&gt;00000541 00000004 W Reserved39_IRQHandler&lt;BR /&gt;00000541 00000004 W Reserved40_IRQHandler&lt;BR /&gt;00000541 00000004 W Reserved41_IRQHandler&lt;BR /&gt;00000541 00000004 W Reserved42_IRQHandler&lt;BR /&gt;00000541 00000004 W Reserved43_IRQHandler&lt;BR /&gt;00000541 00000004 W Reserved45_IRQHandler&lt;BR /&gt;00000541 00000004 W RTC_IRQHandler&lt;BR /&gt;00000541 00000004 W RTC_Seconds_IRQHandler&lt;BR /&gt;200001bc 00000004 b s_i2cHandle.5355.4492&lt;BR /&gt;200001c0 00000004 b s_i2cMasterIsr.5350.4498&lt;BR /&gt;200001c4 00000004 b s_i2cSlaveIsr.5352.4490&lt;BR /&gt;00000541 00000004 W SPI0_DriverIRQHandler&lt;BR /&gt;0000055d 00000004 W SPI0_IRQHandler&lt;BR /&gt;0000054d 00000004 W SVC_Handler&lt;BR /&gt;1ffffec0 00000004 d SystemCoreClock.4485&lt;BR /&gt;00000555 00000004 W SysTick_Handler&lt;BR /&gt;00000541 00000004 W TPM0_IRQHandler&lt;BR /&gt;00000541 00000004 W TPM1_IRQHandler&lt;BR /&gt;00000f10 00000008 t lircFreqs.4791.4918.4510&lt;BR /&gt;00000efd 00000010 T memset&lt;BR /&gt;000006d1 00000012 T __aeabi_idivmod&lt;BR /&gt;00000611 00000012 T __aeabi_uidivmod&lt;BR /&gt;000003c0 00000020 R BootloaderConfig&lt;BR /&gt;00000e61 00000024 T SystemInit&lt;BR /&gt;00000895 0000002c t CLOCK_GetLircClkFreq.4841.4480&lt;BR /&gt;000008c1 0000002c t CLOCK_GetOutClkFreq.4476&lt;BR /&gt;00000e85 0000002c T exit&lt;BR /&gt;00000a55 00000034 T I2C0_DriverIRQHandler&lt;BR /&gt;00000eb1 0000004c T __libc_init_array&lt;BR /&gt;1ffffe00 00000050 d __compound_literal.1.4555.4495&lt;BR /&gt;000004e9 00000058 W Reset_Handler&lt;BR /&gt;1fffff34 00000060 d impure_data&lt;BR /&gt;1ffffe50 00000070 d __compound_literal.0.4554.4494&lt;BR /&gt;1ffffec4 00000070 d keyMatrix.4493&lt;BR /&gt;00000df1 00000070 T LPTMR0_IRQHandler&lt;BR /&gt;00000589 00000088 T __udivsi3&lt;BR /&gt;00000625 000000ac T __divsi3&lt;BR /&gt;00000000 000000c0 R __isr_vector&lt;BR /&gt;1fffffb4 00000102 b rxMessage.4508&lt;BR /&gt;200000b7 00000102 b txMessage.4496&lt;BR /&gt;000008ed 00000168 t i2cSlaveCallback.4289.4113&lt;BR /&gt;000006e9 000001ac t I2C_SlaveTransferHandleIRQ.4216&lt;BR /&gt;00000a89 00000368 T main&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;According to my knowledge the "b" and "d" records are relevant for RAM allocation, so I computed these records by executing the following on Linux:&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;$ nm --print-size --size-sort uhk-left.elf | egrep '^[0-9a-f]{8} [0-9a-f]{8} [bd]' | awk '{print $2}' | awk '{print "0x" $0}' | awk '{s+=strtonum($1)} END {print s}'&lt;BR /&gt;953&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1600 vs 953 bytes are quite a difference. Would any of you explain which is right and why the two values don't match?&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much in advance!&lt;/P&gt;&lt;P&gt;- Laci&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Original Attachment has been moved to: &lt;A _jive_internal="true" href="https://community.nxp.com/docs/DOC-337463"&gt;uhk-left.map.zip&lt;/A&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Original Attachment has been moved to: &lt;A _jive_internal="true" href="https://community.nxp.com/docs/DOC-337463"&gt;uhk-left.elf.zip&lt;/A&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 27 Sep 2017 20:06:14 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-much-free-RAM-do-I-have/m-p/714481#M43864</guid>
      <dc:creator>laszlomonda</dc:creator>
      <dc:date>2017-09-27T20:06:14Z</dc:date>
    </item>
    <item>
      <title>Re: How much free RAM do I have?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-much-free-RAM-do-I-have/m-p/714482#M43865</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Laci&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Take a look in the map file that is generated. Search for the highest address in SRAM and this will be the value that you need.&lt;/P&gt;&lt;P&gt;Generally you will find &lt;BR /&gt;.data&lt;BR /&gt;.bss&lt;/P&gt;&lt;P&gt;.non_init&lt;BR /&gt;.heap&lt;BR /&gt;.stack&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and .stack will be the highest address.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you don't use heap, make sure that it is 0 in length (to save wasting space).&lt;BR /&gt;Often the size of stack needs to be set in the linker script but I set 0 and just use the remaining SRAM for the stack. In any case, you must also know how much stack your application uses in its worst run-time case to be sure that you have adequate memory.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Mark&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A class="jive-link-external-small" href="https://community.nxp.com/external-link.jspa?url=http%3A%2F%2Fwww.utasker.com%2Fkinetis.html" rel="nofollow" target="_blank"&gt;http://www.utasker.com/kinetis.html&lt;/A&gt;&lt;BR /&gt;&lt;A class="jive-link-external-small" href="https://community.nxp.com/external-link.jspa?url=http%3A%2F%2Fwww.utasker.com%2Fkinetis%2FFRDM-KL03Z.html" rel="nofollow" target="_blank"&gt;http://www.utasker.com/kinetis/FRDM-KL03Z.html&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 27 Sep 2017 22:00:46 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-much-free-RAM-do-I-have/m-p/714482#M43865</guid>
      <dc:creator>mjbcswitzerland</dc:creator>
      <dc:date>2017-09-27T22:00:46Z</dc:date>
    </item>
    <item>
      <title>Re: How much free RAM do I have?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-much-free-RAM-do-I-have/m-p/714483#M43866</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="padding: 0px;"&gt;Hi Mark,&lt;/P&gt;&lt;P style="padding: 0px;"&gt;&lt;/P&gt;&lt;P style="padding: 0px;"&gt;I also attached is the uhk-left.map file above.&lt;/P&gt;&lt;P style="padding: 0px;"&gt;&lt;/P&gt;&lt;P style="padding: 0px;"&gt;It seems to me that I'm using heap and it occupies 0x204 bytes. Is this correct? When should I use heap?&lt;/P&gt;&lt;P style="padding: 0px;"&gt;&lt;/P&gt;&lt;P style="padding: 0px;"&gt;0x20000600 seems to be the highest address. Is this correct? Where does this leave us regarding RAM consumption?&lt;/P&gt;&lt;P style="padding: 0px;"&gt;&lt;/P&gt;&lt;P style="padding: 0px;"&gt;Thanks so much!&lt;/P&gt;&lt;P style="padding: 0px;"&gt;- Laci&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 27 Sep 2017 22:24:23 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-much-free-RAM-do-I-have/m-p/714483#M43866</guid>
      <dc:creator>laszlomonda</dc:creator>
      <dc:date>2017-09-27T22:24:23Z</dc:date>
    </item>
    <item>
      <title>Re: How much free RAM do I have?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-much-free-RAM-do-I-have/m-p/714484#M43867</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Laci&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You have 0x204 [516] bytes of heap and the stack area is defined to use the remaining space (0x20000600 - 0x200003e8) 0x218 [536].&lt;BR /&gt;I don't know whether you use heap (malloc() etc.) or not - if not, you can set HEAP_SIZE in your linker script to 0 to save this space.&lt;BR /&gt;Your variables occupy 0x1ffffe00 ..0x200001e4, which is 0x3e4 [996] bytes&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;996 variables + 516 heap + 536 stack = 2k exactly&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The SRAM consumption also depends on the stack use. This means the local variables and buffers used by each subroutine in the call stack and interrupts. If you fill the stack area with a pattern before the code starts you can get a good idea of its utilisation by seeing which is the lowest address in the stack area where the pattern has been overwritten by the stack use.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Since you have a small chip, with only 2k of SRAM you should be consistently monitoring these details as the project evolves to be sure that there is adequate stack margin to ensure safe operation.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Mark&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 Sep 2017 03:18:35 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-much-free-RAM-do-I-have/m-p/714484#M43867</guid>
      <dc:creator>mjbcswitzerland</dc:creator>
      <dc:date>2017-09-28T03:18:35Z</dc:date>
    </item>
    <item>
      <title>Re: How much free RAM do I have?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-much-free-RAM-do-I-have/m-p/714485#M43868</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks so much for the further explanation, Mark!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Given that I don't utilize malloc() at all, setting the heap size to zero would definitely make a lot of sense for me. I found HEAP_SIZE in &lt;A href="https://github.com/UltimateHackingKeyboard/KSDK_2.0_MKL03Z8xxx4/blob/ac55fc28ee6aa68cddcac00f6b76398cd8c0b541/devices/MKL03Z4/gcc/MKL03Z32xxx4_flash.ld#L52"&gt;MKL03Z32xxx4_flash.ld&lt;/A&gt; and &lt;A href="https://github.com/UltimateHackingKeyboard/KSDK_2.0_MKL03Z8xxx4/blob/ac55fc28ee6aa68cddcac00f6b76398cd8c0b541/devices/MKL03Z4/gcc/MKL03Z32xxx4_ram.ld#L52"&gt;MKL03Z32xxx4_ram.ld&lt;/A&gt;&amp;nbsp;within the KSDK. It'd be nice to modify the heap without touching the KSDK files. I can see that&amp;nbsp;HEAP_SIZE depends on&amp;nbsp;__heap_size__. Is there any way to change this from &lt;A href="https://github.com/UltimateHackingKeyboard/firmware/tree/master/left"&gt;my project&lt;/A&gt;?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks again!&lt;/P&gt;&lt;P&gt;- Laci&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Oct 2017 19:03:41 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-much-free-RAM-do-I-have/m-p/714485#M43868</guid>
      <dc:creator>laszlomonda</dc:creator>
      <dc:date>2017-10-06T19:03:41Z</dc:date>
    </item>
    <item>
      <title>Re: How much free RAM do I have?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-much-free-RAM-do-I-have/m-p/714486#M43869</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Laci&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I don't work with KSDK so someone else will need to give an authoritative answer, however the heap size value is probably used by a library and is therefore needed. Since it is defined in a linker script file (nasty way in my opinion since it makes the file project-specific) there may be no other option but to edit it there and make the file project-specific.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Mark&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Oct 2017 19:52:35 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-much-free-RAM-do-I-have/m-p/714486#M43869</guid>
      <dc:creator>mjbcswitzerland</dc:creator>
      <dc:date>2017-10-06T19:52:35Z</dc:date>
    </item>
    <item>
      <title>Re: How much free RAM do I have?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-much-free-RAM-do-I-have/m-p/714487#M43870</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This article describes how to set the heap and stack size in the GNU linker file without changing the linker file itself:&lt;/P&gt;&lt;P&gt;&lt;A href="https://mcuoneclipse.com/2016/04/17/changing-heap-and-stack-size-for-nxp-kinetis-sdk-v2-0-gcc-projects/"&gt;https://mcuoneclipse.com/2016/04/17/changing-heap-and-stack-size-for-nxp-kinetis-sdk-v2-0-gcc-projects/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I hope this helps,&lt;/P&gt;&lt;P&gt;Erich&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 07 Oct 2017 05:44:36 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-much-free-RAM-do-I-have/m-p/714487#M43870</guid>
      <dc:creator>BlackNight</dc:creator>
      <dc:date>2017-10-07T05:44:36Z</dc:date>
    </item>
  </channel>
</rss>

