<?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 to configure heap and stack sizes in MCUXpresso in MCUXpresso IDE</title>
    <link>https://community.nxp.com/t5/MCUXpresso-IDE/How-to-configure-heap-and-stack-sizes-in-MCUXpresso/m-p/982344#M4973</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Since you're using a FreeRTOS-based project, your change will obviously not help. You're changing the heap size used by the standard C malloc whereas FreeRTOS uses its own memory allocation scheme. If you'll carefully inspect the implementation of prvHeapInit, you'll notice that the total heap size is set to&amp;nbsp;configTOTAL_HEAP_SIZE (which is actually hardcoded to 10K in FreeRTOSConfig.h). This is what you need to change.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The initial stack size should be correctly controlled by the setting you mentioned. The initial MSP is set to _vStackTop that's depending on&amp;nbsp;_StackSize. Check the linker script. Regarding the stack size allocated to a task, isn't that configured/specified when you create the actual task? I don't have much knowledge of the FreeRTOS code itself.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Greetings,&lt;BR /&gt;MCUXpresso IDE Support&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 13 Nov 2019 07:36:20 GMT</pubDate>
    <dc:creator>lpcxpresso_supp</dc:creator>
    <dc:date>2019-11-13T07:36:20Z</dc:date>
    <item>
      <title>How to configure heap and stack sizes in MCUXpresso</title>
      <link>https://community.nxp.com/t5/MCUXpresso-IDE/How-to-configure-heap-and-stack-sizes-in-MCUXpresso/m-p/982343#M4972</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am using MCUXpresso IDE v11.0.0_2516, the FRDM-K22F board and the FreeRTOS 9.0.0 port that comes with SDK.&lt;/P&gt;&lt;P&gt;In the application I am developing, I have no space for creating new dynamic data. So, the first step was increasing the heap size on "Project-&amp;gt;Properties-&amp;gt;C/C++ Build-&amp;gt;Settings-&amp;gt;MCU C++ Linker-&amp;gt;Managed Linker Script" as in figures below.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_1.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/89614i89F58A705ABB791D/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_1.png" alt="pastedImage_1.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The default value that is set is 0x1000 for the heap and 0x1000 for the stack. I set a breakpoint on pvPortMalloc, so I can see the first time that it is called. The "xFreeBytesRemaining" variable wich has the available memory remain is "10224" in first call.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, when I tried to increase the heap size (let's say heap 0x1600 and stack 0x400) nothing happens. The "xFreeBytesRemaining" remains "10224" and application is stuck in same point.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any tips on what is happening, and what can be done?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Nov 2019 19:18:15 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCUXpresso-IDE/How-to-configure-heap-and-stack-sizes-in-MCUXpresso/m-p/982343#M4972</guid>
      <dc:creator>matheus_pinto1</dc:creator>
      <dc:date>2019-11-12T19:18:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to configure heap and stack sizes in MCUXpresso</title>
      <link>https://community.nxp.com/t5/MCUXpresso-IDE/How-to-configure-heap-and-stack-sizes-in-MCUXpresso/m-p/982344#M4973</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Since you're using a FreeRTOS-based project, your change will obviously not help. You're changing the heap size used by the standard C malloc whereas FreeRTOS uses its own memory allocation scheme. If you'll carefully inspect the implementation of prvHeapInit, you'll notice that the total heap size is set to&amp;nbsp;configTOTAL_HEAP_SIZE (which is actually hardcoded to 10K in FreeRTOSConfig.h). This is what you need to change.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The initial stack size should be correctly controlled by the setting you mentioned. The initial MSP is set to _vStackTop that's depending on&amp;nbsp;_StackSize. Check the linker script. Regarding the stack size allocated to a task, isn't that configured/specified when you create the actual task? I don't have much knowledge of the FreeRTOS code itself.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Greetings,&lt;BR /&gt;MCUXpresso IDE Support&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 13 Nov 2019 07:36:20 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCUXpresso-IDE/How-to-configure-heap-and-stack-sizes-in-MCUXpresso/m-p/982344#M4973</guid>
      <dc:creator>lpcxpresso_supp</dc:creator>
      <dc:date>2019-11-13T07:36:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to configure heap and stack sizes in MCUXpresso</title>
      <link>https://community.nxp.com/t5/MCUXpresso-IDE/How-to-configure-heap-and-stack-sizes-in-MCUXpresso/m-p/982345#M4974</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I solve my problem!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Firstly, FreeRTOS does not use the heap or stack defined in the linker. Normally, this heap is set to zero and the stack value set to a minimum for main function use.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Using the "Heap 4" option, the "heap_4.c" file located at "freertos-&amp;gt;portable" within the project directory, the heap is declared as a global variable like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new, courier, monospace;"&gt;static uint8_t ucHeap [configTOTAL_HEAP_SIZE];&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Therefore, you can increase the size of the heap used by FreeRTOS through the configTOTAL_HEAP_SIZE macro in the FreeRTOSConfig.h file. Using the default memory settings available in "Project-&amp;gt; Properties-&amp;gt; C/C ++ Build-&amp;gt; Settings-&amp;gt; MCU C++ Linker-&amp;gt; Managed Linker Script" and increasing the size of this heap, the program will not compile because the ucHeap variable will exceed the SRAM UPPER (which is not allowed). For a value of ucHeap equal to 51200 bytes, in my case, is generated the following memory usage:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Memory region&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Used Size&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Region Size&amp;nbsp;&amp;nbsp; %age Used&lt;BR /&gt;PROGRAM_FLASH:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 216492 B&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 512 KB&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 41.29%&lt;BR /&gt;SRAM_UPPER:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 71516 B&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 64 KB&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 109.12%&lt;BR /&gt;SRAM_LOWER:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0 GB&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 64 KB&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.00%&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;make: *** [makefile:55: HartROS_v3.axf] Error 1&lt;BR /&gt;"make -r -j4 all" terminated with exit code 2. Build might be incomplete.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To get around this, my way out was to put the global variables (and hence ucHeap) in SRAM LOWER with all its space available for storage. For this, in "Project-&amp;gt; Properties-&amp;gt; C/C ++ Build-&amp;gt; Settings-&amp;gt; MCU C++ Linker-&amp;gt; Managed Linker Script" the "Global data placement" field was changed from "default" to "SRAM LOWER" as presented in figure below.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="global_sram.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/96274i2D255E296885E80C/image-size/large?v=v2&amp;amp;px=999" role="button" title="global_sram.png" alt="global_sram.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now my program compiles correctly after increasing the heap to 51200 bytes. The memory usage output was as follows:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Memory region&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Used Size&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Region Size&amp;nbsp;&amp;nbsp; %age Used&lt;BR /&gt;PROGRAM_FLASH:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 216492 B&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 512 KB&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 41.29%&lt;BR /&gt;SRAM_UPPER:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 8 KB&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 64 KB&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 12.50%&lt;BR /&gt;SRAM_LOWER:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 63324 B&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 64 KB&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 96.62%&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Finished building target: HartROS_v3.axf&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jan 2020 19:19:23 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCUXpresso-IDE/How-to-configure-heap-and-stack-sizes-in-MCUXpresso/m-p/982345#M4974</guid>
      <dc:creator>matheus_pinto1</dc:creator>
      <dc:date>2020-01-16T19:19:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to configure heap and stack sizes in MCUXpresso</title>
      <link>https://community.nxp.com/t5/MCUXpresso-IDE/How-to-configure-heap-and-stack-sizes-in-MCUXpresso/m-p/1605576#M8785</link>
      <description>&lt;P&gt;FYI - The responses here are correct only if you are using the FreeRTOS "heap4.c" implementation, where freeRTOS allocates memory from a static buffer. If you use "heap3.c", it uses the C library's malloc(), and these answers re not correct. Heap3 uses the heap as configured by the MCUXpresso linker. As far as I can see, if you are using the "MCUXpresso Style" heap and stack placement method, it's not easy (or maybe it's not possible) to assign a fixed stack size and then have the heap use "everything else."&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 25 Feb 2023 23:44:43 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCUXpresso-IDE/How-to-configure-heap-and-stack-sizes-in-MCUXpresso/m-p/1605576#M8785</guid>
      <dc:creator>brianknittel</dc:creator>
      <dc:date>2023-02-25T23:44:43Z</dc:date>
    </item>
  </channel>
</rss>

