Perform an entire chip erase for UPDI targets, in preparation for programming
This commit is contained in:
@@ -325,42 +325,48 @@ namespace Bloom::Targets::Microchip::Avr::Avr8Bit
|
||||
void Avr8::writeMemory(TargetMemoryType memoryType, std::uint32_t startAddress, const TargetMemoryBuffer& buffer) {
|
||||
if (
|
||||
memoryType == TargetMemoryType::FLASH && this->programmingSession.has_value()
|
||||
&& this->targetConfig->physicalInterface == PhysicalInterface::PDI
|
||||
&& this->targetConfig->physicalInterface != PhysicalInterface::DEBUG_WIRE
|
||||
) {
|
||||
// For PDI targets, we must erase the appropriate section before the first write.
|
||||
const auto startSection = this->getProgramMemorySectionFromAddress(startAddress);
|
||||
const auto endSection = this->getProgramMemorySectionFromAddress(
|
||||
static_cast<std::uint32_t>(startAddress + buffer.size() - 1)
|
||||
);
|
||||
|
||||
if (startSection != endSection) {
|
||||
throw Exception(
|
||||
"Requested program memory write spans more than one section (APPLICATION and BOOT) - aborting."
|
||||
if (this->targetConfig->physicalInterface == PhysicalInterface::PDI) {
|
||||
const auto startSection = this->getProgramMemorySectionFromAddress(startAddress);
|
||||
const auto endSection = this->getProgramMemorySectionFromAddress(
|
||||
static_cast<std::uint32_t>(startAddress + buffer.size() - 1)
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
!this->programmingSession->applicationSectionErased
|
||||
&& (
|
||||
startSection == ProgramMemorySection::APPLICATION
|
||||
|| endSection == ProgramMemorySection::APPLICATION
|
||||
)
|
||||
) {
|
||||
Logger::warning("Erasing program memory APPLICATION section, in preparation for writing.");
|
||||
this->avr8DebugInterface->eraseProgramMemorySection(ProgramMemorySection::APPLICATION);
|
||||
this->programmingSession->applicationSectionErased = true;
|
||||
}
|
||||
if (startSection != endSection) {
|
||||
throw Exception(
|
||||
"Requested program memory write spans more than one section (APPLICATION and BOOT) - aborting."
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
!this->programmingSession->bootSectionErased
|
||||
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 writing.");
|
||||
this->avr8DebugInterface->eraseProgramMemorySection(ProgramMemorySection::BOOT);
|
||||
this->programmingSession->bootSectionErased = true;
|
||||
) {
|
||||
Logger::warning("Erasing program memory BOOT section, in preparation for programming.");
|
||||
this->avr8DebugInterface->eraseProgramMemory(ProgramMemorySection::BOOT);
|
||||
this->programmingSession->bootSectionErased = true;
|
||||
}
|
||||
|
||||
} else if (!this->programmingSession->chipErased) {
|
||||
Logger::warning("Erasing entire chip, in preparation for programming.");
|
||||
this->avr8DebugInterface->eraseProgramMemory();
|
||||
this->programmingSession->chipErased = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -962,7 +968,8 @@ namespace Bloom::Targets::Microchip::Avr::Avr8Bit
|
||||
}
|
||||
|
||||
ProgramMemorySection Avr8::getProgramMemorySectionFromAddress(std::uint32_t address) {
|
||||
return address >= this->targetParameters->bootSectionStartAddress.value()
|
||||
return this->targetParameters->bootSectionStartAddress.has_value()
|
||||
&& address >= this->targetParameters->bootSectionStartAddress.value()
|
||||
? ProgramMemorySection::BOOT
|
||||
: ProgramMemorySection::APPLICATION;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace Bloom::Targets::Microchip::Avr::Avr8Bit
|
||||
{
|
||||
struct ProgrammingSession
|
||||
{
|
||||
bool chipErased = false;
|
||||
bool applicationSectionErased = false;
|
||||
bool bootSectionErased = false;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user