• Join
  • Sign In with my.TI Login
Texas Instruments
  • Products
  • Applications
  • Tools & Software
  • Support & Community
  • Sample & Buy
  • About TI
Sample & Purchase Cart Sample & Purchase Cart
  • Search
  • Advanced
TI E2E™ Community
  • Support Forums
  • Blogs
  • Groups
  • Videos
  • 简体中文
  • More ...
TI Home » TI E2E Community » Support Forums » Embedded Software » StarterWare » StarterWare forum » lwIP UDP problem in 2.00.00.05 on the BeagleBone.
Share
StarterWare
  • Forum
Options
  • Subscribe via RSS

Forums

lwIP UDP problem in 2.00.00.05 on the BeagleBone.

This question is answered
Jay Larson
Posted by Jay Larson
on Mar 14 2012 12:41 PM
Prodigy220 points

Hi,

I'm having problems with iwIP as supplied in StarterWare 2.00.00.05 for the AM335x and targeted to the BeagleBone. 

 

I made a very simple change to the example program "enetEcho" to add a periodic broadcast of a UDP packet every 1/2 second. 

Here is the code segment with what I added: (in bold)

   

..... SNIP ......

    /* Initialize the sample httpd server. */
    echo_init();

    struct udp_pcb* pcb = udp_new();
    struct pbuf *p;
    udp_bind(pcb, IP_ADDR_ANY, 1235);
    char msg[80];
    int packet = 0;

    /* Loop forever.  All the work is done in interrupt handlers. */
    while(1)
    {

     packet++;
     p = pbuf_alloc(PBUF_TRANSPORT, sizeof(msg), PBUF_RAM);    // allocate a pbuf, (ref=1)
     if (!p || 1!=p->ref)
     {
      UARTPuts("pbuf_alloc failed!\n", -1);
      while (1) ;
     }
     sprintf(msg, "test packet %d", packet);
     memcpy(p->payload, msg, strlen(msg));
     UARTprintf("packet %d, PBuf at 0x%08X, ref = %d sending...", packet, p, p->ref);
     udp_sendto(pcb, p, IP_ADDR_BROADCAST, 1234);
     delay(500); // half second delay - should have plenty of time to send
     UARTprintf("ref is now %d \n", p->ref);
     pbuf_free(p); // ref should be zero after we free.
    }
}

   

This works great for about 30 packets or so.  Then suddenly they stop being sent.  Below is a typical output:

 

StarterWare AM335x Boot Loader
Copying application image from MMC/SD card to RAM
Acquiring IP Adress...
EVM IP Address Assigned: 192.168.9.106packet 1, PBuf at 0x80018060, ref = 1 sending...ref is now 1
packet 2, PBuf at 0x80018060, ref = 1 sending...ref is now 1
packet 3, PBuf at 0x80018060, ref = 1 sending...ref is now 1
.... and so on....

packet 21, PBuf at 0x80018060, ref = 1 sending...ref is now 1
packet 22, PBuf at 0x80018060, ref = 1 sending...ref is now 1
packet 23, PBuf at 0x80018060, ref = 1 sending...ref is now 1
packet 24, PBuf at 0x80018060, ref = 1 sending...ref is now 1
packet 25, PBuf at 0x80018060, ref = 1 sending...ref is now 1
packet 26, PBuf at 0x80018060, ref = 1 sending...ref is now 1
packet 27, PBuf at 0x80018060, ref = 1 sending...ref is now 1
packet 28, PBuf at 0x80018060, ref = 1 sending...ref is now 1
packet 29, PBuf at 0x80018060, ref = 1 sending...ref is now 1
packet 30, PBuf at 0x80018060, ref = 1 sending...ref is now 1
packet 31, PBuf at 0x80018060, ref = 1 sending...ref is now 1
packet 32, PBuf at 0x80018060, ref = 1 sending...ref is now 1
packet 33, PBuf at 0x80018060, ref = 1 sending...ref is now 2
packet 34, PBuf at 0x80018100, ref = 1 sending...ref is now 2
packet 35, PBuf at 0x800181a0, ref = 1 sending...ref is now 2
packet 36, PBuf at 0x80018240, ref = 1 sending...ref is now 2

