EMAC receive not working

User avatar
rudi ;-)
Posts: 1558
Joined: Fri Nov 13, 2015 3:25 pm

Re: EMAC receive not working

Postby rudi ;-) » Sat Feb 25, 2017 11:13 am

FYI
tlk_OUI_MSB.png
tlk_OUI_MSB.png (40.02 KiB) Viewed 7934 times
its only a test for the revision..hw..
not more :)
best wishes
rudi ;-)

edit:
( LAN8720 )
better to change and expand the esp_eth_smi_read function with second parameter
example:

Code: Select all


// void phy_tlk110_init_test(void){

void phy_lan8720_init_test(void){

unsigned int PhyAddr;
    union {
      uint32_t    HI_LO;
      struct
      {
        uint16_t  LO;
        uint16_t  HI;
      };
    } PHYID;

for(PhyAddr = 1; 32 >= PhyAddr; PhyAddr++)
  {
    // datasheet for the LAN8720A ethernet controller 
	// (http://www.smsc.com/media/Downloads_Public/Data_Sheets/8720a.pdf)
    // page 51-52 --> PHY Identifier Register 1 and 2
  
  // esp_eth_smi_read does not support second parameter
  // must be then changed.. here or in esp_eth_smi_read function
    PHYID.HI = esp_eth_smi_read(PhyAddr, 2);  // 0x0007
    PHYID.LO = esp_eth_smi_read(PhyAddr, 3);  // Mixed bits
  	if (0x0007 == PHYID.HI) break;
  }
   
  if(32 < PhyAddr)
  {
    //printf("Ethernet Phy Not Found\n\r");
    while (-1){
		ESP_LOGI(TAG, "hang here: [%d]:[%s]", __LINE__, __FILE__);
		printf("Ethernet Phy Not Found\n\r");
		vTaskDelay(5000 / portTICK_PERIOD_MS);		
    }
  }

    esp_eth_smi_write(SOFTWARE_STRAP_CONTROL_REG, DEFAULT_PHY_CONFIG |SW_STRAP_CONFIG_DONE);
    
    ets_delay_us(300);

    //if config.flow_ctrl_enable == true ,enable this 
    phy_enable_flow_ctrl();
  
}

smsc link does not work any more, take this:
https://web.archive.org/web/20130729021 ... /8720a.pdf
or here:
8720a.pdf
(1.02 MiB) Downloaded 236 times
-------------------------------------
love it, change it or leave it.
-------------------------------------
問候飛出去的朋友遍全球魯迪

www220
Posts: 34
Joined: Wed Dec 21, 2016 7:21 am

Re: EMAC receive not working

Postby www220 » Sun Feb 26, 2017 1:05 am

我的lan8720已经能获取ip,也可以ping通,esp32提供的demo中的phy不是8720所以对phy的操作,以及寄存器判定也需要做相应的修改

RobinC
Posts: 45
Joined: Sat Feb 04, 2017 5:29 pm

Re: EMAC receive not working

Postby RobinC » Sun Feb 26, 2017 1:16 am

I have the Microchip/SMSC LAN8720A eval board wired up to the stock ESP32 dev board. No hardware changes were needed to the phy board. I duplicated the TLK110 functions for the 8720 and customized to match. The esp-idf source uses phy address 31 so I changed it to 0 for the 8720. The ESP32 sees the phy and talks to it without issue. I turned lwip debug on and see the DHCP packets transmitting and get the tx done signal. I scoped the rx lines and see the response packets coming back but the ESP32 never indicates that it received anything.

I also have the TLK110CUSEVM and modified it for RMII by removing the 25MHz crystal, R71, and R72. I placed a zero ohm resistor on R73 and added a 50MHz oscillator. With this config (modified for stock phy address 1), I'm able to get the same transmitted packets and no received packets, just like the 8720. Clearly there is some magic setting or hardware config that we don't know about.

It would be nice to get a response from Espressif.

TLK110 setup:
IMG_0576.JPG
IMG_0576.JPG (2.4 MiB) Viewed 7910 times
LAN8720A setup:
IMG_0577.JPG
IMG_0577.JPG (1.73 MiB) Viewed 7910 times

RobinC
Posts: 45
Joined: Sat Feb 04, 2017 5:29 pm

Re: EMAC receive not working

Postby RobinC » Sun Feb 26, 2017 1:23 am

Hey www220, that is very good to hear. Could you list your ping connects between the ESP32 and the phy? Also, what modifications did you make to the ethernet example code?

