ESP32-S3 with W5500 reeeealy slow performance
Posted: Fri May 10, 2024 10:15 am
Hi there.
I have some code, that is working with WIFI flawlessly. But due to a special application, I need to run it wired, and having used the W5500 before (on arduino framework), I was happy to learn that there are direct support for W5500 in the ESP32.
And basically, the sample codes that I found, are working. I use a esp_http_client, and the esp_http_server.
And its working - sort of......
I have the webinterface, and communication with http_client. But the responsetime is really, really slow.
EG, a simple submit from my webpage, with only 63 bytes of data, takes around 60ms using WIFI, but using LAN and the W5500 the responsetime is 1.32 seconds.... It is simply just pending. Setting my timeout for the http_client as 2 seconds to prevent timeout, is actually works, and received aroung 10k of data. Again, it just seems to be pending for a long time, before action.
I have tried various stuff, but nothing seems to help. It does not seem, that its the newwork traffic as such, that is slow. its more, why is it pending for more than a second for no reason...
Any help would be apreciated...
My initialiazation code:
I have some code, that is working with WIFI flawlessly. But due to a special application, I need to run it wired, and having used the W5500 before (on arduino framework), I was happy to learn that there are direct support for W5500 in the ESP32.
And basically, the sample codes that I found, are working. I use a esp_http_client, and the esp_http_server.
And its working - sort of......
I have the webinterface, and communication with http_client. But the responsetime is really, really slow.
EG, a simple submit from my webpage, with only 63 bytes of data, takes around 60ms using WIFI, but using LAN and the W5500 the responsetime is 1.32 seconds.... It is simply just pending. Setting my timeout for the http_client as 2 seconds to prevent timeout, is actually works, and received aroung 10k of data. Again, it just seems to be pending for a long time, before action.
I have tried various stuff, but nothing seems to help. It does not seem, that its the newwork traffic as such, that is slow. its more, why is it pending for more than a second for no reason...
Any help would be apreciated...
My initialiazation code:
- void MyLAN::ethernet_init(void)
- {
- gpio_reset_pin(GPIO_NUM_43); // free uart0
- gpio_reset_pin(GPIO_NUM_44); // free uart0
- ESP_ERROR_CHECK(esp_netif_init());
- // Create default event loop that running in background
- ESP_ERROR_CHECK(esp_event_loop_create_default()); // ****
- // Register user defined event handers
- ESP_ERROR_CHECK(esp_event_handler_register(ETH_EVENT, ESP_EVENT_ANY_ID, &EthernetHardwareEventHandler, NULL));
- ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_ETH_GOT_IP, &EthernetIpEventHandler, NULL));
- // Create instance(s) of esp-netif for SPI Ethernet(s)
- esp_netif_inherent_config_t esp_netif_config = ESP_NETIF_INHERENT_DEFAULT_ETH();
- esp_netif_config_t cfg_spi = { };
- cfg_spi.base = &esp_netif_config;
- cfg_spi.stack = ESP_NETIF_NETSTACK_DEFAULT_ETH;
- esp_netif_t* eth_netif_spi = NULL;
- char if_key_str[10];
- char if_desc_str[10];
- char num_str[3];
- itoa(0, num_str, 10);
- strcat(strcpy(if_key_str, "ETH_SPI_"), num_str);
- strcat(strcpy(if_desc_str, "eth"), num_str);
- esp_netif_config.if_key = if_key_str;
- esp_netif_config.if_desc = if_desc_str;
- esp_netif_config.route_prio = 30;
- eth_netif_spi = esp_netif_new(&cfg_spi);
- if (eth_netif_spi == NULL) printf("Jo, den er nul 1\n");
- else printf("Den er i det mindste ikke nul 1\n");
- // Init MAC and PHY configs to default
- eth_mac_config_t mac_config_spi = ETH_MAC_DEFAULT_CONFIG();
- eth_phy_config_t phy_config_spi = ETH_PHY_DEFAULT_CONFIG();
- phy_config_spi.autonego_timeout_ms = 0;
- phy_config_spi.reset_gpio_num = -1;
- ESP_LOGD(TAG, "Installing isr service");
- gpio_install_isr_service(0);
- // Init SPI bus
- spi_bus_config_t buscfg = { };
- buscfg.miso_io_num = GVs->Board->io_sdi0.MISO; // ETHERNET_SPI_MOSI_GPIO;
- buscfg.mosi_io_num = GVs->Board->io_sdi0.MOSI; // ETHERNET_SPI_MISO_GPIO;
- buscfg.sclk_io_num = GVs->Board->io_sdi0.CLK; // ETHERNET_SPI_CLK_GPIO;
- buscfg.quadwp_io_num = -1;
- buscfg.quadhd_io_num = -1;
- ESP_ERROR_CHECK(spi_bus_initialize(SPI2_HOST, &buscfg, SPI_DMA_CH_AUTO));
- // Configure SPI interface and Ethernet driver for specific SPI module
- esp_eth_mac_t* mac_spi;
- esp_eth_phy_t* phy_spi;
- esp_eth_handle_t eth_handle_spi = NULL;
- spi_device_interface_config_t spi_devcfg = { };
- spi_devcfg.command_bits = 16; // Actually it's the address phase in W5500 SPI frame
- spi_devcfg.address_bits = 8; // Actually it's the control phase in W5500 SPI frame
- spi_devcfg.spics_io_num = GVs->Board->io_sdi0.SS; // ETHERNET_SPI_CS_GPIO;
- spi_devcfg.mode = 0;
- spi_devcfg.clock_speed_hz = 33 * 1000 * 1000; // org. 33
- spi_devcfg.queue_size = 20;
- // Set remaining GPIO numbers and configuration used by the SPI module
- phy_config_spi.phy_addr = 1;
- eth_w5500_config_t w5500_config = ETH_W5500_DEFAULT_CONFIG(SPI2_HOST, &spi_devcfg);
- w5500_config.int_gpio_num = GVs->Board->io_sdi0.INT; // ETHERNET_SPI_INT_GPIO;
- mac_spi = esp_eth_mac_new_w5500(&w5500_config, &mac_config_spi);
- phy_spi = esp_eth_phy_new_w5500(&phy_config_spi);
- vTaskDelay(pdMS_TO_TICKS(10)); // wait for w5500 to startup
- esp_eth_config_t eth_config_spi = ETH_DEFAULT_CONFIG(mac_spi, phy_spi);
- ESP_ERROR_CHECK(esp_eth_driver_install(ð_config_spi, ð_handle_spi));
- uint8_t mac_addr[6];
- esp_read_mac(mac_addr, ESP_MAC_ETH);
- ESP_ERROR_CHECK(esp_eth_ioctl(eth_handle_spi, ETH_CMD_S_MAC_ADDR, mac_addr));
- if (eth_netif_spi == NULL) printf("Jo, den er nul 2\n");
- else printf("Den er i det mindste ikke nul 2\n");
- if (eth_handle_spi == NULL) printf("Jo, den er nul 3\n");
- else printf("Den er i det mindste ikke nul 3\n");
- vTaskDelay(1000/portTICK_PERIOD_MS);
- // attach Ethernet driver to TCP/IP stack
- ESP_ERROR_CHECK(esp_netif_attach(eth_netif_spi, esp_eth_new_netif_glue(eth_handle_spi)));
- /* start Ethernet driver state machine */
- ESP_ERROR_CHECK(esp_eth_start(eth_handle_spi));
- }