Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KSZ8863 Ethernet Driver (beta) failing in I2C client mode (IDFGH-13769) #40

Closed
3 tasks done
derrick-senva opened this issue Sep 24, 2024 · 7 comments
Closed
3 tasks done
Assignees
Labels
Resolution: Won't Do This will not be worked on Status: Done Issue is done internally

Comments

@derrick-senva
Copy link

Checklist

  • Checked the issue tracker for similar issues to ensure this is not a duplicate
  • Read the documentation to confirm the issue is not addressed there and your configuration is set correctly
  • Tested with the latest version to ensure the issue hasn't been fixed

How often does this bug occurs?

always

Expected behavior

I expect the I2C communications to work with the RMII clock generated by the KSZ8863 and for the Ethernet/RMII to work properly.

Actual behavior (suspected bug)

The I2C communications fail to get ACK'd by the KSZ8863 when the RMII clock (REFCLKO_3) is enabled on it. The I2C traffic generated by the ESP32 also appears to sporadically generate invalid I2C traffic.

Error logs or terminal output

No response

Steps to reproduce the behavior

  1. Configure the simple switch example from https://components.espressif.com/components/espressif/ksz8863 for I2C client mode.
  2. Wire the ESP32-PICO-DevKitM-2 to the KSZ8863 Daughter Board
  3. Added an I2C command to the initialization code to configure the KSZ8863's RMII for MAC mode.
  4. See the forum post here for full details: https://esp32.com/viewtopic.php?f=13&t=41997&p=138041#p138041

Project release version

v0.2.6

System architecture

Intel/AMD 64-bit (modern PC, older Mac)

Operating system

Windows

Operating system version

Windows 10

Shell

CMD

Additional context

This issue was originally posted on the forum with full details and screenshots of various analog/digital captures: https://esp32.com/viewtopic.php?f=13&t=41997&p=138041#p138041.

@github-actions github-actions bot changed the title KSZ8863 Ethernet Driver (beta) failing in I2C client mode KSZ8863 Ethernet Driver (beta) failing in I2C client mode (IDFGH-13769) Sep 24, 2024
@derrick-senva
Copy link
Author

This is what the 50 MHz RMII clock from the KSZ8863 looks like when we probe it at the IO0 (REF_CLK) header pin of the ESP32-PICO-DevKitM-2. Is this adequate?

If not, could this be the reason that we are not seeing activity on IO19 (EMAC_TXD0) and IO22 (EMAC_TXD1)? The serial monitor also says "simple_switch_example: L2 TAP write error, errno: 0".

REFCLKO_3_loaded

@kostaond
Copy link
Collaborator

kostaond commented Oct 9, 2024

