From 65bdcd62d3a4fd2970b4df5787c882e88a3fcd4f Mon Sep 17 00:00:00 2001 From: Nav Date: Sat, 17 Sep 2022 19:55:55 +0100 Subject: [PATCH] Enforce flash page alignment for UPDI targets, when accessing flash --- .../EDBG/AVR/EdbgAvr8Interface.cpp | 70 +++++-------------- 1 file changed, 16 insertions(+), 54 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 796a65a1..7ff8046f 100644 --- a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/EdbgAvr8Interface.cpp +++ b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/EdbgAvr8Interface.cpp @@ -1469,32 +1469,13 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr ) { std::uint16_t alignTo = 1; - // We don't have to align to the page size in all cases. We may only need to align to the word size (2 bytes). - switch (memoryType) { - case Avr8MemoryType::FLASH_PAGE: { - alignTo = (this->configVariant == Avr8ConfigVariant::UPDI) - ? 2 - : this->targetParameters.flashPageSize.value(); - break; - } - case Avr8MemoryType::SPM: { - // Memory access via the SPM type must be word aligned. - alignTo = 2; - } - case Avr8MemoryType::APPL_FLASH: - case Avr8MemoryType::BOOT_FLASH: { - if (this->configVariant == Avr8ConfigVariant::UPDI) { - // For UPDI sessions, memory access via the APPL_FLASH must be word aligned. - alignTo = 2; - - } else { - alignTo = this->targetParameters.flashPageSize.value(); - } - break; - } - default: { - break; - } + if ( + memoryType == Avr8MemoryType::FLASH_PAGE + || memoryType == Avr8MemoryType::SPM + || memoryType == Avr8MemoryType::APPL_FLASH + || memoryType == Avr8MemoryType::BOOT_FLASH + ) { + alignTo = this->targetParameters.flashPageSize.value(); } if (this->maximumMemoryAccessSizePerRequest.has_value() && alignTo > this->maximumMemoryAccessSizePerRequest) { @@ -1518,32 +1499,13 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr ) { std::uint16_t alignTo = 1; - // We don't have to align to the page size in all cases. We may only need to align to the word size (2 bytes). - switch (memoryType) { - case Avr8MemoryType::FLASH_PAGE: { - alignTo = (this->configVariant == Avr8ConfigVariant::UPDI) - ? 2 - : this->targetParameters.flashPageSize.value(); - break; - } - case Avr8MemoryType::SPM: { - // Memory access via the SPM type must be word aligned. - alignTo = 2; - } - case Avr8MemoryType::APPL_FLASH: - case Avr8MemoryType::BOOT_FLASH: { - if (this->configVariant == Avr8ConfigVariant::UPDI) { - // For UPDI sessions, memory access via the APPL_FLASH must be word aligned. - alignTo = 2; - - } else { - alignTo = this->targetParameters.flashPageSize.value(); - } - break; - } - default: { - break; - } + if ( + memoryType == Avr8MemoryType::FLASH_PAGE + || memoryType == Avr8MemoryType::SPM + || memoryType == Avr8MemoryType::APPL_FLASH + || memoryType == Avr8MemoryType::BOOT_FLASH + ) { + alignTo = this->targetParameters.flashPageSize.value(); } if ((bytes % alignTo) != 0) { @@ -1718,8 +1680,8 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr for (float i = 1; i <= totalReadsRequired; i++) { auto bytesToRead = static_cast( - (bytes - output.size()) > (singlePacketSize * 2) ? (singlePacketSize * 2) - : bytes - output.size() + (bytes - output.size()) > (singlePacketSize * 2) + ? (singlePacketSize * 2) : bytes - output.size() ); auto data = this->readMemory( type,