feat(esp_eth): add ESP32-S31 EMAC support

Add internal EMAC support for ESP32-S31, including:
- HAL/LL layer: emac_ll, emac_hal, emac_clk, emac_periph for S31
- SOC layer: register structs, soc_caps, peripherals linker script,
  interrupt definitions
- MAC driver: clock source configuration via Kconfig, GPIO/DMA
  adaptations, PHY register defs for clause-45 MDIO
- Ethernet examples updated for S31 (basic, build-test-rules, PTP
  readme)
- Refactored existing ESP32/ESP32-P4 EMAC code for shared patterns
  (emac_clk extraction, struct alignment, periph descriptor cleanup)
This commit is contained in:
Ondrej Kosta
2026-05-21 15:59:42 +08:00
parent c7d6c41198
commit edbf8856ae
39 changed files with 3558 additions and 173 deletions
+31 -4
View File
@@ -49,6 +49,33 @@ void emac_hal_init(emac_hal_context_t *hal)
#endif
}
esp_err_t emac_hal_ref_clock_select(emac_hal_context_t *hal, int sel)
{
if (!emac_ll_ref_clock_supported()) {
return ESP_ERR_NOT_SUPPORTED;
}
emac_ll_ref_clock_select(hal->ext_regs, sel);
return ESP_OK;
}
esp_err_t emac_hal_ref_clock_enable(emac_hal_context_t *hal, bool enable)
{
if (!emac_ll_ref_clock_supported()) {
return ESP_ERR_NOT_SUPPORTED;
}
emac_ll_ref_clock_enable(hal->ext_regs, enable);
return ESP_OK;
}
esp_err_t emac_hal_ref_clock_div(emac_hal_context_t *hal, int div)
{
if (!emac_ll_ref_clock_supported()) {
return ESP_ERR_NOT_SUPPORTED;
}
emac_ll_ref_clock_div(hal->ext_regs, div);
return ESP_OK;
}
void emac_hal_find_set_closest_csr_clock_range(emac_hal_context_t *hal, int mdc_freq_hz, int freq_hz)
{
int min_diff = abs(freq_hz / emac_crs_div_table[0] - mdc_freq_hz);
@@ -166,12 +193,12 @@ void emac_hal_init_dma_default(emac_hal_context_t *hal, emac_hal_dma_config_t *h
/* DMAOMR Configuration */
/* Enable Dropping of TCP/IP Checksum Error Frames */
emac_ll_drop_tcp_err_frame_enable(hal->dma_regs, true);
#if SOC_IS(ESP32P4)
/* Disable Receive Store Forward (Rx FIFO is only 256B) */
emac_ll_recv_store_forward_enable(hal->dma_regs, false);
#else
#if SOC_IS(ESP32)
/* Enable Receive Store Forward */
emac_ll_recv_store_forward_enable(hal->dma_regs, true);
#else
/* Disable Receive Store Forward (Rx FIFO is only 256B) */
emac_ll_recv_store_forward_enable(hal->dma_regs, false);
#endif
/* Enable Flushing of Received Frames because of the unavailability of receive descriptors or buffers */
emac_ll_flush_recv_frame_enable(hal->dma_regs, true);