diff --git a/targets/TARGET_NUVOTON/CMakeLists.txt b/targets/TARGET_NUVOTON/CMakeLists.txt index 2119a105478..861aa00e707 100644 --- a/targets/TARGET_NUVOTON/CMakeLists.txt +++ b/targets/TARGET_NUVOTON/CMakeLists.txt @@ -27,3 +27,16 @@ target_sources(mbed-nuvoton target_link_libraries(mbed-nuvoton INTERFACE mbed-cmsis-cortex-m) +# PyOCD debug restart is failed without this somehow. It appears the device +# under debug must be halted after MBED_UPLOAD_RESTART_COMMANDS, but this is +# broken. Change to "monitor reset halt" to fix it. +function(mbed_upload_nuvoton_adjust_restart_command_for_pyocd target) + if(DEFINED MBED_UPLOAD_RESTART_COMMANDS AND + "${UPLOAD_METHOD}" STREQUAL "PYOCD") + set(MBED_UPLOAD_RESTART_COMMANDS "monitor reset halt" CACHE INTERNAL "" FORCE) + endif() +endfunction() + +function(mbed_adjust_upload_debug_commands target) + mbed_upload_nuvoton_adjust_restart_command_for_pyocd(${target}) +endfunction() diff --git a/tools/cmake/mbed_target_functions.cmake b/tools/cmake/mbed_target_functions.cmake index 11a8e203b98..c63c33c5789 100644 --- a/tools/cmake/mbed_target_functions.cmake +++ b/tools/cmake/mbed_target_functions.cmake @@ -169,6 +169,12 @@ function(mbed_set_post_build target) mbed_generate_map_file(${target}) endif() + # Give chance to adjust MBED_UPLOAD_LAUNCH_COMMANDS or MBED_UPLOAD_RESTART_COMMANDS + # for debug launch + if(COMMAND mbed_adjust_upload_debug_commands) + mbed_adjust_upload_debug_commands(${target}) + endif() + mbed_generate_upload_target(${target}) mbed_generate_ide_debug_configuration(${target}) endfunction()