LwIP tcp_output Pcb Corruption

本文讨论了lwIP在STM32F107VC上使用TCP_output时遇到的PCB腐败问题。当主循环和中断同时操作lwIP堆栈时出现问题,表现为所有->next指针指向同一地址。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

http://lwip.100.n7.nabble.com/LwIP-tcp-output-Pcb-Corruption-td21239.html

LwIP tcp_output Pcb Corruption

classicClassiclistListthreadedThreaded
5 messages  Options  Options 
Reply |  Threaded |  More 
Selected post Mar 22, 2013; 3:17am

LwIP tcp_output Pcb Corruption

mary_west
3 posts

Hi -

 

I'm having an lwip problem in tcp_output.  It hangs in the following ‘for’ loop.

 

/* useg should point to last segment on unacked queue */

  useg = pcb->unacked;

  if (useg != NULL) {

    for (; useg->next != NULL; useg = useg->next);  <------- here

  }

 

  Here's the background:

  - processor: STM32F107vc

  - lwip 1.4.0

  - NO_SYS = 1

  - using raw API

  - ethernet set up on an interrupt using DMA

  - ethernet driver is pulled from an STM32F107 Lwip application note and example code

 

  The stm32 board sits between a device and a PC.  It receives CAN messages from

  the device and sends them to the PC as tcp messages.  When the problem occurs,

  the pcb is corrupted.  All ->nexts point to the same address. 

  I've read in the archive that this is due to the main and

  interrupts using the lwip stack at the same time.  The main loop runs the tcp timers.

  The interrupt calls ethernetif_input.

 

  On the send side (where it fails), the main checks a CAN queue and if there are

  messages, builds a tcpip msg and calls tcp_write followed by tcp_output. 

  

  The tcpip traffic going to the PC consists of MANY small packets.  I have disabled the

  Nagle algorithm.

 

  I read this in the archive as part of an answer to a question about a similar input problem:

  "When running without an OS, you have to put new packets on a linked list that is processed

  periodically from main() (just like the timers)."  Is this true for outgoing tcp packets?

  What are the safeguards for protecting the pcb from corruption?  Any help would be appreciated.

 

  Thanks-

  Mary

  


_______________________________________________ 
lwip-users mailing list 
[hidden email] 
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply |  Threaded |  More 
Mar 22, 2013; 3:23am

Re: LwIP tcp_output Pcb Corruption

Simon Goldschmidt
2729 posts
  [hidden email] wrote:


  I read this in the archive as part of an answer to a question about a similar input problem:

  "When running without an OS, you have to put new packets on a linked list that is processed

  periodically from main() (just like the timers)."  Is this true for outgoing tcp packets?


No, it means don't call ethernet_input from the interrupt but from the main loop, too.

Simon

_______________________________________________ 
lwip-users mailing list 
[hidden email] 
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply |  Threaded |  More 
Mar 22, 2013; 4:16am

Re: LwIP tcp_output Pcb Corruption

mary_west
3 posts

Hi –

 

Thanks for the response.   Do I get rid of ETH_IRQHandler altogether?  It checks for input, calls ethernetif_input which calls low_level_input and ethernet_input (setup in netif_add) then clears the ETH_DMAs.  Do I move this all to the main loop?

 

Thanks in advance-

Mary

 

From: lwip-users-bounces+mary_west=[hidden email] [mailto:lwip-users-bounces+mary_west=[hidden email]On Behalf Of Simon Goldschmidt
Sent: Thursday, March 21, 2013 12:24 PM
To: Mailing list for lwIP users
Subject: Re: [lwip-users] LwIP tcp_output Pcb Corruption

 

 [hidden email] wrote:

 

  I read this in the archive as part of an answer to a question about a similar input problem:

  "When running without an OS, you have to put new packets on a linked list that is processed

  periodically from main() (just like the timers)."  Is this true for outgoing tcp packets?

 

No, it means don't call ethernet_input from the interrupt but from the main loop, too.

 

Simon


_______________________________________________ 
lwip-users mailing list 
[hidden email] 
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply |  Threaded |  More 
Mar 22, 2013; 5:56am

Re: LwIP tcp_output Pcb Corruption

mary_west
3 posts
In reply to  this post by Simon Goldschmidt

Ok – nevermind last email.  I need the ETH IRQ handler.  In there, I load an application list (not an LwIP pbuf) with the received ETH packet and clear the ETHDMA bits to get the next interrupt.  In main, I get the packet out of the list and call ethernet_input to have LwIP handle it.  Is this how it should be done to avoid problems in tcp_output?

 

Thanks-

Mary

 

From: lwip-users-bounces+mary_west=[hidden email] [mailto:lwip-users-bounces+mary_west=[hidden email]On Behalf Of Simon Goldschmidt
Sent: Thursday, March 21, 2013 12:24 PM
To: Mailing list for lwIP users
Subject: Re: [lwip-users] LwIP tcp_output Pcb Corruption

 

 [hidden email] wrote:

 

  I read this in the archive as part of an answer to a question about a similar input problem:

  "When running without an OS, you have to put new packets on a linked list that is processed

  periodically from main() (just like the timers)."  Is this true for outgoing tcp packets?

 

No, it means don't call ethernet_input from the interrupt but from the main loop, too.

 

Simon


_______________________________________________ 
lwip-users mailing list 
[hidden email] 
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply |  Threaded |  More 
Mar 22, 2013; 2:54pm

Re: LwIP tcp_output Pcb Corruption

Simon Goldschmidt
2729 posts
[hidden email] wrote: 
> Ok – nevermind last email.  I need the ETH IRQ handler.  In there, I load an 
> application list (not an LwIP pbuf) with the received ETH packet and clear the 
> ETHDMA bits to get the next interrupt.  In main, I get the packet out of the 
> list and call ethernet_input to have LwIP handle it.  Is this how it should be 
> done to avoid problems in tcp_output? 

Yes. This is one way to do it. You are essentially free to chose any way that makes sure the core lwIP code (except for allocating/freeing PBUF_POOL pbufs and other memp-memory) is not exposed to concurrent execution (i.e. executed from main and ISR at the same time). 

Simon 

_______________________________________________ 
lwip-users mailing list 
[hidden email] 
https://lists.nongnu.org/mailman/listinfo/lwip-users
«  Return to lwip-users  |   371 views
Free forum by NabbleDisable Popup Ads | Edit this page
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值