Corrected EEARL/H register address extraction from AVR8 TDFs.

Some other bits of tidying
This commit is contained in:
Nav
2024-03-29 15:52:12 +00:00
parent b9d537e924
commit 779a5ad151
7 changed files with 109 additions and 100 deletions

View File

@@ -990,22 +990,22 @@ namespace DebugToolDrivers::Microchip::Protocols::Edbg::Avr
this->setParameter(Avr8EdbgParameters::DEVICE_OCD_REVISION, parameters.ocdRevision);
Logger::debug("Setting OCD_DATA_REGISTER AVR8 device parameter");
this->setParameter(Avr8EdbgParameters::DEVICE_OCD_DATA_REGISTER, parameters.ocdDataRegister);
this->setParameter(Avr8EdbgParameters::DEVICE_OCD_DATA_REGISTER, parameters.ocdDataRegisterAddress);
Logger::debug("Setting EEARL_ADDR AVR8 device parameter");
this->setParameter(Avr8EdbgParameters::DEVICE_EEARL_ADDR, parameters.eepromAddressRegisterLow);
this->setParameter(Avr8EdbgParameters::DEVICE_EEARL_ADDR, parameters.eearAddressLow);
Logger::debug("Setting EEARH_ADDR AVR8 device parameter");
this->setParameter(Avr8EdbgParameters::DEVICE_EEARH_ADDR, parameters.eepromAddressRegisterHigh);
this->setParameter(Avr8EdbgParameters::DEVICE_EEARH_ADDR, parameters.eearAddressHigh);
Logger::debug("Setting EECR_ADDR AVR8 device parameter");
this->setParameter(Avr8EdbgParameters::DEVICE_EECR_ADDR, parameters.eepromControlRegisterAddress);
this->setParameter(Avr8EdbgParameters::DEVICE_EECR_ADDR, parameters.eecrAddress);
Logger::debug("Setting EEDR_ADDR AVR8 device parameter");
this->setParameter(Avr8EdbgParameters::DEVICE_EEDR_ADDR, parameters.eepromDataRegisterAddress);
this->setParameter(Avr8EdbgParameters::DEVICE_EEDR_ADDR, parameters.eedrAddress);
Logger::debug("Setting SPMCR_REGISTER AVR8 device parameter");
this->setParameter(Avr8EdbgParameters::DEVICE_SPMCR_REGISTER, parameters.spmcRegisterStartAddress);
this->setParameter(Avr8EdbgParameters::DEVICE_SPMCR_REGISTER, parameters.spmcrAddress);
Logger::debug("Setting OSCCAL_ADDR AVR8 device parameter");
this->setParameter(Avr8EdbgParameters::DEVICE_OSCCAL_ADDR, parameters.osccalAddress);

View File

