Skip to content

Commit bc421db

Browse files
committed
Merge branch 'feat/kconfig_clk_rm' into 'master'
feat(esp_eth): removed RMII CLK Kconfig option Closes IDF-9724 See merge request espressif/esp-idf!41853
2 parents 79c69cf + 5aa9762 commit bc421db

File tree

19 files changed

+102
-224
lines changed

19 files changed

+102
-224
lines changed

components/esp_eth/Kconfig

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -13,74 +13,6 @@ menu "Ethernet"
1313
ESP32 integrates a 10/100M Ethernet MAC controller.
1414

1515
if ETH_USE_ESP32_EMAC
16-
choice ETH_PHY_INTERFACE
17-
prompt "PHY interface"
18-
default ETH_PHY_INTERFACE_RMII
19-
help
20-
Select the communication interface between MAC and PHY chip.
21-
22-
config ETH_PHY_INTERFACE_RMII
23-
bool "Reduced Media Independent Interface (RMII)"
24-
endchoice
25-
26-
if ETH_PHY_INTERFACE_RMII
27-
choice ETH_RMII_CLK_MODE # IDF-9724
28-
depends on IDF_TARGET_ESP32
29-
prompt "RMII clock mode"
30-
default ETH_RMII_CLK_INPUT
31-
help
32-
Select external or internal RMII clock.
33-
34-
config ETH_RMII_CLK_INPUT
35-
bool "Input RMII clock from external"
36-
help
37-
MAC will get RMII clock from outside.
38-
Note that ESP32 only supports GPIO0 to input the RMII clock.
39-
40-
config ETH_RMII_CLK_OUTPUT
41-
bool "Output RMII clock from internal"
42-
help
43-
ESP32 can generate RMII clock by internal APLL.
44-
This clock can be routed to the external PHY device.
45-
ESP32 supports to route the RMII clock to GPIO0/16/17.
46-
endchoice
47-
endif # ETH_PHY_INTERFACE_RMII
48-
49-
if ETH_RMII_CLK_INPUT
50-
config ETH_RMII_CLK_IN_GPIO
51-
depends on IDF_TARGET_ESP32
52-
int
53-
range 0 0
54-
default 0
55-
help
56-
ESP32 only supports GPIO0 to input the RMII clock.
57-
endif # ETH_RMII_CLK_INPUT
58-
59-
if ETH_RMII_CLK_OUTPUT
60-
config ETH_RMII_CLK_OUTPUT_GPIO0
61-
depends on IDF_TARGET_ESP32
62-
bool "Output RMII clock from GPIO0 (Experimental!)"
63-
default n
64-
help
65-
GPIO0 can be set to output a pre-divided PLL clock. Enabling this option will configure
66-
GPIO0 to output a 50MHz clock. In fact this clock doesn't have directly relationship with
67-
EMAC peripheral. Sometimes this clock may not work well with your PHY chip.
68-
WARNING: If you want the Ethernet to work with WiFi, don’t select ESP32 as RMII CLK output
69-
as it would result in clock instability!
70-
71-
if !ETH_RMII_CLK_OUTPUT_GPIO0
72-
config ETH_RMII_CLK_OUT_GPIO
73-
depends on IDF_TARGET_ESP32
74-
int "RMII clock GPIO number"
75-
range 16 17
76-
default 17
77-
help
78-
Set the GPIO number to output RMII Clock.
79-
WARNING: If you want the Ethernet to work with WiFi, don’t select ESP32 as RMII CLK output
80-
as it would result in clock instability!
81-
endif # !ETH_RMII_CLK_OUTPUT_GPIO0
82-
endif # ETH_RMII_CLK_OUTPUT
83-
8416
config ETH_DMA_BUFFER_SIZE
8517
int "Ethernet DMA buffer size (Byte)"
8618
range 256 1600

components/esp_eth/include/esp_eth_mac_esp.h

