From b3ccd8f7de580f5ea548e4314c1c30c96c6f5ca0 Mon Sep 17 00:00:00 2001 From: Nav Date: Sun, 11 Dec 2022 23:27:47 +0000 Subject: [PATCH] Removed automatic erasing when writing to flash memory on AVR8 targets --- src/Targets/Microchip/AVR/AVR8/Avr8.cpp | 71 +------------------------ src/Targets/Microchip/AVR/AVR8/Avr8.hpp | 8 --- 2 files changed, 2 insertions(+), 77 deletions(-) diff --git a/src/Targets/Microchip/AVR/AVR8/Avr8.cpp b/src/Targets/Microchip/AVR/AVR8/Avr8.cpp index 47c467b7..119fff43 100644 --- a/src/Targets/Microchip/AVR/AVR8/Avr8.cpp +++ b/src/Targets/Microchip/AVR/AVR8/Avr8.cpp @@ -367,8 +367,8 @@ namespace Bloom::Targets::Microchip::Avr::Avr8Bit } void Avr8::writeMemory(TargetMemoryType memoryType, std::uint32_t startAddress, const TargetMemoryBuffer& buffer) { - if (memoryType == TargetMemoryType::FLASH) { - return this->writeFlashMemory(startAddress, buffer); + if (memoryType == TargetMemoryType::FLASH && !this->programmingModeEnabled()) { + throw Exception("Attempted FLASH memory write with no active programming session."); } this->avr8DebugInterface->writeMemory(memoryType, startAddress, buffer); @@ -754,73 +754,6 @@ namespace Bloom::Targets::Microchip::Avr::Avr8Bit return this->id.value(); } - void Avr8::writeFlashMemory(TargetMemoryAddress startAddress, const TargetMemoryBuffer& buffer) { - if (!this->programmingSession.has_value()) { - throw Exception("Attempted FLASH memory write with no active programming session."); - } - - if (this->targetConfig->physicalInterface == PhysicalInterface::PDI) { - /* - * For PDI targets, we can erase specific sections (APPLICATION and BOOTLOADER sections) of program memory. - * - * We'll only erase the section if we intend to write to it. - */ - const auto startSection = this->getProgramMemorySectionFromAddress(startAddress); - const auto endSection = this->getProgramMemorySectionFromAddress( - static_cast(startAddress + buffer.size() - 1) - ); - - if (startSection != endSection) { - /* - * TODO: - * Get rid of this. Was placed here because I didn't have enough time to implement and test the - * writing to multiple sections in a single instance. - */ - throw Exception( - "Requested program memory write spans more than one section (APPLICATION and BOOT) - aborting" - ); - } - - if ( - !this->programmingSession->applicationSectionErased - && ( - startSection == ProgramMemorySection::APPLICATION - || endSection == ProgramMemorySection::APPLICATION - ) - ) { - Logger::warning("Erasing program memory APPLICATION section, in preparation for programming"); - this->avr8DebugInterface->eraseProgramMemory(ProgramMemorySection::APPLICATION); - this->programmingSession->applicationSectionErased = true; - } - - if ( - !this->programmingSession->bootSectionErased - && ( - startSection == ProgramMemorySection::BOOT - || endSection == ProgramMemorySection::BOOT - ) - ) { - Logger::warning("Erasing program memory BOOT section, in preparation for programming"); - this->avr8DebugInterface->eraseProgramMemory(ProgramMemorySection::BOOT); - this->programmingSession->bootSectionErased = true; - } - - this->programmingSession->chipErased = true; - } - - // debugWire targets do not need to be erased - this is done automatically when writing to FLASH. - if ( - this->targetConfig->physicalInterface != PhysicalInterface::DEBUG_WIRE - && !this->programmingSession->chipErased - ) { - Logger::warning("Erasing entire chip, in preparation for programming"); - this->avr8DebugInterface->eraseProgramMemory(); - this->programmingSession->chipErased = true; - } - - return this->avr8DebugInterface->writeMemory(TargetMemoryType::FLASH, startAddress, buffer); - } - void Avr8::updateDwenFuseBit(bool enable) { if (this->avrIspInterface == nullptr) { throw Exception( diff --git a/src/Targets/Microchip/AVR/AVR8/Avr8.hpp b/src/Targets/Microchip/AVR/AVR8/Avr8.hpp index 44bc819c..4bb9df2c 100644 --- a/src/Targets/Microchip/AVR/AVR8/Avr8.hpp +++ b/src/Targets/Microchip/AVR/AVR8/Avr8.hpp @@ -175,14 +175,6 @@ namespace Bloom::Targets::Microchip::Avr::Avr8Bit */ TargetSignature getId() override; - /** - * Writes to FLASH memory (with any necessary erasing). - * - * @param startAddress - * @param buffer - */ - void writeFlashMemory(TargetMemoryAddress startAddress, const TargetMemoryBuffer& buffer); - /** * Updates the debugWire enable (DWEN) fuse bit on the AVR target. *