The RMII REF CLK is 50 MHz square wave. You see something similar to sine wave but that might be expected. It depends on your oscilloscope bandwidth and you also need to disable 20 MHz filter (if it's there) on voltage input. If the oscilloscope bandwidth is low or filter is enabled, higher harmonics of the signal are filtered out and you cannot see the square wave. It's expected behavior, please try to search the web.

Anyway, have you tried to shorten wires as I suggested on forum? Did you double check the reference schematics with your setup. Did you double check the Kconfig configuration is in line with your HW setup? If so, please send me log of unmodified "simple switch" example.

@derrick-senva
Copy link
Author

derrick-senva commented Oct 15, 2024

The RMII REF CLK is 50 MHz square wave. You see something similar to sine wave but that might be expected. It depends on your oscilloscope bandwidth and you also need to disable 20 MHz filter (if it's there) on voltage input. If the oscilloscope bandwidth is low or filter is enabled, higher harmonics of the signal are filtered out and you cannot see the square wave. It's expected behavior, please try to search the web.

The scope is rated up to 200 MHz and the probes 350 MHz. The scope settings are configured for no bandwidth limit.

Anyway, have you tried to shorten wires as I suggested on forum? Did you double check the reference schematics with your setup. Did you double check the Kconfig configuration is in line with your HW setup? If so, please send me log of unmodified "simple switch" example.

We tried shortening the wires and providing more ground connections between the two dev kits, but we can only shorten it so much. The Kconfig configuration is correct as far as I can tell. The I2C does work (without REFCLKO_3 enabled) and the RMII worked once as I was able to capture the Wireshark traffic. We don't have a schematic since it's just dev kits. I just have this table showing our board-to-board connections and modifications. Pins on the same row are connected together. We've reviewed it multiple times against reference schematics and the datasheets and cannot find anything that looks incorrect.

One of our engineers is going to prototype a custom PCB using the reference design and we'll try that (since the wires between dev kits are not ideal).

I'll try to run the base example unmodified and copy the serial log output here. One thing I added that looked missing from the example was to set Port 3 MII Mode Selection to MAC mode. This is register 53 (0x35), bit 7. Is this not correct? I added the following function to esp_eth_ksz8863.c:

esp_err_t ksz8863_p3_mac_mode(esp_eth_handle_t port_eth_handle)
{
    esp_err_t ret = ESP_OK;
    esp_eth_mediator_t *eth = (esp_eth_mediator_t *)port_eth_handle;
    ksz8863_pcr5_reg_t pcr5;

    ESP_GOTO_ON_ERROR(eth->phy_reg_read(eth, 0, KSZ8863_P3CR5_ADDR, &(pcr5.val)), err, TAG, "read KSZ8863_P3CR5_ADDR failed");
    pcr5.port3_mii_mode = 1;
    ESP_GOTO_ON_ERROR(eth->phy_reg_write(eth, 0, KSZ8863_P3CR5_ADDR, pcr5.val), err, TAG, "write KSZ8863_P3CR5_ADDR failed");

err:
    return ret;
}

2024-10-15 10_06_33-KSZ8863MLL_FLL_RLL Integrated 3-Port 10_100 Managed Switch with PHYs Data Sheet

@derrick-senva
Copy link
Author

derrick-senva commented Oct 28, 2024

The RMII REF CLK is 50 MHz square wave. You see something similar to sine wave but that might be expected. It depends on your oscilloscope bandwidth and you also need to disable 20 MHz filter (if it's there) on voltage input. If the oscilloscope bandwidth is low or filter is enabled, higher harmonics of the signal are filtered out and you cannot see the square wave. It's expected behavior, please try to search the web.

Anyway, have you tried to shorten wires as I suggested on forum? Did you double check the reference schematics with your setup. Did you double check the Kconfig configuration is in line with your HW setup? If so, please send me log of unmodified "simple switch" example.

@kostaond, I've run the unmodified simple switch example from this repo on our custom PCB prototype, which mostly follows the pin assignments from our "dev kits prototype". If the schematic would be of help, we'd prefer to share that in private. Just let me know what's an appropriate method.

Below is the serial monitor log running the example. At timestamp 18457, I connect a single DHCP client into Ethernet port 1. At timestamp 40467, I connect Ethernet port 2 to a switch on our office LAN which has hundreds of devices. You can see the MAC table entries continue to grow over time. I'm also able to access the DHCP client on port 1 from my laptop, which is connected to the office LAN, so the switch appears to be working across those two ports.

I also have Wireshark capturing network traffic from our office LAN, but I do not see any broadcasts for "This is ESP32 L2 TAP test msg" (I saw it work one time with our previous "dev kits prototype", screenshot is below the serial monitor log). I probed EMAC_TXD0 (GPIO19) and EMAC_TXD1 (GPIO22) with a scope and it appears to be transmitting real data.

The two things from the log that stand out are the I2C warning W (386) i2c: This driver is an old driver, please migrate your application code to adapt `driver/i2c_master.h and
emac error E (447) esp.emac: emac_esp_custom_ioctl(276): unknown io command: 4109. The I2C is technically working fine in this example, so I'm assuming that isn't a serious issue, but what is the error?

Executing action: monitor
Running idf_monitor in directory C:\derrick_workspace\eclipse_workspaces\ksz8863\simple_switch
Executing "C:\Espressif\python_env\idf5.2_py3.11_env\Scripts\python.exe C:\Espressif\frameworks\esp-idf-v5.3.1\tools/idf_monitor.py -p COM16 -b 115200 --toolchain-prefix xtensa-esp32-elf- --target esp32 --revision 0 C:\derrick_workspace\eclipse_workspaces\ksz8863\simple_switch\build\ksz8863_simple_switch.elf --force-color -m 'C:\Espressif\python_env\idf5.2_py3.11_env\Scripts\python.exe' 'C:\Espressif\frameworks\esp-idf-v5.3.1\tools\idf.py'"...
--- WARNING: GDB cannot open serial ports accessed as COMx
--- Using \\.\COM16 instead...
--- esp-idf-monitor 1.4.0 on \\.\COM16 115200 ---
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
ets Jul 29 2019 12:21:46

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 271414342, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:7176
load:0x40078000,len:15564
ho 0 tail 12 room 4
load:0x40080400,len:4
0x40080400: _init at ??:?

load:0x40080404,len:3904
entry 0x40080640
I (32) boot: ESP-IDF v5.3.1-1-g4f8f0a1d23-dirty 2nd stage bootloader
I (32) boot: compile time Oct 21 2024 16:51:49
I (34) boot: Multicore bootloader
I (38) boot: chip revision: v3.1
I (42) boot.esp32: SPI Speed      : 40MHz
I (46) boot.esp32: SPI Mode       : DIO
I (51) boot.esp32: SPI Flash Size : 2MB
I (55) boot: Enabling RNG early entropy source...
I (61) boot: Partition Table:
I (64) boot: ## Label            Usage          Type ST Offset   Length
I (72) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (79) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (87) boot:  2 factory          factory app      00 00 00010000 00100000
I (94) boot: End of partition table
I (98) esp_image: segment 0: paddr=00010020 vaddr=3f400020 size=164dch ( 91356) map
I (138) esp_image: segment 1: paddr=00026504 vaddr=3ffb0000 size=025e4h (  9700) load
I (142) esp_image: segment 2: paddr=00028af0 vaddr=40080000 size=07528h ( 29992) load
I (156) esp_image: segment 3: paddr=00030020 vaddr=400d0020 size=39730h (235312) map
I (237) esp_image: segment 4: paddr=00069758 vaddr=40087528 size=092e4h ( 37604) load
I (260) boot: Loaded app from partition at offset 0x10000
I (260) boot: Disabling RNG early entropy source...
I (272) cpu_start: Multicore app
I (280) cpu_start: Pro cpu start user code
I (280) cpu_start: cpu freq: 160000000 Hz
I (280) app_init: Application information:
I (283) app_init: Project name:     ksz8863_simple_switch
I (289) app_init: App version:      1
I (293) app_init: Compile time:     Oct 21 2024 16:49:10
I (299) app_init: ELF file SHA256:  bc9054f40...
I (305) app_init: ESP-IDF:          v5.3.1-1-g4f8f0a1d23-dirty
I (311) efuse_init: Min chip rev:     v0.0
I (316) efuse_init: Max chip rev:     v3.99
I (321) efuse_init: Chip rev:         v3.1
I (326) heap_init: Initializing. RAM available for dynamic allocation:
I (333) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (339) heap_init: At 3FFB39A0 len 0002C660 (177 KiB): DRAM
I (345) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (352) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (358) heap_init: At 4009080C len 0000F7F4 (61 KiB): IRAM
I (366) spi_flash: detected chip: generic
I (369) spi_flash: flash io: dio
W (373) spi_flash: Detected size(8192k) larger than the size in the binary image header(2048k). Using the size in the binary image header.
W (386) i2c: This driver is an old driver, please migrate your application code to adapt `driver/i2c_master.h`
I (397) main_task: Started on CPU0
I (407) main_task: Calling app_main()
W (407) simple_switch_example: Simple Switch mode Example...

W (407) ksz8863_eth: SW reset resets all Global, MAC and PHY registers!
I (417) esp_eth.netif.netif_glue: 0c:8b:95:b3:b9:af
I (417) esp_eth.netif.netif_glue: ethernet attached to netif
I (447) simple_switch_example: Ethernet Started
E (447) esp.emac: emac_esp_custom_ioctl(276): unknown io command: 4109
I (447) simple_switch_example: Ethernet Link Up
I (457) simple_switch_example: Ethernet HW Addr 0c:8b:95:b3:b9:af
I (457) simple_switch_example: Ethernet Started
I (4467) simple_switch_example: Ethernet Started
I (4467) main_task: Returned from app_main()
I (4477) simple_switch_example: Dynamic MAC Table content:
I (4477) simple_switch_example: valid entries 1
I (4477) simple_switch_example: port 1
I (4477) simple_switch_example: 21 3a 41 3b 61 c9

I (9487) simple_switch_example: Dynamic MAC Table content:
I (9487) simple_switch_example: valid entries 1
I (9487) simple_switch_example: port 1
I (9497) simple_switch_example: 21 3a 41 3b 61 c9

I (14507) simple_switch_example: Dynamic MAC Table content:
I (14507) simple_switch_example: valid entries 1
I (14517) simple_switch_example: port 1
I (14517) simple_switch_example: 21 3a 41 3b 61 c9

I (18457) simple_switch_example: Ethernet Link Up Port 1
I (18457) simple_switch_example: Ethernet HW Addr 00:00:00:00:00:00
I (19527) simple_switch_example: Dynamic MAC Table content:
I (19527) simple_switch_example: valid entries 1
I (19527) simple_switch_example: port 1
I (19537) simple_switch_example: 4c 75 25 a4 27 0f

I (24547) simple_switch_example: Dynamic MAC Table content:
I (24547) simple_switch_example: valid entries 1
I (24557) simple_switch_example: port 1
I (24557) simple_switch_example: 4c 75 25 a4 27 0f

I (29567) simple_switch_example: Dynamic MAC Table content:
I (29567) simple_switch_example: valid entries 1
I (29567) simple_switch_example: port 1
I (29577) simple_switch_example: 4c 75 25 a4 27 0f

I (34587) simple_switch_example: Dynamic MAC Table content:
I (34587) simple_switch_example: valid entries 1
I (34597) simple_switch_example: port 1
I (34597) simple_switch_example: 4c 75 25 a4 27 0f

I (39607) simple_switch_example: Dynamic MAC Table content:
I (39607) simple_switch_example: valid entries 1
I (39607) simple_switch_example: port 1
I (39617) simple_switch_example: 4c 75 25 a4 27 0f

I (40467) simple_switch_example: Ethernet Link Up Port 2
I (40467) simple_switch_example: Ethernet HW Addr 00:00:00:00:00:00
I (44627) simple_switch_example: Dynamic MAC Table content:
I (44627) simple_switch_example: valid entries 1
I (44637) simple_switch_example: port 1
I (44637) simple_switch_example: 4c 75 25 a4 27 0f

I (49647) simple_switch_example: Dynamic MAC Table content:
I (49647) simple_switch_example: valid entries 1
I (49657) simple_switch_example: port 1
I (49657) simple_switch_example: 4c 75 25 a4 27 0f

I (54667) simple_switch_example: Dynamic MAC Table content:
I (54667) simple_switch_example: valid entries 1
I (54667) simple_switch_example: port 1
I (54677) simple_switch_example: 4c 75 25 a4 27 0f

I (59687) simple_switch_example: Dynamic MAC Table content:
I (59687) simple_switch_example: valid entries 1
I (59697) simple_switch_example: port 1
I (59697) simple_switch_example: 4c 75 25 a4 27 0f

I (64467) simple_switch_example: Ethernet Link Down Port 2
I (64707) simple_switch_example: Dynamic MAC Table content:
I (64707) simple_switch_example: valid entries 1
I (64707) simple_switch_example: port 1
I (64717) simple_switch_example: 4c 75 25 a4 27 0f

I (69727) simple_switch_example: Dynamic MAC Table content:
I (69727) simple_switch_example: valid entries 1
I (69737) simple_switch_example: port 1
I (69737) simple_switch_example: 4c 75 25 a4 27 0f

I (72467) simple_switch_example: Ethernet Link Up Port 2
I (72467) simple_switch_example: Ethernet HW Addr 00:00:00:00:00:00
I (74747) simple_switch_example: Dynamic MAC Table content:
I (74747) simple_switch_example: valid entries 32
I (74757) simple_switch_example: port 2
I (74757) simple_switch_example: 00 10 18 11 c5 26
I (74767) simple_switch_example: port 2
I (74767) simple_switch_example: 00 d8 61 f3 46 36
I (74777) simple_switch_example: port 2
I (74777) simple_switch_example: 0c 8b 95 93 d2 cc
I (74787) simple_switch_example: port 2
I (74787) simple_switch_example: 0c 8b 95 94 75 00
I (74797) simple_switch_example: port 2
I (74797) simple_switch_example: 0c 8b 95 94 76 98

I (79807) simple_switch_example: Dynamic MAC Table content:
I (79807) simple_switch_example: valid entries 55
I (79817) simple_switch_example: port 2
I (79817) simple_switch_example: 00 10 18 11 c5 26
I (79827) simple_switch_example: port 2
I (79827) simple_switch_example: 00 d8 61 f3 46 36
I (79837) simple_switch_example: port 2
I (79837) simple_switch_example: 08 92 04 6f b6 98
I (79847) simple_switch_example: port 2
I (79847) simple_switch_example: 0a 31 8a 9e c9 a5
I (79857) simple_switch_example: port 2
I (79857) simple_switch_example: 0c 8b 95 93 d1 ec

I (84867) simple_switch_example: Dynamic MAC Table content:
I (84867) simple_switch_example: valid entries 68
I (84877) simple_switch_example: port 2
I (84877) simple_switch_example: 00 10 18 11 c5 26
I (84887) simple_switch_example: port 2
I (84887) simple_switch_example: 00 24 e8 24 75 8c
I (84897) simple_switch_example: port 2
I (84897) simple_switch_example: 00 d8 61 f3 46 36
I (84907) simple_switch_example: port 2
I (84907) simple_switch_example: 08 92 04 6f b6 98
I (84917) simple_switch_example: port 2
I (84917) simple_switch_example: 0a 31 8a 9e c9 a5

I (89927) simple_switch_example: Dynamic MAC Table content:
I (89927) simple_switch_example: valid entries 78
I (89937) simple_switch_example: port 2
I (89937) simple_switch_example: 00 10 18 11 c5 26
I (89947) simple_switch_example: port 2
I (89947) simple_switch_example: 00 24 e8 24 75 8c
I (89957) simple_switch_example: port 2
I (89957) simple_switch_example: 00 d8 61 f3 46 36
I (89967) simple_switch_example: port 2
I (89967) simple_switch_example: 08 92 04 6f b6 98
I (89977) simple_switch_example: port 2
I (89977) simple_switch_example: 0a 31 8a 9e c9 a5

2024-10-28 10_45_07-Wireshark · Packet 161 · ksz8863 p3 eth and i2c working pcapng

@kostaond
Copy link
Collaborator

kostaond commented Oct 29, 2024

I'm also able to access the DHCP client on port 1 from my laptop

I'm not sure if I follow. Simple switch example workflow is to connect to DCHP Server. You should got the IP address and be able to ping your device at that address. I don't see it in your logs... Here is example what should have seen.

Please send me schematics and your sdkconfig.h to [email protected]. I'll have a look.

@kostaond
Copy link
Collaborator

The two things from the log that stand out are the I2C warning W (386) i2c: This driver is an old driver, please migrate your application code to adapt `driver/i2c_master.h and
emac error E (447) esp.emac: emac_esp_custom_ioctl(276): unknown io command: 4109. The I2C is technically working fine in this example, so I'm assuming that isn't a serious issue, but what is the error?

Yeah, these are expected. I need to migrate to new I2C driver and suppress that io command error since it is expected.

@kostaond
Copy link
Collaborator

kostaond commented Nov 8, 2024

Closing since issue was user's board hardware related.

@kostaond kostaond closed this as completed Nov 8, 2024
@espressif-bot espressif-bot added Status: Done Issue is done internally Resolution: Won't Do This will not be worked on and removed Status: Opened labels Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Won't Do This will not be worked on Status: Done Issue is done internally
Projects
None yet
Development

No branches or pull requests

3 participants