I can monitor the packets on the wire, and in this case, the last one sent was number 32.  This is consistient with the reference count not being decremented on packet 33. Sometimes it will make it to 50 packets before the stack dies, but never much longer. 

Further investigation revealed that the interrupt handler that should be called after transmission stops being called after so many packets... But why?  Any Ideas would be very welcome!  I hope I haven't made some silly assumption on the use of lwIP under StarterWare.

Cheers,

-Jay

StarterWare beaglebone LwIP am3359
Report Abuse
  • Reply
You have posted to a forum that requires a moderator to approve posts before they are publicly available.
All Replies
  • Sujith KV
    Posted by Sujith KV
    on Apr 13 2012 06:11 AM
    Verified Answer
    Verified by Jay Larson
    Intellectual2505 points

    Hi Jay,

    At last it worked for me with a small change in tx buffer descriptor configuration !

    In /third_party/lwip-1.3.2/ports/am335x/netif/sitaraif.c,  define a macro,

     #define CPDMA_BUF_DESC_TO_PORT(port)     ((port << 16) | 0x100000)

    and in sitaraif_transmit() function, replace  the line

         curr_bd->flags_pktlen |= ((CPDMA_BUF_DESC_SOP | CPDMA_BUF_DESC_OWNER)

    with

          curr_bd->flags_pktlen |= ((CPDMA_BUF_DESC_SOP | CPDMA_BUF_DESC_OWNER) |CPDMA_BUF_DESC_TO_PORT(1));

    Could you please verify this ? (The additional flag indicates to which port it has to send, But it is not mandatory. And EVM works without this change !)

     We will include the above changes in next StarterWare release.

    Regards,

    Sujith.

     

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Jay Larson
    Posted by Jay Larson
    on Apr 13 2012 07:32 AM
    Prodigy220 points

    Hello Sujith,

    That fixes the problem for me too!  Many Many thanks!!

    It is very strange that the problem doesn't come up with the EVM.  Could that be because the unused interface is differently terminated on the beaglebone? 

    Cheers,

    -Jay

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Sujith KV
    Posted by Sujith KV
    on Apr 16 2012 00:47 AM
    Intellectual2505 points

    Hi Jay,

    May be. We can also try the experiment by removing all the configuration for the unused port in sitaraif.c.

    Cheers,

    Sujith.

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Jay Larson
    Posted by Jay Larson
    on Apr 16 2012 02:17 AM
    Prodigy220 points

    Hi Sujith,

    I've been reviewing the code in sitaraif.c.  It looks like the flags in the buffer descriptor are uninitialized at the point of use at the beginning of sitarif_transmit.

    Would it not be more defensive to initilize the entire flags_pktlen word to zero rather than just clearing the least significant 16 bits?  That is, change:

      curr_bd->flags_pktlen &= ~0xFFFF;
      curr_bd->flags_pktlen |= pbuf->tot_len;

    to:

      curr_bd->flags_pktlen = 0;
      curr_bd->flags_pktlen |= pbuf->tot_len;

    or perhaps better:

      curr_bd->flags_pktlen = 0x3FF & pbuf->tot_len;  // clear flags and set 10 bit total length

    I do see that the flags are cleared when the descriptors are inititially created, but I think that it is generally better to initialize things at the point of use rather than rely on them being already initialized.

     

    Also, would it be good to use the actual port number used (To_Port) in the buffer descripter flags rather than the a #define constant?  sitaraif_transmit is passed a pointer to the sitaraif structure so we know what port it should be goint to using its port field, so we would use:

      curr_bd->flags_pktlen |= ((CPDMA_BUF_DESC_SOP | CPDMA_BUF_DESC_OWNER) | CPDMA_BUF_DESC_TO_PORT(sitarif->port));

    instead of:

      curr_bd->flags_pktlen |= ((CPDMA_BUF_DESC_SOP | CPDMA_BUF_DESC_OWNER) | CPDMA_BUF_DESC_TO_PORT(1));

    Just some thoughts.  I'm just happy it is now working well!  I had it run over the weekend and it still going.  So I'm sure you squashed that bug.

     

    Cheers,

    -Jay

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Sujith KV
    Posted by Sujith KV
    on Apr 16 2012 04:30 AM
    Intellectual2505 points

    Hi Jay,

    Thank you very much for your valuable inputs.

    [Jay :Would it not be more defensive to initilize the entire flags_pktlen word to zero rather than just clearing the least significant 16 bits?  That is, change:]

    You are correct. its better if we give curr_bd->flags_pktlen = 0.

    [Jay: Also, would it be good to use the actual port number used (To_Port) in the buffer descripter flags rather than the a #define constant?  sitaraif_transmit is passed a pointer to the sitaraif structure so we know what port it should be goint to using its port field, so we would use:]

    Yes, we have to give sitaraif->port as you explained. I wanted to verify if that works. Anyway, this shall be properly given in the next release.

    Cheers,

    Sujith.

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Ramesh Nair
    Posted by Ramesh Nair
    on Jul 06 2012 01:36 AM
    Prodigy135 points

    Trying to run starterware 2.0.0.6 with Beaglebone. On console i get "Acquiring IP address " and seems to be hanging there.

    Using wireless router as dhcp server for providing IP address to the board.

     

    Need some help here.

     

     

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Vinesh Balan2
    Posted by Vinesh Balan2
    on Jul 13 2012 10:36 AM
    Prodigy10 points

    Hi Sujith, 

    This fix has helped us also(for IDK). The application was crashing consistently while using a particular feature of EthernetIP Protocol. On debugging, it pointed out to the rx_handler where curr_bd->next was a null pointer. Incorporating

    curr_bd->flags_pktlen |= ((CPDMA_BUF_DESC_SOP | CPDMA_BUF_DESC_OWNER) |CPDMA_BUF_DESC_TO_PORT(1)); 

    the above change has helped in solving this issue.

    Also, we have used lwip v1.4.0, and an interesting bug came up(in SYS/Bios). v1.4.0, unlike v1.3.2 uses mutexes to manage the mem_alloc(in mem.c). As we are processing rx in the context of interrupts, these gate mutexes are being called from the ISR, leading to a crash.

    Thanks once again!

    Regards,
    Vinesh 

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
12
TI E2E™ Community
  • Support Forums
  • Blogs
  • Videos
  • Groups
  • Site Support & Feedback
  • Settings
TI E2E™ Community Groups
  • TI University Program
  • Make the Switch
  • Microcontroller Projects
  • Motor Drive & Control
Other Communities
  • Deyisupport
  • Designsomething.org
  • beagleboard.org
  • TI on Element 14
  • TI on TechXchangeSM
Other Technical & Support Resources
  • WEBENCH® Design Center
  • Product Information Centers
  • Technical Documents
  • TI Design Network
  • TI Technical Articles
  • TI Training

All content and materials on this site are provided "as is". TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with regard to these materials, including but not limited to all implied warranties and conditions of merchantability, fitness for a particular purpose, title and non-infringement of any third party intellectual property right. TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with respect to these materials. No license, either express or implied, by estoppel or otherwise, is granted by TI. Use of the information on this site may require a license from a third party, or a license from TI.

Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms of Use of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms of Use of this site. TI, its suppliers and providers of content reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.

Follow Us Texas Instruments on Facebook Texas Instruments on Twitter Texas Instruments on LinkedIn Texas Instruments on Google+
TI Worldwide | Contact Us | my.TI Login | Site Map | Corporate Citizenship | mobile m.ti.com (Mobile Version)

TI is a global semiconductor design and manufacturing company. Innovate with 100,000+ analog ICs and
embedded processors, along with software, tools and the industry’s largest sales/support staff.

© Copyright 1995-2013 Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy Policy | Terms of Use