<?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 Defining Start of Heap in Kinetis Microcontrollers</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Defining-Start-of-Heap/m-p/692809#M42686</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 trying to figure out how can I define the start and end of the Heap.&lt;/P&gt;&lt;P&gt;My processor is MK66 with 256K Ram &amp;amp; Atolic True Studio.&lt;/P&gt;&lt;P&gt;The Ram Starts at 0x1FFF 0000 and ends at 0x2002 FFFF.&lt;/P&gt;&lt;P&gt;According to Data sheet the memory is not divided into two regions.&lt;/P&gt;&lt;P&gt;SRAM_L&amp;nbsp;&amp;nbsp;&amp;nbsp; From&amp;nbsp; 0x1FFF 0000&amp;nbsp;&amp;nbsp;&amp;nbsp; to &amp;nbsp;&amp;nbsp;&amp;nbsp; 0x1FFF FFFF&amp;nbsp;&amp;nbsp; (in total 64K bytes).&lt;/P&gt;&lt;P&gt;SRAM_U&amp;nbsp;&amp;nbsp; From&amp;nbsp; 0x2000 0000&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; to&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0x2002 FFFF&amp;nbsp;&amp;nbsp; (in total 192K bytes).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want to place Data, Fast Code &amp;amp; Stack in SRAM_L Region. And the Heap in SRAM_U region.&lt;/P&gt;&lt;P&gt;The first part is easy but I don't know how to tell the Linker to place Heap at the start of SRAM_U.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;By default the linker script provided by Atolic considers the whole Ram as one continuous Region and places the the start of Heap at some where after end of .bss section.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;(I know from my previous experience with TI's TMS320 DSP where there were symbols called ".sysmem" &amp;amp; "heap size" which could be linked at desired address and with desired size. )&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 11 Jul 2017 15:50:16 GMT</pubDate>
    <dc:creator>ishwarlal</dc:creator>
    <dc:date>2017-07-11T15:50:16Z</dc:date>
    <item>
      <title>Defining Start of Heap</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Defining-Start-of-Heap/m-p/692809#M42686</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 trying to figure out how can I define the start and end of the Heap.&lt;/P&gt;&lt;P&gt;My processor is MK66 with 256K Ram &amp;amp; Atolic True Studio.&lt;/P&gt;&lt;P&gt;The Ram Starts at 0x1FFF 0000 and ends at 0x2002 FFFF.&lt;/P&gt;&lt;P&gt;According to Data sheet the memory is not divided into two regions.&lt;/P&gt;&lt;P&gt;SRAM_L&amp;nbsp;&amp;nbsp;&amp;nbsp; From&amp;nbsp; 0x1FFF 0000&amp;nbsp;&amp;nbsp;&amp;nbsp; to &amp;nbsp;&amp;nbsp;&amp;nbsp; 0x1FFF FFFF&amp;nbsp;&amp;nbsp; (in total 64K bytes).&lt;/P&gt;&lt;P&gt;SRAM_U&amp;nbsp;&amp;nbsp; From&amp;nbsp; 0x2000 0000&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; to&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0x2002 FFFF&amp;nbsp;&amp;nbsp; (in total 192K bytes).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want to place Data, Fast Code &amp;amp; Stack in SRAM_L Region. And the Heap in SRAM_U region.&lt;/P&gt;&lt;P&gt;The first part is easy but I don't know how to tell the Linker to place Heap at the start of SRAM_U.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;By default the linker script provided by Atolic considers the whole Ram as one continuous Region and places the the start of Heap at some where after end of .bss section.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;(I know from my previous experience with TI's TMS320 DSP where there were symbols called ".sysmem" &amp;amp; "heap size" which could be linked at desired address and with desired size. )&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 11 Jul 2017 15:50:16 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Defining-Start-of-Heap/m-p/692809#M42686</guid>
      <dc:creator>ishwarlal</dc:creator>
      <dc:date>2017-07-11T15:50:16Z</dc:date>
    </item>
    <item>
      <title>Re: Defining Start of Heap</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Defining-Start-of-Heap/m-p/692810#M42687</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi again,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;there is a typo in sentence number 4 so here is my question re posted.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am trying to figure out how can I define the start and end of the Heap.&lt;/P&gt;&lt;P&gt;My processor is MK66 with 256K Ram &amp;amp; Atolic True Studio.&lt;/P&gt;&lt;P&gt;The Ram Starts at 0x1FFF 0000 and ends at 0x2002 FFFF.&lt;/P&gt;&lt;P&gt;According to Data sheet the memory is divided into two regions. &lt;/P&gt;&lt;P&gt;SRAM_L&amp;nbsp;&amp;nbsp;&amp;nbsp; From&amp;nbsp; 0x1FFF 0000&amp;nbsp;&amp;nbsp;&amp;nbsp; to &amp;nbsp;&amp;nbsp;&amp;nbsp; 0x1FFF FFFF&amp;nbsp;&amp;nbsp; (in total 64K bytes).&lt;/P&gt;&lt;P&gt;SRAM_U&amp;nbsp;&amp;nbsp; From&amp;nbsp; 0x2000 0000&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; to&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0x2002 FFFF&amp;nbsp;&amp;nbsp; (in total 192K bytes).&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to place Data, Fast Code &amp;amp; Stack in SRAM_L Region. And the Heap in SRAM_U region.&lt;/P&gt;&lt;P&gt;The first part is easy but I don't know how to tell the Linker to place Heap at the start of SRAM_U.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;By default the linker script provided by Atolic considers the whole Ram as one continuous Region and places the the start of Heap at some where after end of .bss section.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(I know from my previous experience with TI's TMS320 DSP where there were symbols called ".sysmem" &amp;amp; "heap size" which could be linked at desired address and with desired size. )&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Lal.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 11 Jul 2017 15:55:47 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Defining-Start-of-Heap/m-p/692810#M42687</guid>
      <dc:creator>ishwarlal</dc:creator>
      <dc:date>2017-07-11T15:55:47Z</dc:date>
    </item>
    <item>
      <title>Re: Defining Start of Heap</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Defining-Start-of-Heap/m-p/692811#M42688</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 think I found the answer to my question but if someone have a better one please feel free to correct me.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Well after a bit research I came across this article of stackoverflow.com: (which shed some light on the matter)&lt;/P&gt;&lt;P&gt;&lt;A class="link-titled" href="https://stackoverflow.com/questions/22317477/setting-up-heap-in-memory-for-arm-embedded-system" title="https://stackoverflow.com/questions/22317477/setting-up-heap-in-memory-for-arm-embedded-system"&gt;gcc - setting up heap in memory for ARM embedded system - Stack Overflow&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Atolic True Studio Provides following "_sbrk" function in syscalls.c file. which is called in this sequence&lt;/P&gt;&lt;P&gt;( new[] -&amp;gt; malloc() -&amp;gt; _sbrk_r() -&amp;gt; _sbrk()&amp;nbsp; ).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;caddr_t _sbrk(int32_t incr)&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;{&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;extern uint8_t end asm("end");&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;static uint8_t *heap_end;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;uint8_t *prev_heap_end;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;if (heap_end == 0)&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;heap_end = &amp;amp;end;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;prev_heap_end = heap_end;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;if (heap_end + incr &amp;gt; stack_ptr)&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;{&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;errno = ENOMEM;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;return (caddr_t) -1;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; heap_end += incr;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return (caddr_t) prev_heap_end;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;}&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and also see the following listing from linker file.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; /* User_heap_stack section, used to check that there is enough RAM left */&lt;BR /&gt;&amp;nbsp; ._user_heap_stack :&lt;BR /&gt;&amp;nbsp; {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; . = ALIGN(4);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; PROVIDE ( end = . );&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; PROVIDE ( _end = . );&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; . = . + _Min_Heap_Size;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; . = . + _Min_Stack_Size;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; . = ALIGN(4);&lt;BR /&gt;&amp;nbsp; } &amp;gt;RAM&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;in both the listings the symbol "end" is the key.&lt;/P&gt;&lt;P&gt;This symbol defines the start point of Heap and you can control the Heap size by re-writing the function "&lt;EM&gt;_sbrk&lt;/EM&gt;", for that see also the link &lt;A class="link-titled" href="https://stackoverflow.com/questions/22317477/setting-up-heap-in-memory-for-arm-embedded-system" title="https://stackoverflow.com/questions/22317477/setting-up-heap-in-memory-for-arm-embedded-system"&gt;gcc - setting up heap in memory for ARM embedded system - Stack Overflow&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Lal&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 12 Jul 2017 08:10:35 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Defining-Start-of-Heap/m-p/692811#M42688</guid>
      <dc:creator>ishwarlal</dc:creator>
      <dc:date>2017-07-12T08:10:35Z</dc:date>
    </item>
    <item>
      <title>Re: Defining Start of Heap</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Defining-Start-of-Heap/m-p/692812#M42689</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;also see this thread &lt;A href="https://community.nxp.com/thread/443554"&gt;https://community.nxp.com/thread/443554&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Lal&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Jul 2017 09:47:55 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Defining-Start-of-Heap/m-p/692812#M42689</guid>
      <dc:creator>ishwarlal</dc:creator>
      <dc:date>2017-07-13T09:47:55Z</dc:date>
    </item>
  </channel>
</rss>

