I spent several evenings with testing. It needs some time and good luck (or bad luck?) to cause the problem. Finally the problem also occured on the original lwip Demo. I only did the minimum changes to make the Olimex P407 demo run on the Discovery with Chinese DP83848 board (using Jacon's board.h).
Up to now, I was not able to reproduce the problem on the old ChibiOS Olimex P107 lwip demo with ST wrapper. Also the original lwip demo from ST works stable up to now. There is a port of the ST demo for the discovery board:
http://www.mikrocontroller.net/topic/237223#2491080
There is an obvious difference between ChibiOS and the ST demo:
With ChibiOS I loose ~40% of packets.
With ST demo I only loose ~2% of packets (it uses lwip 1.3.2)
I changed MEM_SIZE from 1600bytes to 10k as done in the ST demo, but no impact.
Edit:
Once the problem occurs, the lwipthread fails in low_level_input with
p = pbuf_alloc(PBUF_RAW, len, PBUF_POOL);
The MAC itself still receives the packets. This explains why a ping with smaller packets still works - there seems to be a memory leak.
In my point of view, this pbuf could be allocated statically, because the lwipthread is not re-entrant. But the lwip architecture frees this buffer in different places.
In the lwipthread main loop, is it ensured that the buffer is always freed by the input handler when the switch/case runs into the break?
Code: Select all
if (mask & FRAME_RECEIVED_ID) {
struct pbuf *p;
while ((p = low_level_input(&thisif)) != NULL) {
struct eth_hdr *ethhdr = p->payload;
// GPIOD->ODR = GPIOD->ODR ^ (1<<15); // toggle LED unten
switch (htons(ethhdr->type)) {
/* IP or ARP packet? */
case ETHTYPE_IP:
case ETHTYPE_ARP:
#if PPPOE_SUPPORT
/* PPPoE packet? */
case ETHTYPE_PPPOEDISC:
case ETHTYPE_PPPOE:
#endif /* PPPOE_SUPPORT */
/* full packet send to tcpip_thread to process */
if (thisif.input(p, &thisif) == ERR_OK)
break;
LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: IP input error\n"));
default:
pbuf_free(p);
}
}