CMakeLists.txt 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. idf_build_get_property(idf_target IDF_TARGET)
  2. if(${idf_target} STREQUAL "linux")
  3. return() # This component is not supported by the POSIX/Linux simulator
  4. endif()
  5. if(IDF_TARGET STREQUAL "esp32p4")
  6. # TODO: IDF-7460
  7. return()
  8. endif()
  9. set(srcs "src/phy_override.c" "src/lib_printf.c" "src/phy_common.c")
  10. if(CONFIG_APP_NO_BLOBS)
  11. set(link_binary_libs 0)
  12. set(ldfragments)
  13. else()
  14. set(link_binary_libs 1)
  15. set(ldfragments "linker.lf")
  16. endif()
  17. if(CONFIG_SOC_IEEE802154_BLE_ONLY)
  18. list(APPEND srcs "src/phy_init_esp32hxx.c")
  19. else()
  20. list(APPEND srcs "src/phy_init.c")
  21. endif()
  22. if(CONFIG_SOC_BT_SUPPORTED OR CONFIG_SOC_IEEE802154_SUPPORTED OR CONFIG_SOC_IEEE802154_BLE_ONLY)
  23. list(APPEND srcs "src/btbb_init.c")
  24. endif()
  25. if(CONFIG_ESP_PHY_ENABLE_CERT_TEST)
  26. list(APPEND srcs "src/phy_callback.c")
  27. endif()
  28. idf_build_get_property(build_dir BUILD_DIR)
  29. if(CONFIG_SOC_WIFI_SUPPORTED)
  30. if(CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN)
  31. if(NOT EXISTS "${build_dir}/phy_multiple_init_data.bin")
  32. file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/${idf_target}/phy_multiple_init_data.bin DESTINATION "${build_dir}")
  33. endif()
  34. endif()
  35. if(CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN_EMBED)
  36. set(embed_files "${build_dir}/phy_multiple_init_data.bin")
  37. endif()
  38. endif()
  39. # [refactor-todo]: requires "driver" component for periph_ctrl header file
  40. idf_component_register(SRCS "${srcs}"
  41. INCLUDE_DIRS "include" "${idf_target}/include"
  42. PRIV_REQUIRES nvs_flash driver efuse esp_timer esp_wifi
  43. LDFRAGMENTS "${ldfragments}"
  44. EMBED_FILES ${embed_files}
  45. )
  46. set(target_name "${idf_target}")
  47. target_link_directories(${COMPONENT_LIB} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/lib/${target_name}")
  48. # Override functions in PHY lib with the functions in 'phy_override.c'
  49. target_link_libraries(${COMPONENT_LIB} INTERFACE "-u include_esp_phy_override")
  50. if(link_binary_libs)
  51. target_link_libraries(${COMPONENT_LIB} PUBLIC phy)
  52. idf_component_get_property(esp_phy_lib esp_phy COMPONENT_LIB)
  53. if(CONFIG_IDF_TARGET_ESP32)
  54. target_link_libraries(${COMPONENT_LIB} PUBLIC rtc)
  55. target_link_libraries(${COMPONENT_LIB} INTERFACE $<TARGET_FILE:${esp_phy_lib}> libphy.a librtc.a
  56. $<TARGET_FILE:${esp_phy_lib}>)
  57. elseif(CONFIG_IDF_TARGET_ESP32S2)
  58. target_link_libraries(${COMPONENT_LIB} INTERFACE $<TARGET_FILE:${esp_phy_lib}> libphy.a
  59. $<TARGET_FILE:${esp_phy_lib}>)
  60. elseif(CONFIG_SOC_BT_SUPPORTED OR CONFIG_SOC_IEEE802154_SUPPORTED)
  61. target_link_libraries(${COMPONENT_LIB} PUBLIC btbb)
  62. target_link_libraries(${COMPONENT_LIB} INTERFACE $<TARGET_FILE:${esp_phy_lib}> libphy.a libbtbb.a
  63. $<TARGET_FILE:${esp_phy_lib}>)
  64. endif()
  65. if(CONFIG_ESP_PHY_ENABLE_CERT_TEST)
  66. target_link_libraries(${COMPONENT_LIB} INTERFACE $<TARGET_FILE:${esp_phy_lib}> libbttestmode.a
  67. librfate.a librftest.a $<TARGET_FILE:${esp_phy_lib}>)
  68. endif()
  69. endif()
  70. if(CONFIG_ESP_PHY_INIT_DATA_IN_PARTITION)
  71. idf_component_get_property(esp_common_dir esp_common COMPONENT_DIR)
  72. partition_table_get_partition_info(phy_partition_offset "--partition-type data --partition-subtype phy" "offset")
  73. if(CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN)
  74. set(phy_init_data_bin "${build_dir}/phy_multiple_init_data.bin")
  75. if(CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN_EMBED)
  76. set(COMPONENT_EMBED_FILES "${build_dir}/phy_multiple_init_data.bin")
  77. endif()
  78. else()
  79. set(phy_init_data_bin "${build_dir}/phy_init_data.bin")
  80. # To get the phy_init_data.bin file, compile phy_init_data.h as a C file and then objcopy
  81. # the object file to a raw binary
  82. idf_build_get_property(config_dir CONFIG_DIR)
  83. add_custom_command(
  84. OUTPUT ${phy_init_data_bin}
  85. DEPENDS ${CMAKE_CURRENT_LIST_DIR}/${idf_target}/include/phy_init_data.h
  86. COMMAND ${CMAKE_C_COMPILER} -x c -c
  87. -I ${esp_common_dir}/include -I ${CMAKE_CURRENT_LIST_DIR}/include -I ${config_dir}
  88. -o phy_init_data.obj
  89. ${CMAKE_CURRENT_LIST_DIR}/${idf_target}/include/phy_init_data.h
  90. COMMAND ${CMAKE_OBJCOPY} -O binary phy_init_data.obj ${phy_init_data_bin}
  91. )
  92. add_custom_target(phy_init_data ALL DEPENDS ${phy_init_data_bin})
  93. add_dependencies(flash phy_init_data)
  94. idf_component_get_property(main_args esptool_py FLASH_ARGS)
  95. idf_component_get_property(sub_args esptool_py FLASH_SUB_ARGS)
  96. endif()
  97. set(phy_name "phy")
  98. esptool_py_flash_target(${phy_name}-flash "${main_args}" "${sub_args}")
  99. esptool_py_flash_target_image(${phy_name}-flash ${phy_name} "${phy_partition_offset}" "${phy_init_data_bin}")
  100. esptool_py_flash_target_image(flash ${phy_name} "${phy_partition_offset}" "${phy_init_data_bin}")
  101. endif()