Thanks

User avatar
rudi ;-)
Posts: 1558
Joined: Fri Nov 13, 2015 3:25 pm

Re: EMAC receive not working

Postby rudi ;-) » Sun Feb 26, 2017 1:41 am

Hi Robin,

LAN8720
with one word, the SMI works here now too, phy is found, check Manufacturer Data ( Register 3 )
phy_found.png
phy_found.png (18.35 KiB) Viewed 7908 times

but get no correct IP just in time.
now i start to protocoll the transfer between router and esp32 what happend.
and play with the AUTO / DHCP ect.

@www220
please, where is the demo ?
can you please post it?
we are two steps behind you :) , we have no IP get, how looks your LAN8720 header example? ;-)
what have you done for get the ip? ( DHCP ) or do you set this static ( How? )

btw:
restart, power on, power down, LED Check, Switch,
Register Check, Write, Read ok.
ESP32 talks over SMI with the PHY Adapter :)

ESP32-DEVKitC V2 with LAN8720

best wishes
rudi ;-)
-------------------------------------
love it, change it or leave it.
-------------------------------------
問候飛出去的朋友遍全球魯迪

User avatar
rudi ;-)
Posts: 1558
Joined: Fri Nov 13, 2015 3:25 pm

Re: EMAC receive not working

Postby rudi ;-) » Sun Feb 26, 2017 2:33 am

RobinC wrote: .. The esp-idf source uses phy address 31 so I changed it to 0 for the 8720.
hi robin
i have ordered the 150 EURO board too, but need a few days to arrival.
i use the LAN8720 Modul i get with express. i changed from 31 to PHY1 and phy is found,
on PHY0 there is no phy, can be, that the modul is fixed by resistor.
the SMI works fine. i missing few register must search on datasheet.
rudi ;-) wrote:
/* LAN8720 / tlk110 */
/* ?? */

/*ok */ #define BASIC_MODE_STATUS_REG (0x0) // (0x1)
/*ok */ #define AUTO_NEGOTIATION_COMPLETE BIT(5)
/*ok */ #define LINK_STATUS BIT(2)

/*ok */ #define PHY_IDENTIFIER_REG (0x2)
/*new*/ #define PHY_IDENTIFIER1_REG (0x2)
/*new*/ #define PHY_IDENTIFIER2_REG (0x3)

/*old*/ #define OUI_MSB_21TO6_DEF 0x2000
/*new*/ #define OUI_MSB_LAN8720_DEF 0x7

/*ok*/ #define AUTO_NEG_ADVERTISEMENT_REG (0x4)
/*??*/ #define ASM_DIR BIT(11)
/*??*/ #define PAUSE BIT(10)

/*ok*/ #define PHY_LINK_PARTNER_ABILITY_REG (0x5)
/*??*/ #define PARTNER_ASM_DIR BIT(11)
/*??*/ #define PARTNER_PAUSE BIT(10)



/*??*/ #define SOFTWARE_STRAP_CONTROL_REG (0x9)
/*??*/ #define SW_STRAP_CONFIG_DONE BIT(15)
/*??*/ #define AUTO_MDIX_ENABLE BIT(14)
/*??*/ #define AUTO_NEGOTIATION_ENABLE BIT(13)
/*??*/ #define AN_1 BIT(12)
/*??*/ #define AN_0 BIT(11)
/*??*/ #define LED_CFG BIT(10)
/*??*/ #define RMII_ENHANCED_MODE BIT(9)

/* LAN8720 / tlk110 */
/*ok*/ #define PHY_STATUS_REG (0x1) // (0x10)
/*??*/ #define AUTO_NEGOTIATION_STATUS BIT(4)
/*??*/ #define DUPLEX_STATUS BIT(2)
/*??*/ #define SPEED_STATUS BIT(1)


// ??
/*??*/ #define CABLE_DIAGNOSTIC_CONTROL_REG (0x1e)
/*??*/ #define DIAGNOSTIC_DONE BIT(1)



/* LAN8720 / tlk110 */
/*ok*/ #define PHY_RESET_CONTROL_REG 0x0 // (0x1f)
/*ok*/ #define SOFTWARE_RESET BIT(15)

RobinC wrote:
I turned lwip debug on and see the DHCP packets transmitting and get the tx done signal.
I scoped the rx lines and see the response packets coming back but the ESP32 never indicates that it received anything.
this are my next steps

