Removed automatic erasing when writing to flash memory on AVR8 targets
This commit is contained in:
@@ -367,8 +367,8 @@ namespace Bloom::Targets::Microchip::Avr::Avr8Bit
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Avr8::writeMemory(TargetMemoryType memoryType, std::uint32_t startAddress, const TargetMemoryBuffer& buffer) {
|
void Avr8::writeMemory(TargetMemoryType memoryType, std::uint32_t startAddress, const TargetMemoryBuffer& buffer) {
|
||||||
if (memoryType == TargetMemoryType::FLASH) {
|
if (memoryType == TargetMemoryType::FLASH && !this->programmingModeEnabled()) {
|
||||||
return this->writeFlashMemory(startAddress, buffer);
|
throw Exception("Attempted FLASH memory write with no active programming session.");
|
||||||
}
|
}
|
||||||
|
|
||||||
this->avr8DebugInterface->writeMemory(memoryType, startAddress, buffer);
|
this->avr8DebugInterface->writeMemory(memoryType, startAddress, buffer);
|
||||||
@@ -754,73 +754,6 @@ namespace Bloom::Targets::Microchip::Avr::Avr8Bit
|
|||||||
return this->id.value();
|
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<std::uint32_t>(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) {
|
void Avr8::updateDwenFuseBit(bool enable) {
|
||||||
if (this->avrIspInterface == nullptr) {
|
if (this->avrIspInterface == nullptr) {
|
||||||
throw Exception(
|
throw Exception(
|
||||||
|
|||||||
@@ -175,14 +175,6 @@ namespace Bloom::Targets::Microchip::Avr::Avr8Bit
|
|||||||
*/
|
*/
|
||||||
TargetSignature getId() override;
|
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.
|
* Updates the debugWire enable (DWEN) fuse bit on the AVR target.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user