From d6b216d51ea204c424eecf9d12c159c7f81add2d Mon Sep 17 00:00:00 2001 From: Nav Date: Sun, 26 Nov 2023 00:41:45 +0000 Subject: [PATCH] Send "end process" command to detach from target, upon deactivaition of WCH-Link debug tools --- .../WchLink/Commands/Control/DetachTarget.hpp | 20 +++++++++++++++++++ .../Protocols/WchLink/WchLinkInterface.cpp | 7 ++++++- 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 src/DebugToolDrivers/WCH/Protocols/WchLink/Commands/Control/DetachTarget.hpp diff --git a/src/DebugToolDrivers/WCH/Protocols/WchLink/Commands/Control/DetachTarget.hpp b/src/DebugToolDrivers/WCH/Protocols/WchLink/Commands/Control/DetachTarget.hpp new file mode 100644 index 00000000..246198e6 --- /dev/null +++ b/src/DebugToolDrivers/WCH/Protocols/WchLink/Commands/Control/DetachTarget.hpp @@ -0,0 +1,20 @@ +#pragma once + +#include + +#include "src/DebugToolDrivers/WCH/Protocols/WchLink/Commands/Command.hpp" + +namespace DebugToolDrivers::Wch::Protocols::WchLink::Commands::Control +{ + class DetachTarget: public Command> + { + public: + DetachTarget() + : Command(0x0d) + { + this->payload = { + 0xff + }; + } + }; +} diff --git a/src/DebugToolDrivers/WCH/Protocols/WchLink/WchLinkInterface.cpp b/src/DebugToolDrivers/WCH/Protocols/WchLink/WchLinkInterface.cpp index 0dfff372..59495440 100644 --- a/src/DebugToolDrivers/WCH/Protocols/WchLink/WchLinkInterface.cpp +++ b/src/DebugToolDrivers/WCH/Protocols/WchLink/WchLinkInterface.cpp @@ -4,6 +4,7 @@ #include "Commands/Control/GetDeviceInfo.hpp" #include "Commands/Control/AttachTarget.hpp" +#include "Commands/Control/DetachTarget.hpp" #include "Commands/SetClockSpeed.hpp" #include "Commands/DebugModuleInterfaceOperation.hpp" @@ -63,7 +64,11 @@ namespace DebugToolDrivers::Wch::Protocols::WchLink } void WchLinkInterface::deactivate() { - // TODO: implement this + const auto response = this->sendCommandAndWaitForResponse(Commands::Control::DetachTarget()); + + if (response.payload.size() != 1) { + throw Exceptions::DeviceCommunicationFailure("Unexpected response payload size for DetachTarget command"); + } } std::string WchLinkInterface::getDeviceId() {