cancel
Showing results for 
Search instead for 
Did you mean: 

LwIP Custom memory pool configuration

SSone.1
Associate III

I'm working on building an Ethernet infrastructure using LWIP on an STM32H7 series MCU for various purposes. In this setup, I want to avoid using malloc, and instead rely entirely on LWIP’s memory pool system for all memory allocations. Here's the configuration I’m planning to use:

MEM_LIBC_MALLOC               0   // Don't use the standard malloc (i.e., disable mem_malloc from libc)
MEMP_MEM_MALLOC               1   // Use mem_malloc for allocating MEMP pools
MEM_USE_POOLS                 1   // Redirect mem_malloc calls to the defined memory pools
MEMP_USE_CUSTOM_POOLS         1   // Enable support for user-defined custom pools
MEM_USE_POOLS_TRY_BIGGER_POOL 1   // Allow searching for a larger pool if needed

In lwippools.h, I’ll define custom pools with different sizes like this:

 

LWIP_MALLOC_MEMPOOL_START
   LWIP_MALLOC_MEMPOOL(24,  128)
   LWIP_MALLOC_MEMPOOL(16,  256)
   LWIP_MALLOC_MEMPOOL(8,   512)
   LWIP_MALLOC_MEMPOOL(4,  1024)
   LWIP_MALLOC_MEMPOOL(4,  1536)
LWIP_MALLOC_MEMPOOL_END

 

For RX, I will use the following structure from STM's LWIP examples:

 

#define ETH_RX_BUFFER_CNT             8U
LWIP_MEMPOOL_DECLARE(RX_POOL, ETH_RX_BUFFER_CNT, sizeof(RxBuff_t), "Zero-copy RX PBUF pool");
__DMA_RAM extern u8_t memp_memory_RX_POOL_base[];

 

I have three questions:

  1. The following two options seem to contradict each other: MEMP_MEM_MALLOC = 1 and MEM_USE_POOLS = 1. Will this configuration work as I intend (i.e., using mem_malloc() but redirecting it to pools)?

  2. If it does work, do I still need the memory space defined by PBUF_POOL_SIZE? Can I set this to 0? In other words, does my configuration allow LWIP to use only the custom pools defined in lwippools.h instead of the default PBUF_POOL memory?

  3. In this configuration, will LWIP allocate MEMP_NUM_.. defined pool items (e.g., MEMP_NUM_TCP_PCB, MEMP_NUM_NETBUF, etc.) from the default static MEMP pools, or will those also be served from the custom pools defined in lwippools.h?

 

0 REPLIES 0