RobinC wrote: I also have the TLK110CUSEVM and modified it for RMII by removing the 25MHz crystal, R71, and R72. I placed a zero ohm resistor on R73 and added a 50MHz oscillator. ...
Clearly there is some magic setting or hardware config that we don't know about.
thanks, will follow yours for the tlk110
RobinC wrote: It would be nice to get a response from Espressif.
+1

best wishes
rudi ;-)
Last edited by rudi ;-) on Sun Feb 26, 2017 3:45 am, edited 1 time in total.
-------------------------------------
love it, change it or leave it.
-------------------------------------
問候飛出去的朋友遍全球魯迪

RobinC
Posts: 45
Joined: Sat Feb 04, 2017 5:29 pm

Re: EMAC receive not working

Postby RobinC » Sun Feb 26, 2017 3:38 am

Success on the tlk110!!! I ran the CRS pin from the eval board to the esp32 GPIO27.

Lot's of debug turned on in lwip:

Code: Select all

ethernetif_input: IP input
tcpip_thread: PACKET 0x3ffbf790
dhcp_discover(): set request timeout 500 msecs
ethernet_input: dest:24:0a:c4:00:9f:c9, src:00:0c:29:5a:72:1c, type:800
ip_input: iphdr->dest 0x661f1fac netif->ip_addr 0x0 (0x0, 0x0, 0x661f1fac)
ip4_input: UDP packet to DHCP client port 68
ip4_input: DHCP packet accepted.
ip4_input: 
IP header:
+-------------------------------+
| 4 | 5 |  0x10 |       328     | (v, hl, tos, len)
+-------------------------------+
|        0      |000|       0   | (id, flags, offset)
+-------------------------------+
|   16  |   17  |    0x12e8     | (ttl, proto, chksum)
+-------------------------------+
|  172  |   31  |   31  |    9  | (src)
+-------------------------------+
|  172  |   31  |   31  |  102  | (dest)
+-------------------------------+
ip4_input: p->len 328 p->tot_len 328
dhcp_recv(pbuf = 0x3ffbf770) from DHCP server 172.31.31.9 port 67
pbuf->len = 300
pbuf->tot_len = 300
skipping option 28 in options
skipping option 15 in options
searching DHCP_OPTION_MESSAGE_TYPE
DHCP_OFFER received in DHCP_STATE_SELECTING state
dhcp_handle_offer(netif=0x3ffc5318) en0
dhcp_handle_offer(): server 0x091f1fac
dhcp_handle_offer(): offer for 0x661f1fac
dhcp_select(netif=0x3ffc5318) en0
transaction id xid(5851f42d)

Code: Select all

robin@u64imac:~/esp/esp-idf/components/lwip/include/lwip/port$ ping 172.31.31.102
PING 172.31.31.102 (172.31.31.102) 56(84) bytes of data.
64 bytes from 172.31.31.102: icmp_seq=1 ttl=255 time=1.11 ms
64 bytes from 172.31.31.102: icmp_seq=2 ttl=255 time=0.558 ms
64 bytes from 172.31.31.102: icmp_seq=3 ttl=255 time=0.509 ms
64 bytes from 172.31.31.102: icmp_seq=4 ttl=255 time=0.599 ms
I tried to do the same with the LAN8720 eval board but don't get CRS_DV asserted upon packet receipt. I'm checking config pins...

Robin

User avatar
rudi ;-)
Posts: 1558
Joined: Fri Nov 13, 2015 3:25 pm

Re: EMAC receive not working

Postby rudi ;-) » Sun Feb 26, 2017 4:09 am

you are welcome ;-)

btw:
LAN8720 , PIN_CRS_DV on GPIO 27

Code: Select all

static const char *TAG = "eth_demo";

#define PIN_PHY_POWER 17
#define PIN_SMI_MDC   23
#define PIN_SMI_MDIO  18
// LAN8720 
#define PIN_CRS_DV    27
but we must check on the register / datasheet the things for

Code: Select all

#define DEFAULT_PHY_CONFIG (AUTO_MDIX_ENABLE|AUTO_NEGOTIATION_ENABLE|AN_1|AN_0|LED_CFG)

Code: Select all


