<?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: Set Stack onto external memory in LPC Microcontrollers</title>
    <link>https://community.nxp.com/t5/LPC-Microcontrollers/Set-Stack-onto-external-memory/m-p/616870#M24105</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Don't forget that as soon as you come out of reset, the stack will be used. If you are using external memory, it won't have been initialised (through the EMC) and so it is anybody's guess what will happen - hard fault seems very likely. You will only be able to set up the stack after you have set up the EMC for your memory, so you will need to use on chip ram for the initial stack, and then you will need to change the SP to point to the new memory.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;p.s. Don't forget the stack grows DOWN so you will need to set it to the top of memory, otherwise, as you are trying to do, it will occupy the same space as your heap - not a good idea, and really hard to debug if you don't realise...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 09 Feb 2017 16:25:23 GMT</pubDate>
    <dc:creator>converse</dc:creator>
    <dc:date>2017-02-09T16:25:23Z</dc:date>
    <item>
      <title>Set Stack onto external memory</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/Set-Stack-onto-external-memory/m-p/616869#M24104</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;On my custom board, I have set an external RAM on 32MB. I use it as heap with the following:&lt;span class="lia-inline-image-display-wrapper" image-alt="HardFault.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/13352iE45E0A6C64AE88E8/image-size/large?v=v2&amp;amp;px=999" role="button" title="HardFault.png" alt="HardFault.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;--defsym=__user_heap_base=0xA0000000&lt;/P&gt;&lt;P&gt;--defsym=_pvHeapLimit=0xA2000000&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;since Redlib offers this symbols. It works fine.&lt;/P&gt;&lt;P&gt;Now I want to try using the external RAM for both heap and stack using this symbols:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;--defsym=__user_heap_base=0xA0000000&lt;/P&gt;&lt;P&gt;--defsym=__user_stack_top=0xA2000000&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;My code end&amp;nbsp;with a HardFault trying to execute a NULL pointer.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="MCU.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/13375i74CC341746746849/image-size/large?v=v2&amp;amp;px=999" role="button" title="MCU.png" alt="MCU.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Why this is happening? For sure I'm messing something about memory segmentation, or about its initialization.&lt;/P&gt;&lt;P&gt;I am thankful for your help&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Feb 2017 15:59:45 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/Set-Stack-onto-external-memory/m-p/616869#M24104</guid>
      <dc:creator>abderrezak</dc:creator>
      <dc:date>2017-02-09T15:59:45Z</dc:date>
    </item>
    <item>
      <title>Re: Set Stack onto external memory</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/Set-Stack-onto-external-memory/m-p/616870#M24105</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Don't forget that as soon as you come out of reset, the stack will be used. If you are using external memory, it won't have been initialised (through the EMC) and so it is anybody's guess what will happen - hard fault seems very likely. You will only be able to set up the stack after you have set up the EMC for your memory, so you will need to use on chip ram for the initial stack, and then you will need to change the SP to point to the new memory.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;p.s. Don't forget the stack grows DOWN so you will need to set it to the top of memory, otherwise, as you are trying to do, it will occupy the same space as your heap - not a good idea, and really hard to debug if you don't realise...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Feb 2017 16:25:23 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/Set-Stack-onto-external-memory/m-p/616870#M24105</guid>
      <dc:creator>converse</dc:creator>
      <dc:date>2017-02-09T16:25:23Z</dc:date>
    </item>
    <item>
      <title>Re: Set Stack onto external memory</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/Set-Stack-onto-external-memory/m-p/616871#M24106</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you, it is more clear for me now. For setting SP can I directly call &lt;SPAN style="color: #51626f; background-color: #f6f6f6;"&gt;__set_MSP&lt;/SPAN&gt;&amp;nbsp;from 'main' or my '&lt;SPAN style="color: #51626f; background-color: #f6f6f6;"&gt;SystemInit&lt;/SPAN&gt;', or is there some precaution to take before.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I know that Stack grows down and Heap grows up. For this reason I set Heap at start (0xA0000000) and Stack at top (0xA2000000). Why it is wrong to set it this way?&lt;/P&gt;&lt;P&gt;I thought malloc take care of not overflow Heap into the Stack. In addition, I will set&amp;nbsp;&lt;SPAN style="color: #51626f; background-color: #f6f6f6;"&gt;_pvHeapLimit&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;I referred to this picture&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="code-data-segments.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/13693i423EC2F060316A95/image-size/large?v=v2&amp;amp;px=999" role="button" title="code-data-segments.png" alt="code-data-segments.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Feb 2017 17:02:34 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/Set-Stack-onto-external-memory/m-p/616871#M24106</guid>
      <dc:creator>abderrezak</dc:creator>
      <dc:date>2017-02-09T17:02:34Z</dc:date>
    </item>
    <item>
      <title>Re: Set Stack onto external memory</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/Set-Stack-onto-external-memory/m-p/616872#M24107</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Don't forget that once you change the stack, you lose whatever information is currently on the stack, so you need to do it as soon as possible after startup (and after setting the EMC). I would set the EMC and change stack in your ResetISR, before doing anything else.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In your 1st post you set&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; background-color: #f6f6f6;"&gt;--defsym=_pvHeapLimit=0xA2000000&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; background-color: #f6f6f6;"&gt;So this is the maximum extent of the heap. If you set the stack to that same address, you are going to overwrite your heap with stack. So, you need to make sure that your heap and stack are far enough apart that they will not overwrite each other. That was the point I was trying to make. And no, malloc WILL NOT check for stack overflowing into the heap.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Feb 2017 18:21:27 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/Set-Stack-onto-external-memory/m-p/616872#M24107</guid>
      <dc:creator>converse</dc:creator>
      <dc:date>2017-02-09T18:21:27Z</dc:date>
    </item>
    <item>
      <title>Re: Set Stack onto external memory</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/Set-Stack-onto-external-memory/m-p/616873#M24108</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV style="color: #51626f; border: 0px; font-size: 14px;"&gt;&lt;DIV class="" style="border: 0px; font-weight: inherit; margin: 20px 0px;"&gt;&lt;P style="border: 0px; font-weight: inherit;"&gt;Hi,&lt;/P&gt;&lt;P style="border: 0px; font-weight: inherit;"&gt;Thank you for help.&lt;/P&gt;&lt;P style="border: 0px; font-weight: inherit;"&gt;Sure, in case of Heap and Stack, I will set&amp;nbsp;&lt;SPAN style="color: #51626f; background-color: #f6f6f6; border: 0px; font-weight: inherit;"&gt;_pvHeapLimit&lt;/SPAN&gt; to an other value.&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Feb 2017 07:22:21 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/Set-Stack-onto-external-memory/m-p/616873#M24108</guid>
      <dc:creator>abderrezak</dc:creator>
      <dc:date>2017-02-10T07:22:21Z</dc:date>
    </item>
  </channel>
</rss>

