How can I visualise the memory (SRAM) usage of an AVR program?

前端 未结 8 1065
不知归路
不知归路 2020-12-14 08:40

I have encountered a problem in a C program running on an AVR microcontroller (ATMega328P). I believe it is due to a stack/heap collision but I\'d like to be able to confirm

8条回答
  •  春和景丽
    2020-12-14 08:55

    On Unix like operating systems a library function named sbrk() with a parameter of 0 allows you to access the topmost address of dynamically allocated heap memory. The return value is a void * pointer and could be compared with the address of an arbitrary stack allocated variable.

    Using the result of this comparison should be used with care. Depending on the CPU and system architecture, the stack may be growing down from a arbitrary high address while the allocated heap will move up from low-bound memory.

    Sometimes the operating system has other concepts for memory management (i.e. OS/9) which places heap and stack in different memory segments in free memory. On these operating systems - especially for embedded systems - you need to define the maximum memory requirements of your applications in advance to enable the system to allocate memory segments of matching sizes.

提交回复
热议问题