Flash programming support for WCH-LinkE tool

This commit is contained in:
Nav
2024-11-16 20:05:26 +00:00
parent 0118306e30
commit 07283a2dc7
24 changed files with 638 additions and 53 deletions

View File

@@ -14,6 +14,8 @@ namespace Targets::RiscV::Wch
)
: RiscV(targetConfig, targetDescriptionFile)
, targetDescriptionFile(std::move(targetDescriptionFile))
, programMemorySegmentDescriptor(this->sysAddressSpaceDescriptor.getMemorySegmentDescriptor("internal_program_memory"))
, mappedProgramMemorySegmentDescriptor(this->sysAddressSpaceDescriptor.getMemorySegmentDescriptor("mapped_progmem"))
{}
void WchRiscV::activate() {
@@ -85,4 +87,29 @@ namespace Targets::RiscV::Wch
return descriptor;
}
void WchRiscV::writeMemory(
const TargetAddressSpaceDescriptor& addressSpaceDescriptor,
const TargetMemorySegmentDescriptor& memorySegmentDescriptor,
TargetMemoryAddress startAddress,
const TargetMemoryBuffer& buffer
) {
/*
* WCH targets have a memory segment that maps to either the program memory segment or the boot program
* memory segment.
*
* Reading directly from the mapped memory segment is fine, but we cannot write to it - the operation just
* fails silently. We handle this by altering the write operation so that we write to the appropriate,
* non-mapped segment.
*/
if (memorySegmentDescriptor == this->mappedProgramMemorySegmentDescriptor) {
const auto newAddress = startAddress - this->mappedProgramMemorySegmentDescriptor.addressRange.startAddress
+ this->programMemorySegmentDescriptor.addressRange.startAddress;
assert(this->programMemorySegmentDescriptor.addressRange.contains(newAddress));
return RiscV::writeMemory(addressSpaceDescriptor, this->programMemorySegmentDescriptor, newAddress, buffer);
}
return RiscV::writeMemory(addressSpaceDescriptor, memorySegmentDescriptor, startAddress, buffer);
}
}