lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lwip-users] MEM_SIZE


From: Giuseppe Modugno
Subject: Re: [lwip-users] MEM_SIZE
Date: Thu, 15 Mar 2018 10:33:47 +0100
User-agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0

Il 14/03/2018 20:26, address@hidden ha scritto:
On 14.03.2018 16:42, Giuseppe Modugno wrote:
I was experimenting with lwip memory allocator. I defined:

#define MEM_LIBC_MALLOC  0
#define MEM_USE_POOLS      0
#define MEM_SIZE  (32 * 1024)
#define LWIP_RAM_HEAP_POINTER  ( (void *)0x2007C000 )

I'm using LPC1768 that has a 32kB SRAM block starting from address
0x2007C000. However I have a Hard Fault error during mem_init(), because
ram_end is initialized to 0x2007C000 + (32*1024), that is over the
available memory.

So MEM_SIZE should be smaller than available heap memory.

Is that a question? Or an action request?
It was a question, even if I forgot to add a question mark :-)

To my understanding, the comment above #ifndef LWIP_RAM_HEAP_POINTER in mem.c clearly states that enough memory is required. It does NOT say that amount is MEM_SIZE. If you want, create a patch with a better documentation and we could apply it.
Ah ok, I now understand the comment "we need one struct mem at the end and some room for alignment".

MEM_SIZE isn't the total available memory for heap management (including accessory structs), but it is the *useful* memory space the application needs for the heap (excluding accessory structs). For example, if MEM_SIZE is 1024, I can be sure one malloc(1024) won't fail.

In my case, I have a completely free (not used by the linker) 32kB RAM region starting from 0x2007C000. To instruct lwip to use that region for heap, I think I have to define:

#define MEM_SIZE      (32 * 1024 - 1 * SIZEOF_STRUCT_MEM)
#define LWIP_RAM_HEAP_POINTER     ( (void *)0x2007C000 )

Supposing we don't need other additional space for alignment.
In this case the total free heap memory available for data is exactly MEM_SIZE, that is less than 32kB.

Is it correct?



reply via email to

[Prev in Thread] Current Thread [Next in Thread]