Lines changed: 13 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -22,75 +22,25 @@ extern "C" {
2222
*
2323
*/
2424
typedef enum {
25-
/**
26-
* @brief Default values configured using Kconfig are going to be used when "Default" selected.
27-
*
28-
* @warning Deprecated option. Clock configuration using Kconfig is limitedly supported only for ESP32 SoC via @c ETH_ESP32_EMAC_DEFAULT_CONFIG
29-
* and is going to be reevaluated in the next major release.
30-
* Clock mode and clock GPIO number is supposed to be defined in `EMAC specific configuration` structure from user's code.
31-
*
32-
*/
33-
EMAC_CLK_DEFAULT __attribute__((deprecated)), // IDF-9724
34-
3525
/**
3626
* @brief Input RMII Clock from external. EMAC Clock GPIO number needs to be configured when this option is selected.
3727
*
38-
* @note MAC will get RMII clock from outside. Note that ESP32 only supports GPIO0 to input the RMII clock.
28+
* @note See components/soc/esp32(*)/emac_periph.c for available GPIO numbers.
3929
*
4030
*/
4131
EMAC_CLK_EXT_IN,
4232

4333
/**
4434
* @brief Output RMII Clock from internal (A/M)PLL Clock. EMAC Clock GPIO number needs to be configured when this option is selected.
4535
*
46-
*/
47-
EMAC_CLK_OUT
48-
} emac_rmii_clock_mode_t;
49-
50-
#if CONFIG_IDF_TARGET_ESP32
51-
/**
52-
* @brief RMII Clock GPIO number Options for ESP32
53-
*
54-
* @warning If you want the Ethernet to work with WiFi, don’t select ESP32 as RMII CLK output as it would result in clock instability.
55-
*
56-
*/
57-
typedef enum {
58-
/**
59-
* @brief MAC will get RMII clock from outside at this GPIO.
60-
*
61-
* @note ESP32 only supports GPIO0 to input the RMII clock.
62-
*
63-
*/
64-
EMAC_CLK_IN_GPIO = 0,
65-
66-
/**
67-
* @brief Output RMII Clock from internal APLL Clock available at GPIO0
36+
* @warning ESP32 Errata: If you want the Ethernet to work with Wi-Fi or BT, don’t select ESP32 as RMII CLK output as it would result in clock instability.
37+
* Applicable only to ESP32, other ESP32 SoCs are not affected.
6838
*
69-
* @note GPIO0 can be set to output a pre-divided PLL clock. Enabling this option will configure GPIO0 to output a 50MHz clock.
70-
* In fact this clock doesn’t have directly relationship with EMAC peripheral. Sometimes this clock may not work well with your PHY chip.
71-
*
72-
*/
73-
EMAC_APPL_CLK_OUT_GPIO = 0,
74-
75-
/**
76-
* @brief Output RMII Clock from internal APLL Clock available at GPIO16
77-
*
78-
*/
79-
EMAC_CLK_OUT_GPIO = 16,
80-
81-
/**
82-
* @brief Inverted Output RMII Clock from internal APLL Clock available at GPIO17
39+
* @note See components/soc/esp32(*)/emac_periph.c for available GPIO numbers.
8340
*
8441
*/
85-
EMAC_CLK_OUT_180_GPIO = 17
86-
} emac_rmii_clock_gpio_t;
87-
#else
88-
/**
89-
* @brief RMII Clock GPIO number
90-
*
91-
*/
92-
typedef int emac_rmii_clock_gpio_t;
93-
#endif // CONFIG_IDF_TARGET_ESP32
42+
EMAC_CLK_OUT
43+
} emac_rmii_clock_mode_t;
9444

9545
/**
9646
* @brief Ethernet MAC Clock Configuration
@@ -102,8 +52,8 @@ typedef union {
10252
// Reserved for GPIO number, clock source, etc. in MII mode
10353
} mii; /*!< EMAC MII Clock Configuration */
10454
struct {
105-
emac_rmii_clock_mode_t clock_mode; /*!< RMII Clock Mode Configuration */
106-
emac_rmii_clock_gpio_t clock_gpio; /*!< RMII Clock GPIO Configuration */
55+
emac_rmii_clock_mode_t clock_mode; /*!< RMII Clock Mode Configuration */
56+
int clock_gpio; /*!< RMII Clock GPIO Configuration */
10757
} rmii; /*!< EMAC RMII Clock Configuration */
10858
} eth_mac_clock_config_t;
10959