@@ -34,7 +34,7 @@ namespace DebugToolDrivers::Microchip::Protocols::Edbg::Avr::Parameters::Avr8Gen
const auto& ocdPropertyGroup = targetDescriptionFile.getPropertyGroup("ocd");
this->ocdRevision = StringService::toUint8(ocdPropertyGroup.getProperty("ocd_revision").value);
this->ocdDataRegister = StringService::toUint8(ocdPropertyGroup.getProperty("ocd_datareg").value);
this->ocdDataRegisterAddress = StringService::toUint8(ocdPropertyGroup.getProperty("ocd_datareg").value);
const auto& eepromRegisterGroupDescriptor = targetDescriptionFile.getTargetPeripheralDescriptor("eeprom")
.getRegisterGroupDescriptor("eeprom");
@@ -42,29 +42,38 @@ namespace DebugToolDrivers::Microchip::Protocols::Edbg::Avr::Parameters::Avr8Gen
const auto& eearDescriptor = eepromRegisterGroupDescriptor.tryGetRegisterDescriptor("eear");
if (eearDescriptor.has_value()) {
const auto startAddress = eearDescriptor->get().startAddress;
this->eepromAddressRegisterLow = static_cast<std::uint8_t>(startAddress);
this->eepromAddressRegisterHigh = static_cast<std::uint8_t>(
eearDescriptor->get().size > 1 ? startAddress >> 2 : startAddress
this->eearAddressLow = static_cast<std::uint8_t>(startAddress);
/*
* If the target doesn't have a high byte in the `EEAR` address, the `eearAddressHigh` parameter should be
* equal to the `eearAddressLow` parameter, as stated in the "EDBG-based Tools Protocols" document.
*/
this->eearAddressHigh = static_cast<std::uint8_t>(
eearDescriptor->get().size > 1 ? startAddress >> 8 : startAddress
);
} else {
const auto& eearlDescriptor = eepromRegisterGroupDescriptor.getRegisterDescriptor("eearl");
this->eepromAddressRegisterLow = static_cast<std::uint8_t>(eearlDescriptor.startAddress);
this->eepromAddressRegisterHigh = static_cast<std::uint8_t>(
eearlDescriptor.size > 1 ? eearlDescriptor.startAddress >> 2 : eearlDescriptor.startAddress
);
this->eearAddressLow = static_cast<std::uint8_t>(eearlDescriptor.startAddress);
/*
* Some debugWire targets only have a single-byte `EEARL` register. In the absence of an `EEARH` register,
* and if there is no high byte in the `EEARL` register, the `eearAddressHigh` parameter should be equal
* to the `eearAddressLow` parameter, as stated in the "EDBG-based Tools Protocols" document.
*/
const auto eearhDescriptor = eepromRegisterGroupDescriptor.tryGetRegisterDescriptor("eearh");
if (eearhDescriptor.has_value()) {
this->eepromAddressRegisterHigh = static_cast<std::uint8_t>(eearhDescriptor->get().startAddress);
}
this->eearAddressHigh = static_cast<std::uint8_t>(
eearhDescriptor.has_value()
? eearhDescriptor->get().startAddress
: eearlDescriptor.size > 1 ? eearlDescriptor.startAddress >> 8 : eearlDescriptor.startAddress
);
}
this->eepromDataRegisterAddress = static_cast<std::uint8_t>(
this->eedrAddress = static_cast<std::uint8_t>(
eepromRegisterGroupDescriptor.getRegisterDescriptor("eedr").startAddress
);
this->eepromControlRegisterAddress = static_cast<std::uint8_t>(
this->eecrAddress = static_cast<std::uint8_t>(
eepromRegisterGroupDescriptor.getRegisterDescriptor("eecr").startAddress
);
@@ -75,7 +84,7 @@ namespace DebugToolDrivers::Microchip::Protocols::Edbg::Avr::Parameters::Avr8Gen
?: cpuRegisterGroupDescriptor.tryGetRegisterDescriptor("spmcr");
if (spmcsrDescriptor.has_value()) {
this->spmcRegisterStartAddress = static_cast<std::uint8_t>(spmcsrDescriptor->get().startAddress);
this->spmcrAddress = static_cast<std::uint8_t>(spmcsrDescriptor->get().startAddress);
} else {
const auto& bootLoaderRegisterGroupDescriptor = targetDescriptionFile.getTargetPeripheralDescriptor(
@@ -89,7 +98,7 @@ namespace DebugToolDrivers::Microchip::Protocols::Edbg::Avr::Parameters::Avr8Gen
throw Exceptions::InternalFatalErrorException("Could not extract SPMCS register from TDF");
}
this->spmcRegisterStartAddress = static_cast<std::uint8_t>(spmcsrDescriptor->get().startAddress);
this->spmcrAddress = static_cast<std::uint8_t>(spmcsrDescriptor->get().startAddress);
}
const auto osccalDescriptor = cpuRegisterGroupDescriptor.tryGetRegisterDescriptor("osccal")
@@ -122,9 +131,9 @@ namespace DebugToolDrivers::Microchip::Protocols::Edbg::Avr::Parameters::Avr8Gen
const auto& ioMemorySegment = targetDescriptionFile.getIoMemorySegment();
this->osccalAddress -= ioMemorySegment.startAddress;
this->eepromAddressRegisterLow -= ioMemorySegment.startAddress;
this->eepromAddressRegisterHigh -= ioMemorySegment.startAddress;
this->eepromControlRegisterAddress -= ioMemorySegment.startAddress;
this->eepromDataRegisterAddress -= ioMemorySegment.startAddress;
this->eearAddressLow -= ioMemorySegment.startAddress;
this->eearAddressHigh -= ioMemorySegment.startAddress;
this->eecrAddress -= ioMemorySegment.startAddress;
this->eedrAddress -= ioMemorySegment.startAddress;
}
}

View File

@@ -22,12 +22,12 @@ namespace DebugToolDrivers::Microchip::Protocols::Edbg::Avr::Parameters::Avr8Gen
std::uint16_t eepromSize;
std::uint8_t eepromPageSize;
std::uint8_t ocdRevision;
std::uint8_t ocdDataRegister;
std::uint8_t eepromAddressRegisterHigh;
std::uint8_t eepromAddressRegisterLow;
std::uint8_t eepromDataRegisterAddress;
std::uint8_t eepromControlRegisterAddress;
std::uint8_t spmcRegisterStartAddress;
std::uint8_t ocdDataRegisterAddress;
std::uint8_t eearAddressHigh;
std::uint8_t eearAddressLow;
std::uint8_t eedrAddress;
std::uint8_t eecrAddress;
std::uint8_t spmcrAddress;
std::uint8_t osccalAddress;
DebugWireJtagParameters(const Targets::Microchip::Avr::Avr8Bit::TargetDescriptionFile& targetDescriptionFile);