From 2282967e0dc0a2ec00b6fca38906948b1e47402b Mon Sep 17 00:00:00 2001 From: Nav Date: Sat, 24 Sep 2022 18:45:45 +0100 Subject: [PATCH] Fixed intermittent 'illegal target state' error from EDBG debug tools, when issuing commands immediately after target reset. --- .../VendorSpecific/EDBG/AVR/EdbgAvr8Interface.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/EdbgAvr8Interface.cpp b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/EdbgAvr8Interface.cpp index d2af1c50..0dc45201 100644 --- a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/EdbgAvr8Interface.cpp +++ b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/EdbgAvr8Interface.cpp @@ -262,6 +262,15 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr } catch (const Exception& exception) { throw Exception("Failed to reset AVR8 target - missing stopped event."); } + + /* + * Issuing another command immediately after reset sometimes results in an 'illegal target state' error from + * the EDBG debug tool. Even though we waited for the break event. + * + * All we can really do here is introduce a small delay, to ensure that we're not issuing commands too quickly + * after reset. + */ + std::this_thread::sleep_for(std::chrono::milliseconds(250)); } void EdbgAvr8Interface::activate() {