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() {