Refactored the preserveEeprom implementation to make use of the EESAVE fuse

This commit is contained in:
Nav
2023-05-26 22:45:57 +01:00
parent 6aca0731b2
commit 1f90f21870
6 changed files with 172 additions and 35 deletions

View File

@@ -787,28 +787,10 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
return;
}
/*
* For JTAG and UPDI targets, the erase command can only erase the entire chip (including EEPROM). This
* violates the Avr8DebugInterface contract - as this member function should only ever erase program memory.
*
* All we can do here is take a copy of EEPROM and restore it after the erase operation.
*
* TODO: Look into setting the EESAVE fuse bit as an alternative to the backup-then-restore approach.
*/
auto eepromSnapshot = std::optional<Targets::TargetMemoryBuffer>();
if (this->targetConfig.preserveEeprom) {
Logger::debug("Capturing EEPROM data, in preparation for chip erase");
eepromSnapshot = this->readMemory(
TargetMemoryType::EEPROM,
this->targetParameters.eepromStartAddress.value(),
this->targetParameters.eepromSize.value()
);
} else {
Logger::warning("EEPROM will be erased - use the 'preserveEeprom' parameter to preserve EEPROM");
}
throw Exception("JTAG and UPDI targets do not support program memory erase.");
}
void EdbgAvr8Interface::eraseChip() {
const auto responseFrame = this->edbgInterface->sendAvrCommandFrameAndWaitForResponseFrame(
EraseMemory(Avr8EraseMemoryMode::CHIP)
);
@@ -816,15 +798,6 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
if (responseFrame.id == Avr8ResponseId::FAILED) {
throw Avr8CommandFailure("AVR8 erase memory command failed", responseFrame);
}
if (eepromSnapshot.has_value()) {
Logger::debug("Restoring EEPROM data");
this->writeMemory(
TargetMemoryType::EEPROM,
this->targetParameters.eepromStartAddress.value(),
std::move(*eepromSnapshot)
);
}
}
TargetState EdbgAvr8Interface::getTargetState() {

View File

@@ -233,7 +233,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
) override;
/**
* Issues the "Erase" command to erase a particular section of program memory, or the entire chip.
* Issues the "Erase" command to erase a particular section of program memory.
*
* @param section
*/
@@ -241,6 +241,11 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
std::optional<Targets::Microchip::Avr::Avr8Bit::ProgramMemorySection> section = std::nullopt
) override;
/**
* Issues the "Erase" command to erase the entire chip.
*/
void eraseChip() override;
/**
* Returns the current state of the target.
*

View File

@@ -184,6 +184,11 @@ namespace Bloom::DebugToolDrivers::TargetInterfaces::Microchip::Avr::Avr8
std::optional<Targets::Microchip::Avr::Avr8Bit::ProgramMemorySection> section = std::nullopt
) = 0;
/**
* Should erase the chip.
*/
virtual void eraseChip() = 0;
/**
* Should obtain the current target state.
*