help allocating heap and stack

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


Hello!

 

I have a question about allocating memory in an Atmel Studio Project. I have been suffering from stack overflows in my project and I was looking-

for some feedback on my process of allocating the two. 

 

My process is composed of the following steps:

 

1.) set stack and heap size to 0x01 in my linker script compile and see the size of the .bss section.

     The purpose of this step is to find the size of all the global variables in my application.

 

      here is the output:     

 

2.) allocate enough heap for the maximum amount of ram that could be taken by calls to malloc()

     for this, I used the mem_size of my LWIP and leave a little bit of cushion.

 

3.) allocate the remainder of RAM to the stack, I calculate this using the formula

     RAM SIZE - .bss - stack. Below you can see my calculations and compiler output

     

 

I'm wondering if this seems like a good approach for allocating heap and stack, also curious if there's an easier way to do it!

Also, I'm curious, is it normal for the data section to be 0? Finally, I was wondering as to why the .bss section grows as I allocate

my heap and stack, any ideas?

 

For reference, I am using Atmel studio 7, ASF, and in case it is relevant, the application is going on a ATSAME70N19B.

Also, I attached my linker script as a .txt :) 

 

 

Attachment(s): 

Last Edited: Sat. Aug 10, 2019 - 11:54 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I would normally think that stack usage is easier to predict (and test for) that heap usage (which is subject to memory leaks and such), and that therefore you'd want to look at calculating an appropriate stack size, and then "allocate the remainder" for the heap...

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

justinh109 wrote:
... also curious if there's an easier way to do it!
Yes though

  • restrictions wrt recursion, function pointers, and no variable length arrays as auto variables
  • not zero price

 

IAR C/C++ Development Guide (Arm)

[page 98]

Stack usage analysis

via User Guides: IAR Embedded Workbench for Arm

due to Mastering stack and heap for system reliability: Part 2 - Properly allocating stacks | Embedded

 

3. The GNATstack Tool — GNATstack 20.0w documentation

...

GNATstack aims at finding an upper-bound to stack usage by static analysis techniques that give accurate results if some conditions are met, such as no indirect calls, no variable-sized local variable, no recursion and full access to the complete environment (including run-time and system calls). 

...

GNAT is a part of FSF GCC.

 

both via

On Stacks - The Embedded Muse 309

 


GNAT Pro Comparison - Adacore

 

fyi, IAR EW ARM for Renesas is zero price from Renesas :

IAR Embedded Workbench® for Renesas Synergy™

via The Embedded Muse 365 | This Week's Cool Product

 

"Dare to be naïve." - Buckminster Fuller