<div dir="ltr"><div dir="ltr"><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Mar 23, 2019 at 9:37 PM Florian Klämpfl <<a href="mailto:florian@freepascal.org">florian@freepascal.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Am 23.03.2019 um 11:52 schrieb Dimitrios Chr. Ioannidis via fpc-devel:<br>
> Hi,<br>
> <br>
> I'm using the heapmgr unit and, for the atmega328p, AFAIU the default heap size is 80 bytes. Cause it's too small for<br>
> my needs, I changed to 512 bytes ( -Ch512 ). But now I'm worrying for the stack and heap collision.<br>
> <br>
> Can anybody know any resources, docs regarding FPC stack and heap management for the AVR platform ? Any hints, tools ?<br>
<br>
The sources ;) For the embedded targets, the stack grows downward from the highest ram address. So set a suitable stack<br>
size so you do not exceed total memory, test with stack checking on, then you should be fine.<br></blockquote><div></div><div><br></div><div>I did some testing of stack checking on AVR (the long version is here: <a href="https://github.com/ccrause/freepascal/wiki/Investigating-stack-and-heap-management-(avr-embedded)">https://github.com/ccrause/freepascal/wiki/Investigating-stack-and-heap-management-(avr-embedded)</a>). The short version is that I suspect there are a couple of problems with the current code:<br></div><div>* The AVR implementation of function Sptr (which should return the stack pointer I believe) is missing.</div><div>* The variable StackBottom (the stack limit) is not calculated correctly because some of the required pointer declarations are not correctly linked with corresponding external symbols.</div><div>* The current stack margin defined in system.inc of 16384 exceeds the SRAM in most AVR 8 bit controllers (the only exception is atmega1284P), so a smaller margin should be selected for the AVR target.<br></div><div><br> </div><div>If anyone can confirm these issues I can log a bug with patches. If I missed the plot (most of the relevant RTL code was unchanged for 8 years or longer) I would appreciate it if someone can point out where I made errors or misinterpreted code or specifications.<br></div></div></div></div>