From 4934323931f3833a0f927d0e398ba548f97e18c8 Mon Sep 17 00:00:00 2001 From: Frank Li Date: Fri, 24 Aug 2018 22:55:19 +0800 Subject: [PATCH] drivers: eth: enc28j60: Fix read error when ERDPT < ERXRDPT After read first packet and if ERDPT < ERXRDPT,cause read Rx FIFO error. The fix is to set ERDPT properly before reading next packet. Fixed #9537 Signed-off-by: Frank Li --- drivers/ethernet/eth_enc28j60.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/ethernet/eth_enc28j60.c b/drivers/ethernet/eth_enc28j60.c index 8da1357ed12fc7..43f606682ae14c 100644 --- a/drivers/ethernet/eth_enc28j60.c +++ b/drivers/ethernet/eth_enc28j60.c @@ -520,6 +520,15 @@ static int eth_enc28j60_rx(struct device *dev) u8_t info[RSV_SIZE]; struct net_pkt *pkt; u16_t next_packet; + u8_t rdptl = 0; + u8_t rdpth = 0; + + /* remove read fifo address to packet header address */ + eth_enc28j60_set_bank(dev, ENC28J60_REG_ERXRDPTL); + eth_enc28j60_read_reg(dev, ENC28J60_REG_ERXRDPTL, &rdptl); + eth_enc28j60_read_reg(dev, ENC28J60_REG_ERXRDPTH, &rdpth); + eth_enc28j60_write_reg(dev, ENC28J60_REG_ERDPTL, rdptl); + eth_enc28j60_write_reg(dev, ENC28J60_REG_ERDPTH, rdpth); /* Read address for next packet */ eth_enc28j60_read_mem(dev, info, 2); @@ -527,12 +536,12 @@ static int eth_enc28j60_rx(struct device *dev) /* Errata 14. Even values in ERXRDPT * may corrupt receive buffer. - */ + No need adjust next packet if (next_packet == 0) { next_packet = ENC28J60_RXEND; } else if (!(next_packet & 0x01)) { next_packet--; - } + }*/ /* Read reception status vector */ eth_enc28j60_read_mem(dev, info, 4);