GPIO4 can't be used for UART when Ethernet is enabled

stijnb1234
Posts: 4
Joined: Tue Feb 27, 2024 12:15 pm

GPIO4 can't be used for UART when Ethernet is enabled

Postby stijnb1234 » Tue Feb 27, 2024 12:17 pm

I'm using an ESP32-WROOM-U. When I try to use GPIO4 for UART when I have Ethernet enabled, it can't get an IP. Why is this? How can I fix this?

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

Re: GPIO4 can't be used for UART when Ethernet is enabled

Postby ESP_Sprite » Wed Feb 28, 2024 2:07 am

You need to be a bit more specific: the ESP32-WROOM-U is a module that by itself does not have Ethernet capabilities, it needs an external PHY. What hardware are you using that has that module?

stijnb1234
Posts: 4
Joined: Tue Feb 27, 2024 12:15 pm

Re: GPIO4 can't be used for UART when Ethernet is enabled

Postby stijnb1234 » Wed Feb 28, 2024 12:47 pm

I'm using an LAN8720 chip connected by a custom PCB, which works fine when I'm not using GPIO4 for UART.

TX EN: IO21
TX D0: IO19
TX D1: IO22
RX D0: IO25
RX D1: IO26
CRS DV: IO27
MDIO: IO18
MDC: IO23
REF CLK: IO0
RESET: IO17
LAN8720 ON: IO2

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

Re: GPIO4 can't be used for UART when Ethernet is enabled

Postby ESP_Sprite » Fri Mar 01, 2024 3:51 am

Can you share your code that initializes the Ethernet MAC and the GPIO?

stijnb1234
Posts: 4
Joined: Tue Feb 27, 2024 12:15 pm

Re: GPIO4 can't be used for UART when Ethernet is enabled

Postby stijnb1234 » Fri Mar 01, 2024 8:26 am

  1. #define ETH_PHY_ADDR 0
  2. #define ETH_PHY_RST_GPIO GPIO_NUM_17
  3. #define ETH_PHY_POWER_GPIO GPIO_NUM_2
  4. #define ETH_PHY_MDIO_GPIO GPIO_NUM_18
  5. #define ETH_PHY_MDC_GPIO GPIO_NUM_23
  6.  
  7. esp_err_t Ethernet::init() {
  8.   esp_err_t err;
  9.  
  10.   // Turn on LAN8720
  11.   gpio_set_direction(ETH_PHY_POWER_GPIO, GPIO_MODE_OUTPUT);
  12.   gpio_set_level(ETH_PHY_POWER_GPIO, 1);
  13.  
  14.   // Initialize the EMAC
  15.   eth_esp32_emac_config_t config = ETH_ESP32_EMAC_DEFAULT_CONFIG();
  16.   config.smi_mdc_gpio_num = ETH_PHY_MDC_GPIO;
  17.   config.smi_mdio_gpio_num = ETH_PHY_MDIO_GPIO;
  18.   config.clock_config = {
  19.       .rmii = {.clock_mode = EMAC_CLK_EXT_IN, .clock_gpio = EMAC_CLK_IN_GPIO}};
  20.  
  21.   // Initialize the MAC and PHY
  22.   eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG();
  23.   eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG();
  24.   phy_config.phy_addr = ETH_PHY_ADDR;
  25.   phy_config.reset_gpio_num = ETH_PHY_RST_GPIO;
  26.   mac = esp_eth_mac_new_esp32(&config, &mac_config);
  27.   phy = esp_eth_phy_new_lan87xx(&phy_config);
  28.  
  29.   // Install the driver
  30.   esp_eth_handle_t eth_handle = NULL;
  31.   esp_eth_config_t eth_conf = ETH_DEFAULT_CONFIG(mac, phy);
  32.   err = esp_eth_driver_install(&eth_conf, &eth_handle);
  33.   if (err != ESP_OK) {
  34.     ESP_LOGE(TAG, "Ethernet driver installation failure: %s",
  35.              esp_err_to_name(err));
  36.     return err;
  37.   }
  38.  
  39.   // Initialize TCP/IP network interface
  40.   err = esp_netif_init();
  41.   if (err != ESP_OK) {
  42.     ESP_LOGE(TAG, "Network Interface initialization failure: %s",
  43.              esp_err_to_name(err));
  44.     return err;
  45.   }
  46.   err = esp_event_loop_create_default();
  47.   if (err != ESP_OK) {
  48.     ESP_LOGE(TAG, "Event loop creation failure: %s", esp_err_to_name(err));
  49.     return err;
  50.   }
  51.   esp_netif_config_t netif_config = ESP_NETIF_DEFAULT_ETH();
  52.   esp_netif_t* eth_netif = esp_netif_new(&netif_config);
  53.   err = esp_netif_attach(eth_netif, esp_eth_new_netif_glue(eth_handle));
  54.   if (err != ESP_OK) {
  55.     ESP_LOGE(TAG, "Network Interface attachment failure: %s",
  56.              esp_err_to_name(err));
  57.     return err;
  58.   }
  59.  
  60.   // Register event handlers
  61.   err = esp_event_handler_register(ETH_EVENT, ESP_EVENT_ANY_ID, &on_eth_event,
  62.                                    NULL);
  63.   if (err != ESP_OK) {
  64.     ESP_LOGE(TAG, "Ethernet event handler registration failure: %s",
  65.              esp_err_to_name(err));
  66.     return err;
  67.   }
  68.   err = esp_event_handler_register(IP_EVENT, IP_EVENT_ETH_GOT_IP, &on_got_ip,
  69.                                    NULL);
  70.   if (err != ESP_OK) {
  71.     ESP_LOGE(TAG, "IP event handler registration failure: %s",
  72.              esp_err_to_name(err));
  73.     return err;
  74.   }
  75.  
  76.   // Start the Ethernet driver
  77.   err = esp_eth_start(eth_handle);
  78.   if (err != ESP_OK) {
  79.     ESP_LOGE(TAG, "Ethernet start failure: %s", esp_err_to_name(err));
  80.     return err;
  81.   }
  82.  
  83.   return ESP_OK;
  84. }

phatpaul
Posts: 110
Joined: Fri Aug 24, 2018 1:14 pm

Re: GPIO4 can't be used for UART when Ethernet is enabled

Postby phatpaul » Fri Mar 15, 2024 2:00 pm

Not sure if relevant or helpful, but I previously found that JTAG was unusable when the EMAC is enabled, even though they don't share any pins. I never figured out why, but configured my project with macros to disable EMAC when I need to debug with JTAG.

ESP_ondrej
Posts: 211
Joined: Fri May 07, 2021 10:35 am

Re: GPIO4 can't be used for UART when Ethernet is enabled

Postby ESP_ondrej » Mon Mar 25, 2024 9:32 am

That's strange... The only thing which crossed my mind is the GPIO4 can be IO MUXed to EMAC_TX_ER function (see section 4.10 IO_MUX Pad List in TRM). Therefore make sure the GPIO4 is properly configured.

Who is online

Users browsing this forum: No registered users and 166 guests