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 4183f484..d7803567 100644 --- a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/EdbgAvr8Interface.cpp +++ b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/EdbgAvr8Interface.cpp @@ -4,11 +4,13 @@ #include #include +#include "src/Logger/Logger.hpp" +#include "src/Helpers/Paths.hpp" + #include "src/Exceptions/InvalidConfig.hpp" #include "src/TargetController/Exceptions/DeviceInitializationFailure.hpp" #include "src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/Exceptions/Avr8CommandFailure.hpp" -#include "src/Logger/Logger.hpp" -#include "src/Helpers/Paths.hpp" +#include "src/Targets/Microchip/AVR/AVR8/Exceptions/DebugWirePhysicalInterfaceError.hpp" // Command frames #include "src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/SetParameter.hpp" @@ -219,7 +221,21 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr void EdbgAvr8Interface::activate() { if (!this->physicalInterfaceActivated) { - this->activatePhysical(); + try { + this->activatePhysical(); + + } catch (const Avr8CommandFailure& activationException) { + if (this->physicalInterface == PhysicalInterface::DEBUG_WIRE + && activationException.code == Avr8CommandFailureCode::DEBUGWIRE_PHYSICAL_ERROR + ) { + throw DebugWirePhysicalInterfaceError( + "Failed to activate the debugWire physical interface - check target connection. " + "The target's DWEN fuse bit may need to be updated. See [TODO_ADD_LINK] for more information." + ); + } + + throw activationException; + } } if (!this->targetAttached) { diff --git a/src/DebugToolDrivers/TargetInterfaces/Microchip/AVR/AVR8/Avr8DebugInterface.hpp b/src/DebugToolDrivers/TargetInterfaces/Microchip/AVR/AVR8/Avr8DebugInterface.hpp index feec4e58..2c3d6ef1 100644 --- a/src/DebugToolDrivers/TargetInterfaces/Microchip/AVR/AVR8/Avr8DebugInterface.hpp +++ b/src/DebugToolDrivers/TargetInterfaces/Microchip/AVR/AVR8/Avr8DebugInterface.hpp @@ -102,6 +102,10 @@ namespace Bloom::DebugToolDrivers::TargetInterfaces::Microchip::Avr::Avr8 /** * Should activate the physical interface between the debug tool and the AVR8 target. + * + * If the debugWire interface has been selected - this function should throw a DebugWirePhysicalInterfaceError + * exception, in the event of a failure when activating the interface. The reason for this is to allow us the + * chance to check the DWEN fuse bit, via an ISP interface. See Avr8::activate() for more. */ virtual void activate() = 0; diff --git a/src/Exceptions/Exception.hpp b/src/Exceptions/Exception.hpp index 2c93ee0c..216a739a 100644 --- a/src/Exceptions/Exception.hpp +++ b/src/Exceptions/Exception.hpp @@ -8,6 +8,13 @@ namespace Bloom::Exceptions { public: explicit Exception(): std::runtime_error("") {} + virtual ~Exception() = default; + + Exception(const Exception& other) noexcept = default; + Exception(Exception&& other) = default; + + Exception& operator = (const Exception& other) = default; + Exception& operator = (Exception&& other) = default; explicit Exception(const std::string& message): std::runtime_error(message.c_str()), message(message) {} diff --git a/src/Targets/Microchip/AVR/AVR8/Exceptions/DebugWirePhysicalInterfaceError.hpp b/src/Targets/Microchip/AVR/AVR8/Exceptions/DebugWirePhysicalInterfaceError.hpp new file mode 100644 index 00000000..3c29d1eb --- /dev/null +++ b/src/Targets/Microchip/AVR/AVR8/Exceptions/DebugWirePhysicalInterfaceError.hpp @@ -0,0 +1,18 @@ +#pragma once + +#include "src/TargetController/Exceptions/TargetOperationFailure.hpp" + +namespace Bloom::Exceptions +{ + class DebugWirePhysicalInterfaceError: public TargetOperationFailure + { + public: + explicit DebugWirePhysicalInterfaceError(const std::string& message): TargetOperationFailure(message) { + this->message = message; + } + + explicit DebugWirePhysicalInterfaceError(const char* message): TargetOperationFailure(message) { + this->message = std::string(message); + } + }; +}