void eth_gpio_config_rmii(void)
{
	ESP_LOGI(TAG, "eth_gpio_config_rmii: [%d]", __LINE__);
    //txd0 to gpio19 ,can not change
    PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO19_U, FUNC_GPIO19_EMAC_TXD0);
    //tx_en to gpio21 ,can not change
    PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO21_U, FUNC_GPIO21_EMAC_TX_EN);
    //txd1 to gpio22 , can not change
    PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO22_U, FUNC_GPIO22_EMAC_TXD1);
    
	/*LAN8720*/
	// FUNC_GPIO27_EMAC_RX_DV rmii -> CRS_DV
	PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO27_U, FUNC_GPIO27_EMAC_RX_DV); 
	
	
	//rxd0 to gpio25 , can not change
    gpio_set_direction(25, GPIO_MODE_INPUT);
    //rxd1 to gpio26 ,can not change
    gpio_set_direction(26, GPIO_MODE_INPUT);
    //rmii clk  ,can not change
    gpio_set_direction(0, GPIO_MODE_INPUT);
	

    //mdc to gpio23 
    gpio_matrix_out(PIN_SMI_MDC, EMAC_MDC_O_IDX, 0, 0);
    //mdio to gpio18
    gpio_matrix_out(PIN_SMI_MDIO, EMAC_MDO_O_IDX, 0, 0);
    gpio_matrix_in(PIN_SMI_MDIO, EMAC_MDI_I_IDX, 0);
}


how looks your LAN8720 header, robin?

best wishes

rudi ;-)

pp
so i have now to hack the new TLK110 board? :lol:
..i will give 50MHz by pass .. in a try ;-) first before demount
-------------------------------------
love it, change it or leave it.
-------------------------------------
問候飛出去的朋友遍全球魯迪

www220
Posts: 34
Joined: Wed Dec 21, 2016 7:21 am

Re: EMAC receive not working

Postby www220 » Sun Feb 26, 2017 8:18 am

LAN8720连接方式
MDIO->GPIO14
MDC->GPIO32
RST->GPIO18
其他管脚按照默认的GPIO连接
RXD0,RXD1,CRS_DV,TXD0,TXD1,TXEN,EXT_CLK

#define PHY_RESET_CONTROL_REG (0x0)
#define SOFTWARE_RESET BIT(15)
#define SOFTWARE_AUTO_NEGTIATION BIT(12)

#define BASIC_MODE_STATUS_REG (0x1)
#define AUTO_NEGOTIATION_COMPLETE BIT(5)
#define LINK_STATUS BIT(2)

#define AUTO_NEG_ADVERTISEMENT_REG (0x4)
#define ASM_DIR BIT(11)
#define PAUSE BIT(10)

#define PHY_LINK_PARTNER_ABILITY_REG (0x5)
#define PARTNER_ASM_DIR BIT(11)
#define PARTNER_PAUSE BIT(10)

#define PHY_STATUS_REG (0x1f)
#define AUTO_NEGTIATION_STATUS BIT(12)
#define DUPLEX_STATUS BIT(4)
#define SPEED_STATUS BIT(2)

void phy_tlk110_check_phy_init(void)
{
while((esp_eth_smi_read(BASIC_MODE_STATUS_REG) & AUTO_NEGOTIATION_COMPLETE ) != AUTO_NEGOTIATION_COMPLETE)
{};
while((esp_eth_smi_read(PHY_STATUS_REG) & AUTO_NEGTIATION_STATUS ) != AUTO_NEGTIATION_STATUS)
{};
}

eth_speed_mode_t phy_tlk110_get_speed_mode(void)
{
if((esp_eth_smi_read(PHY_STATUS_REG) & SPEED_STATUS ) != SPEED_STATUS) {
return ETH_SPEED_MODE_100M;
} else {
return ETH_SPEED_MODE_10M;
}
}

eth_duplex_mode_t phy_tlk110_get_duplex_mode(void)
{
if((esp_eth_smi_read(PHY_STATUS_REG) & DUPLEX_STATUS ) == DUPLEX_STATUS) {
return ETH_MDOE_FULLDUPLEX;
} else {
return ETH_MODE_HALFDUPLEX;
}
}

bool phy_tlk110_check_phy_link_status(void)
{
if((esp_eth_smi_read(BASIC_MODE_STATUS_REG) & LINK_STATUS) == LINK_STATUS ) {
return true;
} else {
return false;
}
}

bool phy_tlk110_get_partner_pause_enable(void)
{
if((esp_eth_smi_read(PHY_LINK_PARTNER_ABILITY_REG) & PARTNER_PAUSE) == PARTNER_PAUSE) {
return true;
} else {
return false;
}
}

