WCH-Link erase command doesn't erase the whole chip, as initially thought. It only erases the program memory segment.

The boot segment appears to be left untouched.
This commit is contained in:
Nav
2024-12-13 22:48:20 +00:00
parent a971e92a58
commit 00919e4057
6 changed files with 33 additions and 18 deletions

View File

@@ -57,6 +57,11 @@ namespace DebugToolDrivers::Wch
this->targetConfig
}
)
, programSegmentDescriptor(
this->targetDescriptionFile.getSystemAddressSpaceDescriptor().getMemorySegmentDescriptor(
"internal_program_memory"
)
)
, flashProgramOpcodes(
WchLinkDebugInterface::getFlashProgramOpcodes(
this->targetDescriptionFile.getProperty("wch_link_interface", "programming_opcode_key").value
@@ -352,11 +357,11 @@ namespace DebugToolDrivers::Wch
const TargetAddressSpaceDescriptor& addressSpaceDescriptor,
const TargetMemorySegmentDescriptor& memorySegmentDescriptor
) {
if (memorySegmentDescriptor.type == TargetMemorySegmentType::FLASH) {
return this->eraseFlashMemory();
if (memorySegmentDescriptor == this->programSegmentDescriptor) {
return this->wchLinkInterface.eraseProgramMemory();
}
throw Exception{"Erasing non-flash memory not supported in WchLinkDebugInterface"};
// Ignore other (non-program memory) erase requests, for now.
}
void WchLinkDebugInterface::enableProgrammingMode() {
@@ -471,10 +476,6 @@ namespace DebugToolDrivers::Wch
this->softwareBreakpointRegistry.remove(softwareBreakpoint);
}
void WchLinkDebugInterface::eraseFlashMemory() {
this->wchLinkInterface.eraseChip();
}
std::span<const unsigned char> WchLinkDebugInterface::getFlashProgramOpcodes(const std::string& key) {
if (key == "op1") {
return FlashProgramOpcodes::FLASH_OP1;