Use SMI/MIIM interface with I2C instead, while keeping MAC alive.

florianhumblot
Posts: 3
Joined: Thu Jan 20, 2022 3:29 pm

Use SMI/MIIM interface with I2C instead, while keeping MAC alive.

Postby florianhumblot » Fri Jan 21, 2022 8:07 am

I am using a KSZ8863[1] managed switch with integrated PHY's from Microchip and I need to set some registers that are not available using MIIM or SMI interface.
Since the ESP32 uses it's hardware MAC to generate SMI packets, the packets will not be accepted by the switch. I managed to put the switch in I2C mode, which should allow me to access the registers.

Now, I have to keep the eth MAC enabled, for the rest of the state machine to work, so I tried giving the eth_mac_config_t from esp-idf the pin "-1" as input to the MDC and MDI pins, but that makes the ESP crash in a reboot loop with loadProhibited exceptions.

I have also tried commenting out the body of the function that sets the pins (emac_esp32_init_smi_gpio) to prevent the use of the pins for SMI interfacing so that I could use the I2C peripheral instead, but that didn't work either. With this, the clock sometimes goes haywire and keeps clocking after the transaction is done.

I'm using ESP-IDF v4.2.

I've seen different forum threads where the discussion participants say they managed to get the I2C to work, but I'm at a loss as to what to do to connect the GPIO23 and GPIO18 to the I2C peripheral instead of the SMI/RMII/MIIM peripherals while keeping the esp mac happy.



[1]: https://ww1.microchip.com/downloads/en/ ... 02335C.pdf

ESP_Sprite
Posts: 8921
Joined: Thu Nov 26, 2015 4:08 am

Re: Use SMI/MIIM interface with I2C instead, while keeping MAC alive.

Postby ESP_Sprite » Fri Jan 21, 2022 8:18 am

I'm not familiar with this particular peripheral, but one thing you could try is initializing the PHY as if you were to use a SMI interface, then loading the I2C driver using the exact same SMI pins. The logic is that the I2C driver will likely grab the GPIOs and it might all simply work.

florianhumblot
Posts: 3
Joined: Thu Jan 20, 2022 3:29 pm

Re: Use SMI/MIIM interface with I2C instead, while keeping MAC alive.

Postby florianhumblot » Fri Jan 21, 2022 9:45 am

I've tried doing the following:

Code: Select all

for(auto i = 0; i < 10; i++) {
    i2c_cmd_handle_t cmd = i2c_cmd_link_create();
    i2c_master_start(cmd);
    i2c_master_write_byte(cmd, (0x5f << 1) | I2C_MASTER_WRITE, 1);
    i2c_master_stop(cmd);
    ret = i2c_master_cmd_begin(i2c_num, cmd, 500 / portTICK_RATE_MS);
    i2c_cmd_link_delete(cmd);
    if (ret == ESP_OK) {
      ESP_LOGW(LOG_TAG, " IT RESPONDED %02x ", 0x5f);
    } else if (ret == ESP_ERR_TIMEOUT) {
      ESP_LOGE(LOG_TAG, "UU ");
    } else {
      ESP_LOGE(LOG_TAG, "-- ");
    }
  }
Which results in the following output:

Code: Select all

E (924) EthernetDevice: --
E (927) EthernetDevice: --
E (931) EthernetDevice: --
E (935) EthernetDevice: --
E (938) EthernetDevice: --
E (942) EthernetDevice: UU
E (945) EthernetDevice: --
E (948) EthernetDevice: --
W (952) EthernetDevice:  IT RESPONDED 5f
E (957) EthernetDevice: UU
So twice there is a timeout despite the 500 ticks, and the 9th time there is an actual ack.

This is what the loop looks like on my scope:
Image
This is one of the no-acks:
Image
This is the timeout (10th message):
Image
And this is the only one that did ack (9th message):
Image

Before running the loop, the ethernet setup is done except actually starting the ethernet by calling esp_eth_start.

ESP_Sprite
Posts: 8921
Joined: Thu Nov 26, 2015 4:08 am

Re: Use SMI/MIIM interface with I2C instead, while keeping MAC alive.

Postby ESP_Sprite » Sat Jan 22, 2022 4:38 am

That clock looks really suspect... you may want to decrease your clockrate or add a smaller pullup.

florianhumblot
Posts: 3
Joined: Thu Jan 20, 2022 3:29 pm

Re: Use SMI/MIIM interface with I2C instead, while keeping MAC alive.

Postby florianhumblot » Mon Jan 24, 2022 10:21 am

ESP_Sprite wrote:
Sat Jan 22, 2022 4:38 am
That clock looks really suspect... you may want to decrease your clockrate or add a smaller pullup.
Yep, you were right. I've added a 1K pull-up to 3v3 and it all works now.

Who is online

Users browsing this forum: No registered users and 157 guests