@@ -165,13 +115,7 @@ typedef union {
165115
*
166116
*/
167117
typedef struct {
168-
union {
169-
emac_esp_smi_gpio_config_t smi_gpio; /*!< SMI GPIO numbers */
170-
struct {
171-
int smi_mdc_gpio_num __attribute__((deprecated("Please use smi_gpio instead"))); /*!< SMI MDC GPIO number, set to -1 could bypass the SMI GPIO configuration */
172-
int smi_mdio_gpio_num __attribute__((deprecated("Please use smi_gpio instead"))); /*!< SMI MDIO GPIO number, set to -1 could bypass the SMI GPIO configuration */
173-
};
174-
};
118+
emac_esp_smi_gpio_config_t smi_gpio; /*!< SMI GPIO numbers */
175119
eth_data_interface_t interface; /*!< EMAC Data interface to PHY (MII/RMII) */
176120
eth_mac_clock_config_t clock_config; /*!< EMAC Interface clock configuration */
177121
eth_mac_dma_burst_len_t dma_burst_len; /*!< EMAC DMA burst length for both Tx and Rx */
@@ -223,24 +167,6 @@ typedef bool (*ts_target_exceed_cb_from_isr_t)(esp_eth_mediator_t *eth, void *us
223167
*
224168
*/
225169
#if CONFIG_IDF_TARGET_ESP32
226-
#if CONFIG_ETH_RMII_CLK_INPUT // IDF-9724
227-
#define DEFAULT_RMII_CLK_MODE EMAC_CLK_EXT_IN
228-
#if CONFIG_ETH_RMII_CLK_IN_GPIO == 0
229-
#define DEFAULT_RMII_CLK_GPIO CONFIG_ETH_RMII_CLK_IN_GPIO
230-
#else
231-
#error "ESP32 EMAC only support input RMII clock to GPIO0"
232-
#endif // CONFIG_ETH_RMII_CLK_IN_GPIO == 0
233-
#elif CONFIG_ETH_RMII_CLK_OUTPUT
234-
#define DEFAULT_RMII_CLK_MODE EMAC_CLK_OUT
235-
#if CONFIG_ETH_RMII_CLK_OUTPUT_GPIO0
236-
#define DEFAULT_RMII_CLK_GPIO EMAC_APPL_CLK_OUT_GPIO
237-
#else
238-
#define DEFAULT_RMII_CLK_GPIO CONFIG_ETH_RMII_CLK_OUT_GPIO
239-
#endif // CONFIG_ETH_RMII_CLK_OUTPUT_GPIO0
240-
#else
241-
#error "Unsupported RMII clock mode"
242-
#endif // CONFIG_ETH_RMII_CLK_INPUT
243-
244170
#define ETH_ESP32_EMAC_DEFAULT_CONFIG() \
245171
{ \
246172
.smi_gpio = \
@@ -253,8 +179,8 @@ typedef bool (*ts_target_exceed_cb_from_isr_t)(esp_eth_mediator_t *eth, void *us
253179
{ \
254180
.rmii = \
255181
{ \
256-
.clock_mode = DEFAULT_RMII_CLK_MODE, \
257-
.clock_gpio = (emac_rmii_clock_gpio_t) DEFAULT_RMII_CLK_GPIO \
182+
.clock_mode = EMAC_CLK_EXT_IN, \
183+
.clock_gpio = 0 \
258184
} \
259185
}, \
260186
.dma_burst_len = ETH_DMA_BURST_LEN_32, \
@@ -274,7 +200,7 @@ typedef bool (*ts_target_exceed_cb_from_isr_t)(esp_eth_mediator_t *eth, void *us
274200
.rmii = \
275201
{ \
276202
.clock_mode = EMAC_CLK_EXT_IN, \
277-
.clock_gpio = (emac_rmii_clock_gpio_t) 50 \
203+
.clock_gpio = 50 \
278204
} \
279205
}, \
280206
.dma_burst_len = ETH_DMA_BURST_LEN_32, \
@@ -296,7 +222,7 @@ typedef bool (*ts_target_exceed_cb_from_isr_t)(esp_eth_mediator_t *eth, void *us
296222
.rmii = \
297223
{ \
298224
.clock_mode = EMAC_CLK_EXT_IN, \
299-
.clock_gpio = (emac_rmii_clock_gpio_t) -1 \
225+
.clock_gpio = -1 \
300226
} \
301227
}, \
302228
}

components/esp_eth/src/mac/esp_eth_mac_esp.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -876,9 +876,9 @@ static esp_err_t emac_esp_config_data_interface(const eth_esp32_emac_config_t *e
876876
emac_hal_clock_enable_rmii_input(&emac->hal);
877877
}
878878
#elif CONFIG_IDF_TARGET_ESP32
879-
// we can also use the IOMUX to route the APLL clock to specific GPIO
880-
if (esp32_emac_config->clock_config.rmii.clock_gpio == EMAC_APPL_CLK_OUT_GPIO) {
881-
ESP_GOTO_ON_ERROR(esp_clock_output_start(CLKOUT_SIG_APLL, EMAC_APPL_CLK_OUT_GPIO, &emac->rmii_clk_hdl),
879+
// we can also use the IOMUX to route the APLL clock to GPIO_0
880+
if (esp32_emac_config->clock_config.rmii.clock_gpio == 0) {
881+
ESP_GOTO_ON_ERROR(esp_clock_output_start(CLKOUT_SIG_APLL, 0, &emac->rmii_clk_hdl),
882882
err, TAG, "start APLL clock output failed");
883883
} else
884884
#endif

components/esp_eth/test_apps/main/esp_eth_test_common.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@ esp_eth_mac_t *mac_init(void *vendor_emac_config, eth_mac_config_t *mac_config)
4242
#if CONFIG_TARGET_RMII_CLK_OUT
4343
esp32_emac_config.clock_config.rmii.clock_mode = EMAC_CLK_OUT;
4444
esp32_emac_config.clock_config.rmii.clock_gpio = CONFIG_TARGET_RMII_CLK_OUT_GPIO;
45+
#if !SOC_EMAC_RMII_CLK_OUT_INTERNAL_LOOPBACK
4546
esp32_emac_config.clock_config_out_in.rmii.clock_mode = EMAC_CLK_EXT_IN;
4647
esp32_emac_config.clock_config_out_in.rmii.clock_gpio = CONFIG_TARGET_RMII_CLK_IN_GPIO;
48+
#endif // !SOC_EMAC_RMII_CLK_OUT_INTERNAL_LOOPBACK
4749
#endif // CONFIG_TARGET_TEST_RMII_CLK_OUT
4850
if (vendor_emac_config == NULL) {
4951
vendor_emac_config = &esp32_emac_config;

components/esp_eth/test_apps/sdkconfig.ci.default_dp83848

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ CONFIG_ESP_TASK_WDT_EN=n
77

88
CONFIG_TARGET_USE_INTERNAL_ETHERNET=y
99
CONFIG_TARGET_ETH_PHY_DEVICE_DP83848=y
10-
CONFIG_ETH_RMII_CLK_OUTPUT=y
11-
CONFIG_ETH_RMII_CLK_OUT_GPIO=17
10+
CONFIG_TARGET_RMII_CLK_OUT=y
11+
CONFIG_TARGET_RMII_CLK_OUT_GPIO=17

components/esp_eth/test_apps/sdkconfig.ci.default_lan8720

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ CONFIG_ESP_TASK_WDT_EN=n
77

88
CONFIG_TARGET_USE_INTERNAL_ETHERNET=y
99
CONFIG_TARGET_ETH_PHY_DEVICE_LAN8720=y
10-
CONFIG_ETH_RMII_CLK_OUTPUT=y
11-
CONFIG_ETH_RMII_CLK_OUT_GPIO=17
10+
CONFIG_TARGET_RMII_CLK_OUT=y
11+
CONFIG_TARGET_RMII_CLK_OUT_GPIO=17

docs/en/api-reference/network/esp_eth.rst

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,8 @@ The Ethernet driver is composed of two parts: MAC and PHY.
130130

131131
One of the obvious differences between MII and RMII is signal consumption. MII usually costs up to 18 signals, while the RMII interface can reduce the consumption to 9.
132132

133-
.. only:: esp32
134-
135-
.. note::
136-
ESP-IDF only supports the RMII interface. Therefore, always set :cpp:member:`eth_esp32_emac_config_t::interface` to :cpp:enumerator:`eth_data_interface_t::EMAC_DATA_INTERFACE_RMII` or always select ``CONFIG_ETH_PHY_INTERFACE_RMII`` in the Kconfig option :ref:`CONFIG_ETH_PHY_INTERFACE`.
137-
138-
.. only:: not esp32
139-
140-
.. note::
141-
ESP-IDF only supports the RMII interface. Therefore, always set :cpp:member:`eth_esp32_emac_config_t::interface` to :cpp:enumerator:`eth_data_interface_t::EMAC_DATA_INTERFACE_RMII`.
133+
.. note::
134+
ESP-IDF only supports the RMII interface. Therefore, always set :cpp:member:`eth_esp32_emac_config_t::interface` to :cpp:enumerator:`eth_data_interface_t::EMAC_DATA_INTERFACE_RMII`.
142135

143136
In RMII mode, both the receiver and transmitter signals are referenced to the ``REF_CLK``. ``REF_CLK`` **must be stable during any access to PHY and MAC**. Generally, there are three ways to generate the ``REF_CLK`` depending on the PHY device in your design:
144137

@@ -150,15 +143,12 @@ The Ethernet driver is composed of two parts: MAC and PHY.
150143

151144
.. only:: esp32
152145

153-
.. note::
154-
The ``REF_CLK`` can be also configured via Project Configuration when :cpp:class:`eth_esp32_emac_config_t` is initialized using :c:macro:`ETH_ESP32_EMAC_DEFAULT_CONFIG` macro. In the Project Configuration, choose appropriately ``CONFIG_ETH_RMII_CLK_INPUT`` or ``CONFIG_ETH_RMII_CLK_OUTPUT`` option under :ref:`CONFIG_ETH_RMII_CLK_MODE` configuration based on your design as discussed above.
155-
156146
.. warning::
157-
If the RMII clock mode is configured to :cpp:enumerator:`emac_rmii_clock_mode_t::EMAC_CLK_OUT` (or ``CONFIG_ETH_RMII_CLK_OUTPUT`` is selected), then ``GPIO0`` can be used to output the ``REF_CLK`` signal. See :cpp:enumerator:`emac_rmii_clock_gpio_t::EMAC_APPL_CLK_OUT_GPIO` or :ref:`CONFIG_ETH_RMII_CLK_OUTPUT_GPIO0` for more information.
147+
If the RMII clock mode is configured to :cpp:enumerator:`emac_rmii_clock_mode_t::EMAC_CLK_OUT`, internal Audio PLL clock is used as a source of 50 MHz clock. Hence be sure it is not in collision with I2S bus configuration.
158148

159-
What is more, if you are not using PSRAM in your design, GPIO16 and GPIO17 are also available to output the reference clock signal. See :cpp:enumerator:`emac_rmii_clock_gpio_t::EMAC_CLK_OUT_GPIO` and :cpp:enumerator:`emac_rmii_clock_gpio_t::EMAC_CLK_OUT_180_GPIO` or :ref:`CONFIG_ETH_RMII_CLK_OUT_GPIO` for more information.
149+
When internal clock is selected, then ``GPIO0`` can be used to output the ``REF_CLK`` signal. However, the clock is outputted directly to the GPIO in this particular case and so it does not have direct relationship with EMAC peripheral. Sometimes this configuration may not work well with your PHY chip. If you are not using PSRAM in your design, GPIO16 and GPIO17 are also available to output the reference clock signal. The source of clock is the same (APLL) but these signals are routed from EMAC peripheral.
160150

161-
If the RMII clock mode is configured to :cpp:enumerator:`emac_rmii_clock_mode_t::EMAC_CLK_EXT_IN` (or ``CONFIG_ETH_RMII_CLK_INPUT`` is selected), then ``GPIO0`` is the only choice to input the ``REF_CLK`` signal. Please note that ``GPIO0`` is also an important strapping GPIO on ESP32. If GPIO0 samples a low level during power-up, ESP32 will go into download mode. The system will get halted until a manually reset. The workaround for this issue is disabling the ``REF_CLK`` in hardware by default so that the strapping pin is not interfered by other signals in the boot stage. Then, re-enable the ``REF_CLK`` in the Ethernet driver installation stage.
151+
If the RMII clock mode is configured to :cpp:enumerator:`emac_rmii_clock_mode_t::EMAC_CLK_EXT_IN`, then ``GPIO0`` is the only choice to input the ``REF_CLK`` signal. Please note that ``GPIO0`` is also an important strapping GPIO on ESP32. If GPIO0 samples a low level during power-up, ESP32 will go into download mode. The system will get halted until a manually reset. The workaround for this issue is disabling the ``REF_CLK`` in hardware by default so that the strapping pin is not interfered by other signals in the boot stage. Then, re-enable the ``REF_CLK`` in the Ethernet driver installation stage.
162152

163153
The ways to disable the ``REF_CLK`` signal can be:
164154

@@ -167,7 +157,7 @@ The Ethernet driver is composed of two parts: MAC and PHY.
167157
* Force the PHY device to reset status (as the case **a** in the picture). **This could fail for some PHY device** (i.e., it still outputs signals to GPIO0 even in reset state).
168158

169159
.. warning::
170-
If you want the **Ethernet to work with Wi-Fi**, don’t select ESP32 as source of ``REF_CLK`` as it would result in ``REF_CLK`` instability. Either disable Wi-Fi or use a PHY or an external oscillator as the ``REF_CLK`` source.
160+
If you want the **Ethernet to work with Wi-Fi or Bluetooth**, don’t select ESP32 as source of ``REF_CLK`` as it would result in ``REF_CLK`` instability. Either disable Wi-Fi or use a PHY or an external oscillator as the ``REF_CLK`` source.
171161

172162
.. only:: not esp32
173163

docs/en/migration-guides/release-6.x/6.0/networking.rst

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,29 @@ Usage example:
1616
.. code-block:: c
1717
1818
esp_eth_phy_802_3_reset_hw(phy_802_3);
19+
20+
21+
Removed RMII Clock Kconfig Options
22+
----------------------------------
23+
24+
Removed the following RMII clock Kconfig options from `components/esp_eth`. Clock configuration is now handled exclusively through EMAC config structures.
25+
26+
**Removed Options**:
27+
- `ETH_PHY_INTERFACE_RMII`, `ETH_RMII_CLK_INPUT`, `ETH_RMII_CLK_OUTPUT`
28+
- `ETH_RMII_CLK_IN_GPIO`, `ETH_RMII_CLK_OUTPUT_GPIO0`, `ETH_RMII_CLK_OUT_GPIO`
29+
30+
**Migration**:
31+
32+
.. code-block:: c
33+
34+
// Before: Configuration via Kconfig
35+
// CONFIG_ETH_RMII_CLK_INPUT=y
36+
37+
// After: Explicit configuration in code
38+
eth_esp32_emac_config_t emac_config = ETH_ESP32_EMAC_DEFAULT_CONFIG();
39+
emac_config.clock_config.rmii.clock_mode = EMAC_CLK_OUT; // or EMAC_CLK_EXT_IN
40+
emac_config.clock_config.rmii.clock_gpio = 0; // GPIO0 for ESP32
41+
42+
43+
**Impact**: Applications using ``ETH_ESP32_EMAC_DEFAULT_CONFIG()`` continue to work. Custom clock configurations must be set explicitly in the EMAC config structure or use the `Ethernet Init component <https://components.espressif.com/components/espressif/ethernet_init>`_.
44+

0 commit comments

Comments
 (0)