diff --git a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/EnterProgrammingMode.hpp b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/EnterProgrammingMode.hpp new file mode 100644 index 00000000..cc9b6df7 --- /dev/null +++ b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/EnterProgrammingMode.hpp @@ -0,0 +1,22 @@ +#pragma once + +#include "Avr8GenericCommandFrame.hpp" + +namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames::Avr8Generic +{ + class EnterProgrammingMode: public Avr8GenericCommandFrame> + { + public: + EnterProgrammingMode() { + /* + * The enter programming mode command consists of 2 bytes: + * 1. Command ID (0x15) + * 2. Version (0x00) + */ + this->payload = { + 0x15, + 0x00 + }; + } + }; +} diff --git a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/LeaveProgrammingMode.hpp b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/LeaveProgrammingMode.hpp new file mode 100644 index 00000000..19d899c3 --- /dev/null +++ b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/LeaveProgrammingMode.hpp @@ -0,0 +1,22 @@ +#pragma once + +#include "Avr8GenericCommandFrame.hpp" + +namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames::Avr8Generic +{ + class LeaveProgrammingMode: public Avr8GenericCommandFrame> + { + public: + LeaveProgrammingMode() { + /* + * The leave programming mode command consists of 2 bytes: + * 1. Command ID (0x16) + * 2. Version (0x00) + */ + this->payload = { + 0x16, + 0x00 + }; + } + }; +} 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 a3cd2600..6e5a8573 100644 --- a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/EdbgAvr8Interface.cpp +++ b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/EdbgAvr8Interface.cpp @@ -34,6 +34,8 @@ #include "src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/SetXmegaSoftwareBreakpoint.hpp" #include "src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/ClearAllSoftwareBreakpoints.hpp" #include "src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/ClearSoftwareBreakpoints.hpp" +#include "src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/EnterProgrammingMode.hpp" +#include "src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/LeaveProgrammingMode.hpp" // AVR events #include "src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/Events/AVR8Generic/BreakEvent.hpp" @@ -676,6 +678,26 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr return this->targetState; } + void EdbgAvr8Interface::enableProgrammingMode() { + auto response = this->edbgInterface.sendAvrCommandFrameAndWaitForResponseFrame( + CommandFrames::Avr8Generic::EnterProgrammingMode() + ); + + if (response.getResponseId() == Avr8ResponseId::FAILED) { + throw Avr8CommandFailure("Failed to enter programming mode on EDBG debug tool", response); + } + } + + void EdbgAvr8Interface::disableProgrammingMode() { + auto response = this->edbgInterface.sendAvrCommandFrameAndWaitForResponseFrame( + CommandFrames::Avr8Generic::LeaveProgrammingMode() + ); + + if (response.getResponseId() == Avr8ResponseId::FAILED) { + throw Avr8CommandFailure("Failed to leave programming mode on EDBG debug tool", response); + } + } + void EdbgAvr8Interface::setParameter(const Avr8EdbgParameter& parameter, const std::vector& value) { auto commandFrame = CommandFrames::Avr8Generic::SetParameter(parameter, value); diff --git a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/EdbgAvr8Interface.hpp b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/EdbgAvr8Interface.hpp index fff07d1d..b7bbe525 100644 --- a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/EdbgAvr8Interface.hpp +++ b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/EdbgAvr8Interface.hpp @@ -250,6 +250,16 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr */ Targets::TargetState getTargetState() override; + /** + * Enters programming mode on the EDBG debug tool. + */ + void enableProgrammingMode() override; + + /** + * Leaves programming mode on the EDBG debug tool. + */ + void disableProgrammingMode() override; + private: /** * The AVR8 Generic protocol is a sub-protocol of the EDBG AVR protocol, which is served via CMSIS-DAP vendor