You are right, that makes sense.
Also, I found out that changing the ETH section does not actually move the relevant buffers of Lwip. I learned that there are two memory concepts used in Lwip: Heap and pools. Heap is mainly used for transmission buffers, pools for everything else. If you want to move heap to another location, make sure to set:
Code: Select all
#ifndef LWIP_RAM_HEAP_POINTER
#define LWIP_RAM_HEAP_POINTER (void *)0xC0200000UL // free storage for heap
#endif
in lwipopts.h. A void pointer is expected for the heap pointer that Lwip uses. This memory region should not be used otherwise (e.g. linker). I chose a place in SDRAM.
If you want to move your pools as well, you need to define this first in lwipopts.h:
Code: Select all
/**
* MEMP_SEPARATE_POOLS: if defined to 1, each pool is placed in its own array.
* This can be used to individually change the location of each pool.
* Default is one big array for all pools
*/
#ifndef MEMP_SEPARATE_POOLS
#define MEMP_SEPARATE_POOLS 1
#endif
Then, you can alter the pool definitions. It is suggested within the memp.c file that memory regions are declared as extern in "arch/cc.h":
Extract from memp.c:
Code: Select all
#if MEMP_SEPARATE_POOLS
/** This creates each memory pool. These are named memp_memory_XXX_base (where
* XXX is the name of the pool defined in memp_std.h).
* To relocate a pool, declare it as extern in cc.h. Example for GCC:
* extern u8_t __attribute__((section(".onchip_mem"))) memp_memory_UDP_PCB_base[];
*/
#define LWIP_MEMPOOL(name,num,size,desc) u8_t memp_memory_ ## name ## _base \
[((num) * (MEMP_SIZE + MEMP_ALIGN_SIZE(size)))];
#include "lwip/memp_std.h"
/** This array holds the base of each memory pool. */
static u8_t *const memp_bases[] = {
#define LWIP_MEMPOOL(name,num,size,desc) memp_memory_ ## name ## _base,
#include "lwip/memp_std.h"
};
For names of all available (and used) memory regions, look at memp_std.h.
You can then add this to ch.h, just at the end:
Code: Select all
extern u8_t __attribute__((section(".ram7"))) memp_memory_PBUF_POOL_base[];
extern u8_t __attribute__((section(".ram7"))) memp_memory_RAW_PCB_base[];
extern u8_t __attribute__((section(".ram7"))) memp_memory_UDP_PCB_base[];
extern u8_t __attribute__((section(".ram7"))) memp_memory_TCP_PCB_base[];
extern u8_t __attribute__((section(".ram7"))) memp_memory_TCP_PCB_LISTEN_base[];
extern u8_t __attribute__((section(".ram7"))) memp_memory_TCP_SEG_base[];
extern u8_t __attribute__((section(".ram7"))) memp_memory_REASSDATA_base[];
extern u8_t __attribute__((section(".ram7"))) memp_memory_FRAG_PBUF_base[];
extern u8_t __attribute__((section(".ram7"))) memp_memory_NETBUF_base[];
extern u8_t __attribute__((section(".ram7"))) memp_memory_NETCONN_base[];
extern u8_t __attribute__((section(".ram7"))) memp_memory_FRAG_PBUF_base[];
"ram7" is a section that is defined in the .ld file. In my case, it starts at 0xC0000000.
I created an additional file for not having to change the lwip code base (lwippoolloc.h):
Code: Select all
/*
* lwippoolloc.h
*
* Created on: Apr 5, 2018
* Author: Useradmin
*/
#ifndef LWIPPOOLLOC_H_
#define LWIPPOOLLOC_H_
#include "arch/cc.h"
#include "lwip/opt.h"
#if MEMP_POOLS_RELOCATE && MEMP_SEPARATE_POOLS
extern u8_t __attribute__((section(".ram7"))) memp_memory_PBUF_POOL_base[];
#if LWIP_RAW
extern u8_t __attribute__((section(".ram7"))) memp_memory_RAW_PCB_base[];
#endif /* LWIP_RAW */
#if LWIP_UDP
extern u8_t __attribute__((section(".ram7"))) memp_memory_UDP_PCB_base[];
#endif /* LWIP_UDP */
#if LWIP_TCP
extern u8_t __attribute__((section(".ram7"))) memp_memory_TCP_PCB_base[];
extern u8_t __attribute__((section(".ram7"))) memp_memory_TCP_PCB_LISTEN_base[];
extern u8_t __attribute__((section(".ram7"))) memp_memory_TCP_SEG_base[];
#endif /* LWIP_TCP */
#if IP_REASSEMBLY
extern u8_t __attribute__((section(".ram7"))) memp_memory_REASSDATA_base[];
#endif /* IP_REASSEMBLY */
#if IP_FRAG && !IP_FRAG_USES_STATIC_BUF && !LWIP_NETIF_TX_SINGLE_PBUF
extern u8_t __attribute__((section(".ram7"))) memp_memory_FRAG_PBUF_base[];
#endif /* IP_FRAG && !IP_FRAG_USES_STATIC_BUF && !LWIP_NETIF_TX_SINGLE_PBUF */
#if LWIP_NETCONN
extern u8_t __attribute__((section(".ram7"))) memp_memory_NETBUF_base[];
extern u8_t __attribute__((section(".ram7"))) memp_memory_NETCONN_base[];
#endif /* LWIP_NETCONN */
extern u8_t __attribute__((section(".ram7"))) memp_memory_FRAG_PBUF_base[];
#endif
#endif /* LWIPPOOLLOC_H_ */
It is included in lwipopts.h at the very end, along with a new setting "MEMP_POOLS_RELOCATE":
Code: Select all
// ... Other code
#ifndef MEMP_POOLS_RELOCATE
#define MEMP_POOLS_RELOCATE 1
#endif
// ... Other code
#if MEMP_POOLS_RELOCATE
#include "lwippoolloc.h"
#endif
#endif /* __LWIPOPT_H__ */
Make sure to disable caching for pool and heap!