AnsweredAssumed Answered

STM32F4 LwIP memp Pbuf Linked List Pointer Corruption Causes Hard Fault

Question asked by Donovan.Nathan on Nov 16, 2016
Latest reply on Nov 17, 2016 by waclawek.jan
Hello STM32 group.  I don't post a lot, but frequently read and benefit from the conversations on this board so I wanted to update you on something we've recently spent quite a bit of time debugging.

We created an application based on the STM32F4x7_ETH_LwIP_V1.1.1 project.  (Apparently if you use the cube utility the default LwIP settings are configured the same way.  I haven't verified this.)

The problem presented with somewhat random hard faults.  If we pinged the controller continuously it might happen 4 or 5 times a day.  These were usually coming from the memp_tab[type] = memp->next; instruction in msg = (struct tcpip_msg *)memp_malloc(MEMP_TCPIP_MSG_INPKT); call from the tcpip_input() function in tcpip.c.  The pointer memp->next was usually pointed out to some random inaccessible place in memory, totally random.  Occasionally the faults came from other places in memory.

The SYS_LIGHTWEIGHT_PROT in lwipopts.h was switched off.  Enabling this switch fixed our problem.  Apparently the buffer allocation or memory allocation function was getting interrupted.  Switching this on protects the allocation/deallocation critical regions.

Hope this helps.