From 6907b79880f291648a7187be93aee2bb829d14a6 Mon Sep 17 00:00:00 2001 From: Nav Date: Tue, 31 Aug 2021 19:45:05 +0100 Subject: [PATCH] Flipped multi-byte AVR8 register values in AVR8 EDBG driver (AVR8 registers are stored LSB, so they needed to be flipped to MSB) --- .../EDBG/AVR/EdbgAvr8Interface.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) 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 ddf3d830..194ac36a 100644 --- a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/EdbgAvr8Interface.cpp +++ b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/EdbgAvr8Interface.cpp @@ -1239,11 +1239,21 @@ TargetRegisters EdbgAvr8Interface::readRegisters(const TargetRegisterDescriptors // Construct our TargetRegister objects directly from the flat memory buffer for (const auto& descriptor : descriptors) { - const auto bufferStartIt = flatMemoryBuffer.begin() + (descriptor->startAddress.value() - startAddress); + /* + * Multi-byte AVR8 registers are stored in LSB form. + * + * This is why we use reverse iterators when extracting our data from flatMemoryBuffer. Doing so allows + * us to extract the data in MSB form (as is expected for all register values held in TargetRegister + * objects). + */ + const auto bufferStartIt = flatMemoryBuffer.rend() - (descriptor->startAddress.value() - startAddress) + - descriptor->size; output.emplace_back( - TargetRegister(*descriptor, - TargetMemoryBuffer(bufferStartIt, bufferStartIt + descriptor->size)) + TargetRegister( + *descriptor, + TargetMemoryBuffer(bufferStartIt, bufferStartIt + descriptor->size) + ) ); } }