CMakeLists.txt 4.6 KB

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