diff --git a/src/DebugToolDrivers/Microchip/Protocols/EDBG/AVR/EdbgAvr8Interface.cpp b/src/DebugToolDrivers/Microchip/Protocols/EDBG/AVR/EdbgAvr8Interface.cpp index cc129ffe..cf8f10b7 100644 --- a/src/DebugToolDrivers/Microchip/Protocols/EDBG/AVR/EdbgAvr8Interface.cpp +++ b/src/DebugToolDrivers/Microchip/Protocols/EDBG/AVR/EdbgAvr8Interface.cpp @@ -720,7 +720,20 @@ namespace DebugToolDrivers::Microchip::Protocols::Edbg::Avr return this->readMemory(Avr8MemoryType::EEPROM, startAddress, bytes, excludedAddresses); } - if (memorySegmentDescriptor.type == TargetMemorySegmentType::FUSES) { + if ( + memorySegmentDescriptor.type == TargetMemorySegmentType::FUSES + && this->programmingModeEnabled + && this->session.configVariant != Avr8ConfigVariant::DEBUG_WIRE + ) { + if (this->session.configVariant == Avr8ConfigVariant::XMEGA) { + return this->readMemory( + Avr8MemoryType::FUSES, + startAddress - this->session.fuseMemorySegment.startAddress, + bytes, + excludedAddresses + ); + } + return this->readMemory(Avr8MemoryType::FUSES, startAddress, bytes, excludedAddresses); } @@ -790,7 +803,20 @@ namespace DebugToolDrivers::Microchip::Protocols::Edbg::Avr return this->writeMemory(Avr8MemoryType::EEPROM, startAddress, buffer); } - if (memorySegmentDescriptor.type == TargetMemorySegmentType::FUSES) { + if ( + memorySegmentDescriptor.type == TargetMemorySegmentType::FUSES + && this->programmingModeEnabled + && this->session.configVariant != Avr8ConfigVariant::DEBUG_WIRE + ) { + if (this->session.configVariant == Avr8ConfigVariant::XMEGA) { + // Fuse addresses should be in relative form, for XMEGA (PDI) targets + return this->writeMemory( + Avr8MemoryType::FUSES, + startAddress - this->session.fuseMemorySegment.startAddress, + buffer + ); + } + return this->writeMemory(Avr8MemoryType::FUSES, startAddress, buffer); } diff --git a/src/DebugToolDrivers/Microchip/Protocols/EDBG/AVR/EdbgAvr8Session.cpp b/src/DebugToolDrivers/Microchip/Protocols/EDBG/AVR/EdbgAvr8Session.cpp index f6a4c310..86e9f6b5 100644 --- a/src/DebugToolDrivers/Microchip/Protocols/EDBG/AVR/EdbgAvr8Session.cpp +++ b/src/DebugToolDrivers/Microchip/Protocols/EDBG/AVR/EdbgAvr8Session.cpp @@ -22,6 +22,7 @@ namespace DebugToolDrivers::Microchip::Protocols::Edbg::Avr , ramMemorySegment(this->targetDescriptionFile.getRamMemorySegment()) , eepromMemorySegment(this->targetDescriptionFile.getEepromMemorySegment()) , ioMemorySegment(this->targetDescriptionFile.getIoMemorySegment()) + , fuseMemorySegment(this->targetDescriptionFile.getFuseMemorySegment()) , signatureMemorySegment(this->targetDescriptionFile.getSignatureMemorySegment()) , programAppSection(this->programMemorySegment.tryGetSection("app_section")) , programBootSection(this->programMemorySegment.tryGetSection("boot_section")) diff --git a/src/DebugToolDrivers/Microchip/Protocols/EDBG/AVR/EdbgAvr8Session.hpp b/src/DebugToolDrivers/Microchip/Protocols/EDBG/AVR/EdbgAvr8Session.hpp index 65375e52..6bba9691 100644 --- a/src/DebugToolDrivers/Microchip/Protocols/EDBG/AVR/EdbgAvr8Session.hpp +++ b/src/DebugToolDrivers/Microchip/Protocols/EDBG/AVR/EdbgAvr8Session.hpp @@ -47,6 +47,7 @@ namespace DebugToolDrivers::Microchip::Protocols::Edbg::Avr const Targets::TargetDescription::MemorySegment& ramMemorySegment; const Targets::TargetDescription::MemorySegment& eepromMemorySegment; const Targets::TargetDescription::MemorySegment& ioMemorySegment; + const Targets::TargetDescription::MemorySegment& fuseMemorySegment; const Targets::TargetDescription::MemorySegment& signatureMemorySegment; const std::optional<