Added eraseProgramMemorySection() function to Avr8 debug interface - to erase XMEGA program memory sections when necessary
This commit is contained in:
@@ -323,6 +323,47 @@ 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
|
||||
) {
|
||||
// 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->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 (
|
||||
!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;
|
||||
}
|
||||
}
|
||||
|
||||
this->avr8DebugInterface->writeMemory(memoryType, startAddress, buffer);
|
||||
}
|
||||
|
||||
@@ -919,4 +960,10 @@ namespace Bloom::Targets::Microchip::Avr::Avr8Bit
|
||||
throw exception;
|
||||
}
|
||||
}
|
||||
|
||||
ProgramMemorySection Avr8::getProgramMemorySectionFromAddress(std::uint32_t address) {
|
||||
return address >= this->targetParameters->bootSectionStartAddress.value()
|
||||
? ProgramMemorySection::BOOT
|
||||
: ProgramMemorySection::APPLICATION;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "TargetParameters.hpp"
|
||||
#include "PadDescriptor.hpp"
|
||||
#include "ProgrammingSession.hpp"
|
||||
#include "ProgramMemorySection.hpp"
|
||||
#include "src/Targets/TargetRegister.hpp"
|
||||
|
||||
#include "TargetDescription/TargetDescriptionFile.hpp"
|
||||
@@ -182,5 +183,13 @@ namespace Bloom::Targets::Microchip::Avr::Avr8Bit
|
||||
* True to set the fuse, false to clear it.
|
||||
*/
|
||||
void writeDwenFuseBit(bool setFuse);
|
||||
|
||||
/**
|
||||
* Resolves the program memory section from a program memory address.
|
||||
*
|
||||
* @param address
|
||||
* @return
|
||||
*/
|
||||
ProgramMemorySection getProgramMemorySectionFromAddress(std::uint32_t address);
|
||||
};
|
||||
}
|
||||
|
||||
12
src/Targets/Microchip/AVR/AVR8/ProgramMemorySection.hpp
Normal file
12
src/Targets/Microchip/AVR/AVR8/ProgramMemorySection.hpp
Normal file
@@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace Bloom::Targets::Microchip::Avr::Avr8Bit
|
||||
{
|
||||
enum class ProgramMemorySection: std::uint8_t
|
||||
{
|
||||
APPLICATION,
|
||||
BOOT,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user