HardFault with lwip

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

HardFault with lwip

twagner
Hello,
I'm using the lwip stack in combination with FreeRTOS for a http server and modbus TCP.
The modbus TCP part makes no Problems.
But after some page hits the lwip stack crashes with a HardFault.
The crashes happens in the tcp_output and tcp_input function.
The HardFault comes from a unaligned memory access.
I tested different lwipopts.h and nothing helped. Using the MEMP_OVERFLOW_CHECK make it worse.
Noticeable are the mbox errors.
If the MEMP_OVERFLOW_CHECK isn't setI get some errors at the memp[6] but the HardFault comes approximately ten times later.
Where can the problem come from?
What are god ways to find such a fault?
Here are my lwip_stats:
link = {xmit = 0, recv = 0, fw = 0, drop = 0, chkerr = 0, lenerr = 0, memerr = 0, rterr = 0, proterr = 0, opterr = 0, err = 0, cachehit = 0}
etharp = {xmit = 1, recv = 37, fw = 0, drop = 48, chkerr = 0, lenerr = 0, memerr = 0, rterr = 0, proterr = 48, opterr = 0, err = 0, cachehit = 13515}
ip = {xmit = 13515, recv = 25585, fw = 0, drop = 0, chkerr = 0, lenerr = 0, memerr = 0, rterr = 0, proterr = 0, opterr = 0, err = 0, cachehit = 0}
icmp = {xmit = 0, recv = 0, fw = 0, drop = 0, chkerr = 0, lenerr = 0, memerr = 0, rterr = 0, proterr = 0, opterr = 0, err = 0, cachehit = 0}
udp = {xmit = 0, recv = 8, fw = 0, drop = 0, chkerr = 0, lenerr = 0, memerr = 0, rterr = 0, proterr = 0, opterr = 0, err = 0, cachehit = 0}
tcp = {xmit = 13050, recv = 25574, fw = 0, drop = 66, chkerr = 0, lenerr = 0, memerr = 0, rterr = 0, proterr = 66, opterr = 0, err = 0, cachehit = 0}
mem = {avail = 20480, used = 184, max = 372, err = 0, illegal = 0}
memp = {{avail = 4, used = 0, max = 0, err = 0, illegal = 0},
                {avail = 10, used = 0, max = 0, err = 0, illegal = 0},
                {avail = 40, used = 40, max = 40, err = 0, illegal = 0},
                {avail = 30, used = 2, max = 2, err = 0, illegal = 0},
                {avail = 34, used = 2, max = 4, err = 0, illegal = 0},
                {avail = 2, used = 0, max = 1, err = 0, illegal = 0},
                {avail = 4, used = 1, max = 4, err = 0, illegal = 0},
                {avail = 8, used = 0, max = 0, err = 0, illegal = 0},
                {avail = 8, used = 0, max = 7, err = 0, illegal = 0},
                {avail = 20, used = 4, max = 4, err = 0, illegal = 0},
                {avail = 200, used = 0, max = 2, err = 0, illegal = 0},
                {avail = 10, used = 0, max = 7, err = 0, illegal = 0}}
