|
5 | 5 |
|
6 | 6 | include(binutils.common) |
7 | 7 |
|
| 8 | +# process ESP32 Ethernet options |
| 9 | +macro(nf_process_esp32_ethernet_options) |
| 10 | + |
| 11 | + # need to process this? |
| 12 | + if(ESP32_ETHERNET_SUPPORT) |
| 13 | + |
| 14 | + if(NOT ESP32_ETHERNET_INTERFACE) |
| 15 | + # default to LAN8720 |
| 16 | + set(ESP32_ETHERNET_INTERFACE "LAN8720" CACHE INTERNAL "Defaulting LAN8720") |
| 17 | + |
| 18 | + message(STATUS "\n\n*** No Ethernet interface defined. Defaulting to LAN8720. ***\n\n") |
| 19 | + endif() |
| 20 | + |
| 21 | + # list of supported PHYs |
| 22 | + set(ESP32_SUPPORTED_PHY "LAN8720" "IP101" "RTL8201" "DP83848" "KSZ8041" CACHE INTERNAL "supported ESP32 PHYs") |
| 23 | + # list of supported ETH SPI PHYs |
| 24 | + # ENJ28J60 currently not supported, driver in IDF examples (TODO) |
| 25 | + set(ESP32_SUPPORTED_ETH_SPI "W5500" "DM9051" "ENJ28J60" CACHE INTERNAL "supported ESP32 ETH SPIs") |
| 26 | + |
| 27 | + list(FIND ESP32_SUPPORTED_PHY ${ESP32_ETHERNET_INTERFACE} ESP32_PHY_INDEX) |
| 28 | + |
| 29 | + if(ESP32_PHY_INDEX EQUAL -1) |
| 30 | + |
| 31 | + # can't find this under supported PHYs |
| 32 | + |
| 33 | + # try with SPIs |
| 34 | + list(FIND ESP32_SUPPORTED_ETH_SPI ${ESP32_ETHERNET_INTERFACE} ESP32_ETH_SPI_INDEX) |
| 35 | + |
| 36 | + if(ESP32_ETH_SPI_INDEX EQUAL -1) |
| 37 | + # can't find it under SPIs either |
| 38 | + message(FATAL_ERROR "\n\nSomething wrong happening: can't find support for Ethernet interface ${ESP32_ETHERNET_INTERFACE}!\n\n") |
| 39 | + else() |
| 40 | + # store SPI option |
| 41 | + set(ESP32_ETHERNET_SPI_OPTION TRUE CACHE INTERNAL "Set ESP32_ETHERNET_SPI option") |
| 42 | + set(ESP32_ETHERNET_INTERNAL_OPTION FALSE CACHE INTERNAL "Set ESP32_ETHERNET_INTERNAL option") |
| 43 | + # set define with SPI module |
| 44 | + set(ESP32_ETHERNET_DEFINES -DESP32_ETHERNET_SPI_MODULE_${ESP32_ETHERNET_INTERFACE} CACHE INTERNAL "define for Ethernet SPI module option") |
| 45 | + endif() |
| 46 | + |
| 47 | + else() |
| 48 | + # store PHY option |
| 49 | + set(ESP32_ETHERNET_INTERNAL_OPTION TRUE CACHE INTERNAL "Set ESP32_ETHERNET_INTERNAL option") |
| 50 | + set(ESP32_ETHERNET_SPI_OPTION FALSE CACHE INTERNAL "Set ESP32_ETHERNET_SPI option") |
| 51 | + # set define with PHY name |
| 52 | + set(ESP32_ETHERNET_DEFINES -DESP32_ETHERNET_PHY_${ESP32_ETHERNET_INTERFACE} CACHE INTERNAL "define for Ethernet PHY interface option") |
| 53 | + endif() |
| 54 | + |
| 55 | + endif() |
| 56 | + |
| 57 | +endmacro() |
| 58 | + |
8 | 59 | # find a set of files on a list of possible locations |
9 | 60 | macro(nf_find_esp32_files_at_location files locations) |
10 | 61 |
|
@@ -165,6 +216,8 @@ macro(nf_add_platform_dependencies target) |
165 | 216 | nf_add_lib_network( |
166 | 217 | BUILD_TARGET |
167 | 218 | ${target} |
| 219 | + EXTRA_COMPILE_DEFINITIONS |
| 220 | + ${ESP32_ETHERNET_DEFINES} |
168 | 221 | EXTRA_SOURCES |
169 | 222 | ${TARGET_ESP32_IDF_NETWORK_SOURCES} |
170 | 223 | EXTRA_INCLUDES |
@@ -470,6 +523,11 @@ macro(nf_add_idf_as_library) |
470 | 523 |
|
471 | 524 | message(STATUS "\n-- SDK CONFIG is: '${SDKCONFIG_DEFAULTS_FILE}'.") |
472 | 525 |
|
| 526 | + # Save original contents to be restored later |
| 527 | + file(READ |
| 528 | + "${SDKCONFIG_DEFAULTS_FILE}" |
| 529 | + SDKCONFIG_ORIGINAL_CONTENTS) |
| 530 | + |
473 | 531 | # set list with the IDF components to add |
474 | 532 | # need to match the list below with the respective libraries |
475 | 533 | set(IDF_COMPONENTS_TO_ADD |
@@ -498,40 +556,6 @@ macro(nf_add_idf_as_library) |
498 | 556 | if(ESP32_ETHERNET_SUPPORT) |
499 | 557 | list(APPEND IDF_COMPONENTS_TO_ADD esp_eth) |
500 | 558 | list(APPEND IDF_LIBRARIES_TO_ADD idf::esp_eth) |
501 | | - |
502 | | - # check for ETH_RMII_CLK_OUT_GPIO in the build options |
503 | | - if(ETH_RMII_CLK_OUT_GPIO) |
504 | | - |
505 | | - message(STATUS "\nETH_RMII_CLK_OUT_GPIO specified. Updating SDK CONFIG to enable CLK output on GPIO${ETH_RMII_CLK_OUT_GPIO}.\n") |
506 | | - |
507 | | - # need to read the supplied SDK CONFIG file and replace the appropriate options |
508 | | - file(READ |
509 | | - "${SDKCONFIG_DEFAULTS_FILE}" |
510 | | - SDKCONFIG_DEFAULT_CONTENTS) |
511 | | - |
512 | | - string(REPLACE |
513 | | - "#CONFIG_ETH_RMII_CLK_OUTPUT=y" |
514 | | - "CONFIG_ETH_RMII_CLK_OUTPUT=y" |
515 | | - SDKCONFIG_DEFAULT_NEW_CONTENTS |
516 | | - "${SDKCONFIG_DEFAULT_CONTENTS}") |
517 | | - |
518 | | - string(REPLACE |
519 | | - "#CONFIG_ETH_RMII_CLK_OUT_GPIO=n" |
520 | | - "CONFIG_ETH_RMII_CLK_OUT_GPIO=${ETH_RMII_CLK_OUT_GPIO}" |
521 | | - SDKCONFIG_DEFAULT_FINAL_CONTENTS |
522 | | - "${SDKCONFIG_DEFAULT_NEW_CONTENTS}") |
523 | | - |
524 | | - # need to temporarilly allow changes in source files |
525 | | - set(CMAKE_DISABLE_SOURCE_CHANGES OFF) |
526 | | - |
527 | | - file(WRITE |
528 | | - ${SDKCONFIG_DEFAULTS_FILE} |
529 | | - ${SDKCONFIG_DEFAULT_FINAL_CONTENTS}) |
530 | | - |
531 | | - set(CMAKE_DISABLE_SOURCE_CHANGES ON) |
532 | | - |
533 | | - endif() |
534 | | - |
535 | 559 | endif() |
536 | 560 |
|
537 | 561 | # handle specifics for ESP32S2 series |
@@ -640,8 +664,17 @@ macro(nf_add_idf_as_library) |
640 | 664 | PROJECT_VER ${BUILD_VERSION} |
641 | 665 | ) |
642 | 666 |
|
| 667 | + #Restore original sdkconfig back to defaults |
| 668 | + set(CMAKE_DISABLE_SOURCE_CHANGES OFF) |
| 669 | + |
| 670 | + file(WRITE |
| 671 | + ${SDKCONFIG_DEFAULTS_FILE} |
| 672 | + ${SDKCONFIG_ORIGINAL_CONTENTS}) |
| 673 | + |
| 674 | + set(CMAKE_DISABLE_SOURCE_CHANGES ON) |
| 675 | + |
643 | 676 | if(USE_NETWORKING_OPTION) |
644 | | - |
| 677 | + |
645 | 678 | FetchContent_GetProperties(esp32_idf) |
646 | 679 |
|
647 | 680 | # get list of source files for lwIP |
|
0 commit comments