cancel
Showing results for 
Search instead for 
Did you mean: 

HardFault with lwip+freeRTOS and STM32f745

twagner
Associate II
Posted on April 18, 2016 at 11:02

Hello,

I'm using the lwip stack in combination with FreeRTOS for a http server (Netconn API) and modbus TCP (FreeModbus).

I'm using the lwip stack and FreeRTOS from the ''STM32Cube_FW_F7_V1.3.0''.

Evriting works great for 10-20 min but after that time the processor crashes with a HardFault.

The HardFault happens in the function tcp_output at the line

''if (TCP_SEQ_LT(ntohl(seg->tcphdr->seqno), ntohl(useg->tcphdr->seqno))) {''.

The processor wants to load ''seg->tcphdr->seqno'' and ''useg->tcphdr->seqno'' but one pointer is not valid and the processor crashes at the address ''0800d50a'' with a HardFault and the flag unaligned memory access is set.

I activated the lwip_stats and get 60 errors at the memp[6].

In the lwipopts.h the SYS_LIGHTWEIGHT_PROT ist set and I teset different configuration in the lwipopts.h but noting helped.

Where can the problem come from?

Here my disassembly:

1010              if (TCP_SEQ_LT(ntohl(seg->tcphdr->seqno), ntohl(useg->tcphdr->seqno))) {

0800d4fc:   ldr r3, [r4, &sharp12]

0800d4fe:   ldr r0, [r3, &sharp4]

0800d500:   bl 0x80097d4 <lwip_ntohl>

0800d504:   mov r6, r0

0800d506:   ldr.w r3, [r8, &sharp12]

0800d50a:   ldr r0, [r3, &sharp4]

0800d50c:   bl 0x80097d4 <lwip_ntohl>

0800d510:   subs r0, r6, r0

0800d512:   cmp r0, &sharp0

0800d514:   bge.n 0x800d546 <tcp_output+526>

1012                struct tcp_seg **cur_seg = &(pcb->unacked);

#lwip #hardfault #stm32f745
4 REPLIES 4
Posted on April 18, 2016 at 11:18

It looks like useg-tcphdr is not aligned. You could sanity check that it is 4-byte aligned, and memcpy out seqno, but this might just move the problem down stream.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
twagner
Associate II
Posted on April 18, 2016 at 12:06

I activated the MEMP_DEBUG and get the message:

memp_malloc: out of memory in pool TCP_PCB

I increased the MEMP_NUM_TCP_PCB (for test purposes to 1000

http://www.dict.cc/englisch-deutsch/purposes.html

) but the meassage comes only later.

Posted on April 18, 2016 at 13:51

A bit scary that it doesn't recognize calloc/malloc return NULLs

So perhaps you have a resource leak, or are getting heap fragmentation. The former you'd want to chase down by understanding who allocated the resource, and then that all exit/return paths handle the release properly. For the latter, a fixed size pool method, where different size allocations a pull from a size appropriate pools, so small but longer term allocations don't bisect large blocks of otherwise free memory.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
sayagyimyo
Associate II
Posted on August 16, 2016 at 05:54

hi sir

I am myo from sg. I am trying to run Modbus tcp server on stm32 f207zg.

do you have source code for your Modbus tcp project.

can you share with me.

my mail is

mailto:sayagyimyo@gmail.com

thanks in advance.