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 7672adbf..fdb01723 100644 --- a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/EdbgAvr8Interface.cpp +++ b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/EdbgAvr8Interface.cpp @@ -1571,6 +1571,14 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr case Avr8MemoryType::SPM: case Avr8MemoryType::APPL_FLASH: case Avr8MemoryType::BOOT_FLASH: { + /* + * Although the EDBG documentation claims any number of bytes can be accessed via the FLASH_PAGE mem + * type, when using the UPDI config variant, this isn't strictly true. + * + * When writing to flash on UPDI targets, we MUST page align the write operations. And we cannot word + * align them - we've tried only word aligning them - the debug tool reports a "Too many or too few + * bytes" error. + */ alignTo = this->targetParameters.flashPageSize.value(); break; } @@ -1610,6 +1618,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr case Avr8MemoryType::SPM: case Avr8MemoryType::APPL_FLASH: case Avr8MemoryType::BOOT_FLASH: { + // See comment in EdbgAvr8Interface::alignMemoryAddress() alignTo = this->targetParameters.flashPageSize.value(); break; } @@ -1779,7 +1788,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr */ const auto singlePacketSize = static_cast(this->edbgInterface->getUsbHidInputReportSize() - 20); const auto totalResponsePackets = std::ceil(static_cast(bytes) / static_cast(singlePacketSize)); - const auto totalReadsRequired = std::ceil(static_cast(totalResponsePackets) / 2); + const auto totalReadsRequired = static_cast(std::ceil(static_cast(totalResponsePackets) / 2)); if (totalResponsePackets > 2) { /* @@ -1788,7 +1797,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr */ auto output = TargetMemoryBuffer(); - for (float i = 1; i <= totalReadsRequired; i++) { + for (auto i = 1; i <= totalReadsRequired; i++) { const auto bytesToRead = static_cast( (bytes - output.size()) > (singlePacketSize * 2) ? (singlePacketSize * 2) : bytes - output.size() diff --git a/src/Targets/Microchip/AVR/AVR8/Avr8.hpp b/src/Targets/Microchip/AVR/AVR8/Avr8.hpp index 4bb9df2c..dab65241 100644 --- a/src/Targets/Microchip/AVR/AVR8/Avr8.hpp +++ b/src/Targets/Microchip/AVR/AVR8/Avr8.hpp @@ -186,6 +186,8 @@ namespace Bloom::Targets::Microchip::Avr::Avr8Bit /** * Resolves the program memory section from a program memory address. * + * Currently unused, but will be needed soon. + * * @param address * @return */