LPC1766 LPCOpen lwIP EMAC driver bug locks up RX

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LPC1766 LPCOpen lwIP EMAC driver bug locks up RX

1,221 Views
craigmcqueenir
Contributor IV

I'm using lwIP 2.1.2 on an LPC1766. I adapted the lwIP EMAC driver code from lpcopen_2_10_keil_iar_nxp_lpcxpresso_1769.

I've been having an issue where sometimes the Ethernet RX locks up — the processor's Ethernet MAC just stops receiving any packets, even though everything still appears to be configured normally in the MAC registers.

I tracked down the bug to the lwIP driver file lpc17xx_40xx_emac.c, function lpc_low_level_input(). The problem is the line:

            p->len = (u16_t) length;

If the following if statement triggers (that is, if it is unable to allocate a new pbuf to replace the one just being taken for this received packet, due to low memory):

            if (lpc_rx_queue(lpc_enetif->pnetif) == 0) {

then it re-queues the current pbuf:

                lpc_rxqueue_pbuf(lpc_enetif, p);

However, because of the previous line that sets p->len to the length of this received packet, the pbuf now has a shorter length (the length of the packet just received), rather than its original length of ENET_ETH_MAX_FLEN. This means this pbuf is now unable to receive longer packets.

Once that bug happens a few times while receiving short packets, RX is effectively crippled in its ability to receive longer packets, and Ethernet RX effectively halts.

The fix is to move the line

            p->len = (u16_t) length;

to be just below the comment:

            /* Save size */

ie where it also sets p->tot_len to the length.

Labels (1)
0 Kudos
5 Replies

1,145 Views
Alexis_A
NXP TechSupport
NXP TechSupport

Hello Craig,

Thanks a lot for your contributions. 

Best Regards,

Alexis Andalon

0 Kudos

1,145 Views
craigmcqueenir
Contributor IV

Will the LPCOpen downloads be updated with a fix?

0 Kudos

1,145 Views
Alexis_A
NXP TechSupport
NXP TechSupport

Unfortunately, there is no news about further releases for LPCOpen so any comments and fixes about it are very appreciated.

Best Regards,

Alexis Andalon

0 Kudos

957 Views
craigmcqueenir
Contributor IV

I'm surprised to hear this. It is very much in NXP's best interests to respond to user-submitted bug reports, and to fix known bugs promptly. By doing so, NXP will improve its reputation as a company that produces robust products.

It would be great if you could contact the people in NXP responsible for doing LPCOpen, and notify them of this bug report.

0 Kudos

1,145 Views
craigmcqueenir
Contributor IV
diff --git a/lpcopen_2_10_keil_iar_nxp_lpcxpresso_1769.old/software/lwip/lpclwip/arch/lpc17xx_40xx_emac.c b/lpcopen_2_10_keil_iar_nxp_lpcxpresso_1769/software/lwip/lpclwip/arch/lpc17xx_40xx_emac.c
index 09b39c2..892b389 100644
--- a/lpcopen_2_10_keil_iar_nxp_lpcxpresso_1769.old/software/lwip/lpclwip/arch/lpc17xx_40xx_emac.c
+++ b/lpcopen_2_10_keil_iar_nxp_lpcxpresso_1769/software/lwip/lpclwip/arch/lpc17xx_40xx_emac.c
@@ -275,7 +275,6 @@ STATIC struct pbuf *lpc_low_level_input(struct netif *netif) {
 
    /* Zero-copy */
    p = lpc_enetif->rxb[idx];
-   p->len = (u16_t) length;
 
    /* Free pbuf from desriptor */
    lpc_enetif->rxb[idx] = NULL;
@@ -302,6 +301,7 @@ STATIC struct pbuf *lpc_low_level_input(struct netif *netif) {
         p, length, idx));
 
     /* Save size */
+    p->len = (u16_t) length;
     p->tot_len = (u16_t) length;
     LINK_STATS_INC(link.recv);
    }
Tags (1)