lwip 1.4 - DM9161A PHY

After reading topic http://mbed.org/forum/mbed/topic/3684/?page=1#comment-18473, i created the lpc_phy_DM9161A.c file (used lpc_phy_lan8720.c as a template).

Partially working

Auto negotiation and DHCP are OK - ethernet communication is not working.

There seems to be a communication problem between the EMAC and PHY (timing?). Any ideas on how to resolve this issue are welcome.

A debug log is available at /media/uploads/frankvnk/tcpsocket_helloworld_with_dm9161a_phy_-_debug_log.txt. The log file indicates a pbuf problem. Further investigation led me to following webpage: http://www.lpcware.com/content/forum/lwip-sample-fail#comment-1785. I tried again with the mentioned modification but then DHCP does not work. I don't know if this modification also needs to be implemented (not present in the current lwip library).

How to test

import http://mbed.org/users/mbed_official/code/TCPSocket_HelloWorld/ into the mbed compiler.

Goto folder EthernetInterface\lwip-eth\arch#

Delete lpc_phy_dp83848.c.

Copy lpc_phy_DM9161A.c into this folder.

Add following MAC address definition in main.cpp (before 'EthernetInterface eth;').

       extern "C" void mbed_mac_address(char * mac)
       {
       // define your own MAC Address
         mac[0] = 0x00;  
         mac[1] = 0x1F;  
         mac[2] = 0x33;  
         mac[3] = 0x42;  
         mac[4] = 0xFC;  
         mac[5] = 0x6F;           
       };

When used with the Mini-DK hardware

Modify EthernetInterface\lwip-eth\arch\lpc_emac_config.h:

Change #define LPC_PHYDEF_PHYADDR 1 to #define LPC_PHYDEF_PHYADDR 19

On the Mini-DK, sometimes no IP address is obtained when the 'Reset' button is pressed after programming the device. Disconnect and reconnect the device and press the 'Reset' button again to restart.

Revision:
2:e8cdfd3c70f5
Parent:
0:6901daab33f0
diff -r 27e909464317 -r e8cdfd3c70f5 lpc_phy_DM9161A.c
--- a/lpc_phy_DM9161A.c	Tue Jan 29 12:47:58 2013 +0000
+++ b/lpc_phy_DM9161A.c	Mon Mar 18 17:42:16 2013 +0000
@@ -360,6 +360,28 @@
 
     lpc_mii_write(DM9161A_BMCR_REG, tmp);
 
+    /* Wait for autonegotiation completion */
+    i = 400;
+    while (i > 0)
+    {
+        osDelay(1);   // 1 ms
+        if (lpc_mii_read(DM9161A_BMSR_REG, &tmp) != 0)
+        {
+            printf("Timeout\n");
+            return ERR_TIMEOUT;
+        }
+        if (tmp & (DM9161A_AUTONEG_COMP))
+            i = -1;
+        else
+            i--;
+    }
+    // Timeout?
+    if (i == 0)
+    {
+        printf("Timeout\n");
+        return ERR_TIMEOUT;
+    }
+
     /* Enable RMII mode for PHY  - NOT NEEDED FOR MIDI-DK - RMII pin is lathed on reset*/
 /*    if (rmii)
         lpc_mii_write(DM9161A_DSCR_REG, DM9161A_RMII_ENABLE);