void phy_enable_flow_ctrl(void)
{
uint32_t data = 0;
data = esp_eth_smi_read(AUTO_NEG_ADVERTISEMENT_REG);
esp_eth_smi_write(AUTO_NEG_ADVERTISEMENT_REG,data|ASM_DIR|PAUSE);
}

void phy_tlk110_power_enable(bool enable)
{
}

void phy_tlk110_init(void)
{
gpio_set_level(GPIO_NUM_18, 0);
vTaskDelay(100 / portTICK_PERIOD_MS);
gpio_set_level(GPIO_NUM_18, 1);

esp_eth_smi_write(PHY_RESET_CONTROL_REG, SOFTWARE_RESET);
vTaskDelay(1000 / portTICK_PERIOD_MS);

esp_eth_smi_write(PHY_RESET_CONTROL_REG, SOFTWARE_AUTO_NEGTIATION);
vTaskDelay(100 / portTICK_PERIOD_MS);

//if config.flow_ctrl_enable == true ,enable this
phy_enable_flow_ctrl();
}

void eth_gpio_config_rmii(void)
{
//txd0 to gpio19 ,can not change
PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO19_U, FUNC_GPIO19_EMAC_TXD0);
//tx_en to gpio21 ,can not change
PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO21_U, FUNC_GPIO21_EMAC_TX_EN);
//txd1 to gpio22 , can not change
PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO22_U, FUNC_GPIO22_EMAC_TXD1);
//rxd0 to gpio25 , can not change
gpio_set_direction(25, GPIO_MODE_INPUT);
//rxd1 to gpio26 ,can not change
gpio_set_direction(26, GPIO_MODE_INPUT);
//rmii clk ,can not change
gpio_set_direction(0, GPIO_MODE_INPUT);

if(RTC_GPIO_IS_VALID_GPIO(GPIO_NUM_32)) rtc_gpio_deinit(GPIO_NUM_32);
if(RTC_GPIO_IS_VALID_GPIO(GPIO_NUM_14)) rtc_gpio_deinit(GPIO_NUM_14);
PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[GPIO_NUM_32], PIN_FUNC_GPIO);
gpio_set_pull_mode(GPIO_NUM_32, GPIO_PULLUP_ONLY);
gpio_set_direction(GPIO_NUM_32, GPIO_MODE_OUTPUT);
gpio_matrix_out(GPIO_NUM_32, EMAC_MDC_O_IDX, 0, 0);
PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[GPIO_NUM_14], PIN_FUNC_GPIO);
gpio_set_pull_mode(GPIO_NUM_14, GPIO_PULLUP_ONLY);
gpio_set_direction(GPIO_NUM_14, GPIO_MODE_INPUT_OUTPUT);
gpio_matrix_in(GPIO_NUM_14, EMAC_MDI_I_IDX, 0);
gpio_matrix_out(GPIO_NUM_14, EMAC_MDO_O_IDX, 0, 0);

if(RTC_GPIO_IS_VALID_GPIO(GPIO_NUM_18)) rtc_gpio_deinit(GPIO_NUM_18);
PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[GPIO_NUM_18], PIN_FUNC_GPIO);
gpio_set_pull_mode(GPIO_NUM_18, GPIO_PULLUP_ONLY);
gpio_set_level(GPIO_NUM_18, 1);
gpio_set_direction(GPIO_NUM_18, GPIO_MODE_OUTPUT);
gpio_matrix_out(GPIO_NUM_18, SIG_GPIO_OUT_IDX, 0, 0);
}

User avatar
rudi ;-)
Posts: 1558
Joined: Fri Nov 13, 2015 3:25 pm

Re: EMAC receive not working

Postby rudi ;-) » Sun Feb 26, 2017 1:10 pm

@www220

更改地址

#define PHY_STATUS_REG(0x1F)
#define AUTO_NEGTIATION_STATUS BIT(12)
#define DUPLEX_STATUS BIT(4)
#define SPEED_STATUS (2)

- >成功

谢谢!
found_missing_register.png
found_missing_register.png (16.76 KiB) Viewed 7756 times
Ethernet RMII
-> TLK110
-> SMS8720
-> LAN8720
-> LAN8720A
-> LAN8710
-> DP...

DONE!


best wishes!

rudi ;-)


@Ivan, Jeroen, Angus,
now we need the APLL 50 MHz solution on GPIO, urgent and fast :ugeek:
-------------------------------------
love it, change it or leave it.
-------------------------------------
問候飛出去的朋友遍全球魯迪

Who is online

Users browsing this forum: No registered users and 14 guests