sys = {sem = {used = 2, max = 5, err = 0}
mutex = {used = 0, max = 0, err = 0}
mbox = {used = 3, max = 6, err = 9}
Reply | Threaded
Open this post in threaded view
|

Re: HardFault with lwip

Andrea Toscan
Hello,
I had a similar problem that has been solved by setting
SYS_LIGHTWEIGHT_PRO to 1 that enable a inter-task protection.
Regards.

A.

On 04/14/2016 12:44 PM, [hidden email] wrote:

> Hello,
> I'm using the lwip stack in combination with FreeRTOS for a http server and
> modbus TCP.
> The modbus TCP part makes no Problems.
> But after some page hits the lwip stack crashes with a HardFault.
> The crashes happens in the tcp_output and tcp_input function.
> The HardFault comes from a unaligned memory access.
> I tested different lwipopts.h and nothing helped. Using the
> MEMP_OVERFLOW_CHECK make it worse.
> Noticeable are the mbox errors.
> If the MEMP_OVERFLOW_CHECK isn't setI get some errors at the memp[6] but the
> HardFault comes approximately ten times later.
> Where can the problem come from?
> What are god ways to find such a fault?
> Here are my lwip_stats:
> link = {xmit = 0, recv = 0, fw = 0, drop = 0, chkerr = 0, lenerr = 0, memerr
> = 0, rterr = 0, proterr = 0, opterr = 0, err = 0, cachehit = 0}
> etharp = {xmit = 1, recv = 37, fw = 0, drop = 48, chkerr = 0, lenerr = 0,
> memerr = 0, rterr = 0, proterr = 48, opterr = 0, err = 0, cachehit = 13515}
> ip = {xmit = 13515, recv = 25585, fw = 0, drop = 0, chkerr = 0, lenerr = 0,
> memerr = 0, rterr = 0, proterr = 0, opterr = 0, err = 0, cachehit = 0}
> icmp = {xmit = 0, recv = 0, fw = 0, drop = 0, chkerr = 0, lenerr = 0, memerr
> = 0, rterr = 0, proterr = 0, opterr = 0, err = 0, cachehit = 0}
> udp = {xmit = 0, recv = 8, fw = 0, drop = 0, chkerr = 0, lenerr = 0, memerr
> = 0, rterr = 0, proterr = 0, opterr = 0, err = 0, cachehit = 0}
> tcp = {xmit = 13050, recv = 25574, fw = 0, drop = 66, chkerr = 0, lenerr =
> 0, memerr = 0, rterr = 0, proterr = 66, opterr = 0, err = 0, cachehit = 0}
> mem = {avail = 20480, used = 184, max = 372, err = 0, illegal = 0}
> memp = {{avail = 4, used = 0, max = 0, err = 0, illegal = 0},
>                  {avail = 10, used = 0, max = 0, err = 0, illegal = 0},
>                  {avail = 40, used = 40, max = 40, err = 0, illegal = 0},
>                  {avail = 30, used = 2, max = 2, err = 0, illegal = 0},
>                  {avail = 34, used = 2, max = 4, err = 0, illegal = 0},
>                  {avail = 2, used = 0, max = 1, err = 0, illegal = 0},
>                  {avail = 4, used = 1, max = 4, err = 0, illegal = 0},
>                  {avail = 8, used = 0, max = 0, err = 0, illegal = 0},
>                  {avail = 8, used = 0, max = 7, err = 0, illegal = 0},
>                  {avail = 20, used = 4, max = 4, err = 0, illegal = 0},
>                  {avail = 200, used = 0, max = 2, err = 0, illegal = 0},
>                  {avail = 10, used = 0, max = 7, err = 0, illegal = 0}}
> sys = {sem = {used = 2, max = 5, err = 0}
> mutex = {used = 0, max = 0, err = 0}
> mbox = {used = 3, max = 6, err = 9}
>
>
>
> --
> View this message in context: http://lwip.100.n7.nabble.com/HardFault-with-lwip-tp26174.html
> Sent from the lwip-users mailing list archive at Nabble.com.
>
> _______________________________________________
> lwip-users mailing list
> [hidden email]
> https://lists.nongnu.org/mailman/listinfo/lwip-users

--
Ing. Andrea Toscan, Project Leader
Bluewind Embedded System Design


e-mail: [hidden email]
skype: andrea.toscan.bluewind
it.linkedin.com/in/andreatoscan


Address:
via Della Borsa, 16/A int.5
31033 Castelfranco Veneto
Treviso - Italy

www.bluewind.it



_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: HardFault with lwip

Sergio R. Caprile
In reply to this post by twagner
I guess by "HardFault" that you are running some port for some ARM
processor.
You should be able to follow the HardFault and determine where the fault
is, and report that to the one who did the port. Your processor
exception mechanism is well documented.
I guess you are running a Cortex-M, where a HardFault is an escalation
of a specific fault, which you could enable and have a clearer
understanding of what is going on.
FreeRTOS has tutorials on this
http://www.freertos.org/Debugging-Hard-Faults-On-Cortex-M-Microcontrollers.html

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: HardFault with lwip

twagner
The HardFault happens in the function tcp_output at the line
"if (TCP_SEQ_LT(ntohl(seg->tcphdr->seqno), ntohl(useg->tcphdr->seqno))) {"
after 10 - 20 minuts.
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.
The SYS_LIGHTWEIGHT_PRO was set and it is a Coretex-M7 (stm32f745).
Increasing the mbox buffer size prevent the mbox errors in the lwip_stats but this time i had 60 errors at the memp[6].

Here my disassembly:
1010              if (TCP_SEQ_LT(ntohl(seg->tcphdr->seqno), ntohl(useg->tcphdr->seqno))) {
0800d4fc:   ldr r3, [r4, #12]
0800d4fe:   ldr r0, [r3, #4]
0800d500:   bl 0x80097d4 <lwip_ntohl>
0800d504:   mov r6, r0
0800d506:   ldr.w r3, [r8, #12]
0800d50a:   ldr r0, [r3, #4]
0800d50c:   bl 0x80097d4 <lwip_ntohl>
0800d510:   subs r0, r6, r0
0800d512:   cmp r0, #0
0800d514:   bge.n 0x800d546 <tcp_output+526>
1012                struct tcp_seg **cur_seg = &(pcb->unacked);
Reply | Threaded
Open this post in threaded view
|

Re: HardFault with lwip

goldsimon@gmx.de
twagner wrote:
> The HardFault happens in the function tcp_output at the line
> "if (TCP_SEQ_LT(ntohl(seg->tcphdr->seqno), ntohl(useg->tcphdr->seqno))) {"
> after 10 - 20 minuts.
> [..]

I could suggest, you probably did not obey lwIP's threading/multitasking requirements, but most obviously, you already read that while reading the list archives to see what the problem is... ;-)


Simon

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: HardFault with lwip

twagner
I solved the problem.
The problem was in the API of the Modbus TCP thread.