title: RAM, Heap, and Stack memory for an STM32 board
body: <p>I am working on a project that requires at least 500 kB of memory to be used.  I have an SDK with this code defining the stack and the heap and it works fine.</p>
  
  <pre><code>Stack_Size      EQU     0x00004000
  
              AREA    STACK, NOINIT, READWRITE, ALIGN=3
  Stack_Mem       SPACE   Stack_Size
  __initial_sp
  
  
  ; &lt;h&gt; Heap Configuration
  ;   &lt;o&gt;  Heap Size (in Bytes) &lt;0x0-0xFFFFFFFF:8&gt;
  ; &lt;/h&gt;
  
  Heap_Size       EQU     0x00200000
  
              AREA    HEAP, NOINIT, READWRITE, ALIGN=3
  __heap_base
  Heap_Mem        SPACE   Heap_Size
  __heap_limit
  </code></pre>
  
  <p>However, I am trying to integrate a camera and LCD screen feature into this SDK, and when I do that, the highest values of the stack and heap that will at least bring up the LCD screen are shown below.  Any values higher than this and the LCD screen stays black and the application doesn´t appear to run.</p>
  
  <pre><code>Stack_Size      EQU     0x00004000
  
              AREA    STACK, NOINIT, READWRITE, ALIGN=3
  Stack_Mem       SPACE   Stack_Size
  __initial_sp
  
  
  ; &lt;h&gt; Heap Configuration
  ;   &lt;o&gt;  Heap Size (in Bytes) &lt;0x0-0xFFFFFFFF:8&gt;
  ; &lt;/h&gt;
  
  Heap_Size       EQU     0x00002B50
  
              AREA    HEAP, NOINIT, READWRITE, ALIGN=3
  __heap_base
  Heap_Mem        SPACE   Heap_Size
  __heap_limit
  </code></pre>
  
  <p>I need the sizes of the stack and heap in the second code sample to match the sizes in the first code sample so that I do not get stuck in a hard fault exception loop due to no memory being available.  Why does increasing the heap size make my project worse? Meaning how come it doesn´t even appear to run when I increase the heap size? </p>
  
  <p>I have attached a screenshot of my project options so you can see the configuration of the RAM.  </p>
  
  <p><img src="https://i.stack.imgur.com/ulkE7.jpg" alt="Screenshot"></p>
  
  <p>Below is the amount of memory I have. Doesn´t this mean that I have 2 MB of RAM?</p>
  
  <p>8 M x 32-bit SDRAM is connected to SDRAM Bank1 of the STM32F439NIH6 FMC
  interface.</p>
  
  <p>1 Mbit x 16 SRAM is connected to bank1 NOR/
  PSRAM2 of the FMC interface and both 8-bit
  and 16-bit access is allowed by BLN0 &amp; BLN1 connected to BLE &amp; BHE of SRAM
  respectively.</p>