From f0225dba882c35f18829d077ff3651f8cc328b4d Mon Sep 17 00:00:00 2001 From: Nav Date: Sun, 11 Dec 2022 23:36:21 +0000 Subject: [PATCH] Fixed bug (in EDBG driver) with `writeMemory()` forwarding an invalid memory type to `readMemory()` (EEPROM_ATOMIC can only be used for writing to memory, not reading) --- .../VendorSpecific/EDBG/AVR/EdbgAvr8Interface.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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 3c83d610..aafcc59d 100644 --- a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/EdbgAvr8Interface.cpp +++ b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/EdbgAvr8Interface.cpp @@ -1809,7 +1809,15 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr const auto alignedBytes = this->alignMemoryBytes(type, bytes + (startAddress - alignedStartAddress)); if (alignedStartAddress != startAddress || alignedBytes != bytes) { - auto alignedBuffer = this->readMemory(type, alignedStartAddress, alignedBytes); + /* + * We can't just forward the memory type to readMemory(), because some memory types (such as + * EEPROM_ATOMIC) can only be used for writing. + * + * This nasty hack will have to do for now. + */ + const auto readMemoryType = type == Avr8MemoryType::EEPROM_ATOMIC ? Avr8MemoryType::EEPROM : type; + + auto alignedBuffer = this->readMemory(readMemoryType, alignedStartAddress, alignedBytes); assert(alignedBuffer.size() >= buffer.size()); const auto offset = alignedBuffer.begin() + (startAddress - alignedStartAddress);