From 131f1aa2496142690264521e1a6669dfd77776bd Mon Sep 17 00:00:00 2001 From: Nav Date: Sun, 11 Dec 2022 23:34:20 +0000 Subject: [PATCH] Added EEPROM_PAGE EDBG memory type and aligned both EEPROM_PAGE and EEPROM_ATOMIC memory types --- .../VendorSpecific/EDBG/AVR/Avr8Generic.hpp | 6 ++++ .../EDBG/AVR/EdbgAvr8Interface.cpp | 33 +++++++++++++++---- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/Avr8Generic.hpp b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/Avr8Generic.hpp index 12456038..beeb42a3 100644 --- a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/Avr8Generic.hpp +++ b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/Avr8Generic.hpp @@ -139,6 +139,12 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr */ EEPROM_ATOMIC = 0xC4, + /** + * The EEPROM_PAGE memory type can be used to read and write to EEPROM whilst the target is in + * programming mode. + */ + EEPROM_PAGE = 0xB1, + /** * The FLASH_PAGE memory type can be used to read and write full flash pages on the target. * 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 576355f1..3c83d610 100644 --- a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/EdbgAvr8Interface.cpp +++ b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/EdbgAvr8Interface.cpp @@ -624,10 +624,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr TargetMemorySize bytes, const std::set& excludedAddressRanges ) { - if ( - this->programmingModeEnabled - && (memoryType == TargetMemoryType::RAM || memoryType == TargetMemoryType::EEPROM) - ) { + if (this->programmingModeEnabled && memoryType == TargetMemoryType::RAM) { throw Exception("Cannot access RAM or EEPROM when programming mode is enabled"); } @@ -666,7 +663,10 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr break; } case TargetMemoryType::EEPROM: { - avr8MemoryType = Avr8MemoryType::EEPROM; + // For JTAG targets, we must use the EEPROM_PAGE memory type when in programming mode. + avr8MemoryType = (this->configVariant == Avr8ConfigVariant::MEGAJTAG && this->programmingModeEnabled) + ? Avr8MemoryType::EEPROM_PAGE + : Avr8MemoryType::EEPROM; } default: { break; @@ -1535,6 +1535,8 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr || memoryType == Avr8MemoryType::SPM || memoryType == Avr8MemoryType::APPL_FLASH || memoryType == Avr8MemoryType::BOOT_FLASH + || memoryType == Avr8MemoryType::EEPROM_ATOMIC + || memoryType == Avr8MemoryType::EEPROM_PAGE ; } @@ -1553,6 +1555,13 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr alignTo = this->targetParameters.flashPageSize.value(); } + if ( + memoryType == Avr8MemoryType::EEPROM_ATOMIC + || memoryType == Avr8MemoryType::EEPROM_PAGE + ) { + alignTo = this->targetParameters.eepromPageSize.value(); + } + if (this->maximumMemoryAccessSizePerRequest.has_value() && alignTo > this->maximumMemoryAccessSizePerRequest) { throw Exception( "Cannot align memory address - alignment size exceeds the maximum memory access size per request." @@ -1583,6 +1592,13 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr alignTo = this->targetParameters.flashPageSize.value(); } + if ( + memoryType == Avr8MemoryType::EEPROM_ATOMIC + || memoryType == Avr8MemoryType::EEPROM_PAGE + ) { + alignTo = this->targetParameters.eepromPageSize.value(); + } + if ((bytes % alignTo) != 0) { return static_cast(std::ceil( static_cast(bytes) / static_cast(alignTo) @@ -1603,8 +1619,11 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr return this->targetParameters.flashPageSize.value(); } - if (memoryType == Avr8MemoryType::EEPROM_ATOMIC) { - // This EEPROM memory type requires single page access. + if ( + memoryType == Avr8MemoryType::EEPROM_ATOMIC + || memoryType == Avr8MemoryType::EEPROM_PAGE + ) { + // These EEPROM memory types requires single page access. return this->targetParameters.eepromPageSize.value(); }