1# Add DFU build and flashing related targets 2# 3 4function(__add_dfu_targets) 5 idf_build_get_property(target IDF_TARGET) 6 if("${target}" STREQUAL "esp32") 7 return() 8 elseif("${target}" STREQUAL "esp32s2") 9 set(dfu_pid "2") 10 elseif("${target}" STREQUAL "esp32s3") 11 set(dfu_pid "9") 12 elseif("${target}" STREQUAL "esp32c3") 13 return() 14 elseif("${target}" STREQUAL "esp32h2") 15 return() 16 elseif("${target}" STREQUAL "linux") 17 return() 18 else() 19 message(FATAL_ERROR "DFU PID unknown for ${target}") 20 endif() 21 22 idf_build_get_property(python PYTHON) 23 idf_build_get_property(idf_path IDF_PATH) 24 25 add_custom_target(dfu 26 COMMAND ${python} ${idf_path}/tools/mkdfu.py write 27 -o "${CMAKE_CURRENT_BINARY_DIR}/dfu.bin" 28 --json "${CMAKE_CURRENT_BINARY_DIR}/flasher_args.json" 29 --pid "${dfu_pid}" 30 DEPENDS gen_project_binary bootloader 31 VERBATIM 32 USES_TERMINAL) 33 34 add_custom_target(dfu-list 35 COMMAND ${CMAKE_COMMAND} 36 -D ESP_DFU_LIST="1" 37 -P ${idf_path}/tools/cmake/run_dfu_util.cmake 38 USES_TERMINAL) 39 40 add_custom_target(dfu-flash 41 COMMAND ${CMAKE_COMMAND} 42 -D ESP_DFU_BIN="${CMAKE_CURRENT_BINARY_DIR}/dfu.bin" 43 -D ESP_DFU_PID="${dfu_pid}" 44 -P ${idf_path}/tools/cmake/run_dfu_util.cmake 45 USES_TERMINAL) 46endfunction() 47