lpcware

BUG in LPCOpen lpc18xx_43xx_emac.c

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by brownm on Sat Jul 11 04:23:46 MST 2015
You may already know this - However I post it again for completeness.

I was trying to get my Phy running with the 4337 LPCOpen and LWIP (TCPEcho)

in the file lpc18xx_43xx_emac.c there is a function low_level_init()  this calls lpc_phy_init()

If lpc_phy_init() returns with an error (because the phy address is wrong in my case) then low_level_init() returns this error code to the caller. This is incorrect. ERROR in lpc_phy_init() enums to 0,  ERR_OK also returns 0, to the caller.


The valid return values for this function are (perhaps some advice on the best ERR to return would be useful.


/* Definitions for error constants. */

#define ERR_OK          0    /* No error, everything OK. */
#define ERR_MEM        -1    /* Out of memory error.     */
#define ERR_BUF        -2    /* Buffer error.            */
#define ERR_TIMEOUT    -3    /* Timeout.                 */
#define ERR_RTE        -4    /* Routing problem.         */
#define ERR_INPROGRESS -5    /* Operation in progress    */
#define ERR_VAL        -6    /* Illegal value.           */
#define ERR_WOULDBLOCK -7    /* Operation would block.   */
#define ERR_USE        -8    /* Address in use.          */
#define ERR_ISCONN     -9    /* Already connected.       */

#define ERR_IS_FATAL(e) ((e) < ERR_ISCONN)

#define ERR_ABRT       -10   /* Connection aborted.      */
#define ERR_RST        -11   /* Connection reset.        */
#define ERR_CLSD       -12   /* Connection closed.       */
#define ERR_CONN       -13   /* Not connected.           */

#define ERR_ARG        -14   /* Illegal argument.        */

#define ERR_IF         -15   /* Low-level netif error    */








/* Low level init of the MAC and PHY */
static err_t low_level_init(struct netif *netif)
{
struct lpc_enetdata *lpc_netifdata = netif->state;

/* Initialize via Chip ENET function */
Chip_ENET_Init(LPC_ETHERNET, BOARD_ENET_PHY_ADDR);

/* Save MAC address */
Chip_ENET_SetADDR(LPC_ETHERNET, netif->hwaddr);

/* Initial MAC configuration for checksum offload, full duplex,
   100Mbps, disable receive own in half duplex, inter-frame gap
   of 64-bits */
LPC_ETHERNET->MAC_CONFIG = MAC_CFG_BL(0) | MAC_CFG_IPC | MAC_CFG_DM |
   MAC_CFG_DO | MAC_CFG_FES | MAC_CFG_PS | MAC_CFG_IFG(3);

/* Setup filter */
#if IP_SOF_BROADCAST_RECV
LPC_ETHERNET->MAC_FRAME_FILTER = MAC_FF_PR | MAC_FF_RA;
#else
LPC_ETHERNET->MAC_FRAME_FILTER = 0;/* Only matching MAC address */
#endif

/* Initialize the PHY */
#if defined(USE_RMII)
if (lpc_phy_init(true, msDelay) != SUCCESS) {
return ERROR;                 <-----------------------------------!!!!!!!!!!!!!!!! - Incorrect - !!!!!!!!!!!!!!!!!!!!!!!!
}

intMask = RDES_CE | RDES_DE | RDES_RE | RDES_RWT | RDES_LC | RDES_OE |
  RDES_SAF | RDES_AFM;
#else
if (lpc_phy_init(false, msDelay) != SUCCESS) {
return ERROR;                 <-----------------------------------!!!!!!!!!!!!!!!! - Incorrect - !!!!!!!!!!!!!!!!!!!!!!!!
}

intMask = RDES_CE | RDES_RE | RDES_RWT | RDES_LC | RDES_OE | RDES_SAF |
  RDES_AFM;
#endif

/* Setup transmit and receive descriptors */
if (lpc_tx_setup(lpc_netifdata) != ERR_OK) {
return ERR_BUF;
}
if (lpc_rx_setup(lpc_netifdata) != ERR_OK) {
return ERR_BUF;
}





Let me know if you need more information, I haven't changed my code, I fixed the error that caused this, It took ages as the error was not caught!

Regards

Marshall


Outcomes