My fix in ChibiOS to make LWIP work

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderators: RoccoMarco, barthess

Laurent
Posts: 35
Joined: Mon Mar 25, 2013 9:01 am

My fix in ChibiOS to make LWIP work

Postby Laurent » Fri Jan 05, 2018 11:48 am

Hi

I was testing LWIP with ChibiOS (latest, 17.6.3) on a STM32F107 (Olimex STM32-P107 board, rev. B), and noticed that it didn't work quite well (couldn't ping the IP). After some random trials, I found that I needed to insert a delay right after the call to macStart (in lwipthread.c). After further investigation I came with the following fix at the beginning of the lwip_thread function:

Code: Select all

  ...
  macStart(&ETHD1, &mac_config);

  /* begin fix */
  while (!ETHD1.link_up)
  {
      macPollLinkStatus(&ETHD1);
      chThdSleepMilliseconds(100);
  }
  /* end fix */

  netif_add(&thisif, &ip, &netmask, &gateway, NULL, ethernetif_init, tcpip_input);
  ...


It takes approximately 1.9 seconds to complete, which matches the delay I was using previously, and after that LWIP works perfectly.

The only problem is that I don't really understand what's going on, and I don't even know if this is really a fix. Can someone who understands LWIP and the ETH driver help me figure out a clean solution (or explain what happens, in case I already have the proper one)?

Thanks

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: My fix in ChibiOS to make LWIP work

Postby Giovanni » Fri Jan 05, 2018 12:15 pm

Hi,

Could you give a try to the new lwIP in trunk code?

Giovanni

Laurent
Posts: 35
Joined: Mon Mar 25, 2013 9:01 am

Re: My fix in ChibiOS to make LWIP work

Postby Laurent » Fri Jan 05, 2018 1:18 pm

Thanks for your quick reply.

The current trunk seems to solve this particular problem, although it brings a new one: LWIP breaks on an assert as soon as a second TCP connection is made (the very first one works flawlessly apparently the first connection appears to break sometimes when receiving data).

Message:

Code: Select all

pbuf_free: p->ref > 0

Call stack:

Code: Select all

chSysHalt() at chsys.c:206 0x8013030   
osalSysHalt.lto_priv.130() at osal.h:480 0x800ed0c   
pbuf_free() at pbuf.c:747 0x800d4f8   
prvxMBTCPPortReceive() at porttcp.c:290 0x8001334   
tcp_process_refused_data() at tcp.c:1 331 0x800cc6a   
tcp_fasttmr() at tcp.c:1 283 0x800cc04   
tcp_tmr() at tcp.c:159 0x800db96   
tcpip_tcp_timer() at timeouts.c:130 0x8007e9a   
sys_check_timeouts() at timeouts.c:351 0x80081de   
sys_timeouts_mbox_fetch() at timeouts.c:419 0x800828e   
tcpip_thread.lto_priv.44() at tcpip.c:101 0x8002e64   
_port_thread_start() at chcoreasm_v7m.S:119 0x8000256   

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: My fix in ChibiOS to make LWIP work

Postby Giovanni » Fri Jan 05, 2018 2:07 pm

The question is: is this caused by our interface layer or lwIP itself? I don't know how to approach this problem.

Giovanni

Laurent
Posts: 35
Joined: Mon Mar 25, 2013 9:01 am

Re: My fix in ChibiOS to make LWIP work

Postby Laurent » Fri Jan 05, 2018 3:03 pm

Nevermind, after investigating more I found that it was caused by another library that we use on top of LWIP.


Return to “STM32 Support”

Who is online

Users browsing this forum: No registered users and 39 guests