MIIM Driver for LAN9354

ivoRoth
Posts: 2
Joined: Sat Aug 25, 2018 10:25 am

MIIM Driver for LAN9354

Postby ivoRoth » Sat Aug 25, 2018 11:26 am

Dear forum
I'm planning a IIoT node based on ESP32-WROOM module and a LAN9354 IEEE1588 switch. The switch chip has an RMII and MIIM PHY interface connection to the EMAC of the ESP32.
http://ww1.microchip.com/downloads/en/D ... 01926B.pdf
My question is, how do I modifie the example PHY drivers in the ESP32 IDF to get a LAN9354 chip supporting driver.

Thank you very much for your help

ivoRoth
Posts: 2
Joined: Sat Aug 25, 2018 10:25 am

Re: MIIM Driver for LAN9354

Postby ivoRoth » Fri Sep 07, 2018 5:56 pm

Dear forum
MIIM communication is based on the functions "void esp_eth_smi_write (uint32_t reg_num, uint16_t value)", "uint16_t esp_eth_smi_read (uint32_t reg_num)" and "esp_err_t esp_eth_smi_wait_value (uint32_t reg_num, uint16_t value, uint16_t value_mask, int timeout_ms)" of the source file. .. \ esp-idf \ components \ ethernet \ emac_main.c ". These features are not compatible with the LAN9354. The LAN9354 uses the PHY addresses 16 to 32 with the 32 register addresses each as the address space of the 256 32 bit chip registers.
If the source file "emac_main.c" is extended by the following method, a dump of the LAN9354 registers is possible.

Code: Select all

uint32_t esp_eth_smi_u32read(uint32_t reg_num)
{
    //uint32_t phy_num = emac_config.phy_addr;
    uint32_t value = 0;

    while (REG_GET_BIT(EMAC_GMIIADDR_REG, EMAC_MIIBUSY) == 1 ) {
    }

    //REG_WRITE(EMAC_GMIIADDR_REG, 0x1 | ((reg_num & 0x1f) << 6) | ((phy_num & 0x1f) << 11) | (0x3 << 2));
    //read upper word
    REG_WRITE(EMAC_GMIIADDR_REG, 0x1 | (((reg_num +1)& 0x3FF) << 6) | (0x3 << 2));
    while (REG_GET_BIT(EMAC_GMIIADDR_REG, EMAC_MIIBUSY) == 1 ) {
    }
    
    value = ((REG_READ(EMAC_MIIDATA_REG) & 0xffff)<< 16);
    
    //read lower word
    REG_WRITE(EMAC_GMIIADDR_REG, 0x1 | ((reg_num & 0x3FF) << 6) | (0x3 << 2));
    while (REG_GET_BIT(EMAC_GMIIADDR_REG, EMAC_MIIBUSY) == 1 ) {
    }
    
    value = value | (REG_READ(EMAC_MIIDATA_REG) & 0xffff);

    return value;
}
and a universal dump methode.

Code: Select all

void phy_lan9354_unidump_registers()
{
    ESP_LOGD(TAG, "LAN9354 Registers:");
    for(uint32 i=0; i<250; i++)
    {
    ESP_LOGD(TAG, "Registers   0x%08x", esp_eth_smi_u32read(i));
    }
}
Thank you very much for your help

minhngvan
Posts: 1
Joined: Fri Nov 23, 2018 2:41 pm

Re: MIIM Driver for LAN9354

Postby minhngvan » Fri Nov 23, 2018 2:48 pm

Hi,
Did you success to make LAN9354 working with esp32?

Who is online

Users browsing this forum: Majestic-12 [Bot] and 85 guests