From 40b681ddde7cd32636d2e24d8c8f1dbea00fa870 Mon Sep 17 00:00:00 2001 From: Nav Date: Sun, 2 May 2021 15:54:23 +0100 Subject: [PATCH] Fixed typo in AVR8 target parameter and introduced "SPMCR" fallback value from part description --- .../EDBG/AVR/EdbgAvr8Interface.cpp | 4 +- src/Targets/Microchip/AVR/AVR8/Avr8.cpp | 12 ++++-- .../PartDescription/PartDescriptionFile.cpp | 37 +++++++++++++++++-- .../PartDescription/PartDescriptionFile.hpp | 4 +- .../Microchip/AVR/AVR8/TargetParameters.hpp | 2 +- 5 files changed, 48 insertions(+), 11 deletions(-) diff --git a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/EdbgAvr8Interface.cpp b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/EdbgAvr8Interface.cpp index a9b6e419..7ddd9d5f 100644 --- a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/EdbgAvr8Interface.cpp +++ b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/EdbgAvr8Interface.cpp @@ -245,9 +245,9 @@ void EdbgAvr8Interface::setTargetParameters(const Avr8Bit::TargetParameters& con this->setParameter(Avr8EdbgParameters::DEVICE_OCD_DATA_REGISTER, config.ocdDataRegister.value()); } - if (config.spmcsRegisterStartAddress.has_value()) { + if (config.spmcRegisterStartAddress.has_value()) { Logger::debug("Setting DEVICE_SPMCR_REGISTER AVR8 parameter"); - this->setParameter(Avr8EdbgParameters::DEVICE_SPMCR_REGISTER, config.spmcsRegisterStartAddress.value()); + this->setParameter(Avr8EdbgParameters::DEVICE_SPMCR_REGISTER, config.spmcRegisterStartAddress.value()); } if (config.osccalAddress.has_value()) { diff --git a/src/Targets/Microchip/AVR/AVR8/Avr8.cpp b/src/Targets/Microchip/AVR/AVR8/Avr8.cpp index d3a69b50..a12fa97f 100644 --- a/src/Targets/Microchip/AVR/AVR8/Avr8.cpp +++ b/src/Targets/Microchip/AVR/AVR8/Avr8.cpp @@ -313,9 +313,15 @@ TargetParameters& Avr8::getTargetParameters() { } } - auto spmcsrRegister = this->partDescription->getSpmcsrRegister(); - if (spmcsrRegister.has_value()) { - this->targetParameters->spmcsRegisterStartAddress = spmcsrRegister->offset; + auto spmcsRegister = this->partDescription->getSpmcsRegister(); + if (spmcsRegister.has_value()) { + this->targetParameters->spmcRegisterStartAddress = spmcsRegister->offset; + + } else { + auto spmcRegister = this->partDescription->getSpmcRegister(); + if (spmcRegister.has_value()) { + this->targetParameters->spmcRegisterStartAddress = spmcRegister->offset; + } } auto osccalRegister = this->partDescription->getOscillatorCalibrationRegister(); diff --git a/src/Targets/Microchip/AVR/AVR8/PartDescription/PartDescriptionFile.cpp b/src/Targets/Microchip/AVR/AVR8/PartDescription/PartDescriptionFile.cpp index 86a54ad0..c10d934c 100644 --- a/src/Targets/Microchip/AVR/AVR8/PartDescription/PartDescriptionFile.cpp +++ b/src/Targets/Microchip/AVR/AVR8/PartDescription/PartDescriptionFile.cpp @@ -624,6 +624,21 @@ std::optional PartDescriptionFile::getCpuRegisterGroup() const { return std::nullopt; } +std::optional PartDescriptionFile::getBootLoadRegisterGroup() const { + auto& modulesByName = this->getModulesMappedByName(); + + if (modulesByName.contains("boot_load")) { + auto& bootLoadModule = modulesByName.at("boot_load"); + auto bootLoadRegisterGroupIt = bootLoadModule.registerGroupsMappedByName.find("boot_load"); + + if (bootLoadRegisterGroupIt != bootLoadModule.registerGroupsMappedByName.end()) { + return bootLoadRegisterGroupIt->second; + } + } + + return std::nullopt; +} + std::optional PartDescriptionFile::getEepromRegisterGroup() const { auto& modulesByName = this->getModulesMappedByName(); @@ -709,14 +724,28 @@ std::optional PartDescriptionFile::getOscillatorCalibrationRegister() return std::nullopt; } -std::optional PartDescriptionFile::getSpmcsrRegister() const { +std::optional PartDescriptionFile::getSpmcsRegister() const { auto cpuRegisterGroup = this->getCpuRegisterGroup(); if (cpuRegisterGroup.has_value()) { - auto spmcsrRegisterIt = cpuRegisterGroup->registersMappedByName.find("spmcsr"); + auto spmcsRegisterIt = cpuRegisterGroup->registersMappedByName.find("spmcsr"); - if (spmcsrRegisterIt != cpuRegisterGroup->registersMappedByName.end()) { - return spmcsrRegisterIt->second; + if (spmcsRegisterIt != cpuRegisterGroup->registersMappedByName.end()) { + return spmcsRegisterIt->second; + } + } + + return std::nullopt; +} + +std::optional PartDescriptionFile::getSpmcRegister() const { + auto bootLoadRegisterGroup = this->getBootLoadRegisterGroup(); + + if (bootLoadRegisterGroup.has_value()) { + auto spmcRegisterIt = bootLoadRegisterGroup->registersMappedByName.find("spmcr"); + + if (spmcRegisterIt != bootLoadRegisterGroup->registersMappedByName.end()) { + return spmcRegisterIt->second; } } diff --git a/src/Targets/Microchip/AVR/AVR8/PartDescription/PartDescriptionFile.hpp b/src/Targets/Microchip/AVR/AVR8/PartDescription/PartDescriptionFile.hpp index d22abceb..f0f2cb91 100644 --- a/src/Targets/Microchip/AVR/AVR8/PartDescription/PartDescriptionFile.hpp +++ b/src/Targets/Microchip/AVR/AVR8/PartDescription/PartDescriptionFile.hpp @@ -158,13 +158,15 @@ namespace Bloom::Targets::Microchip::Avr::Avr8Bit::PartDescription std::optional getEepromMemorySegment() const; std::optional getFirstBootSectionMemorySegment() const; std::optional getCpuRegisterGroup() const; + std::optional getBootLoadRegisterGroup() const; std::optional getEepromRegisterGroup() const; std::optional getStatusRegister() const; std::optional getStackPointerRegister() const; std::optional getStackPointerHighRegister() const; std::optional getStackPointerLowRegister() const; std::optional getOscillatorCalibrationRegister() const; - std::optional getSpmcsrRegister() const; + std::optional getSpmcsRegister() const; + std::optional getSpmcRegister() const; std::optional getEepromAddressRegister() const; std::optional getEepromDataRegister() const; std::optional getEepromControlRegister() const; diff --git a/src/Targets/Microchip/AVR/AVR8/TargetParameters.hpp b/src/Targets/Microchip/AVR/AVR8/TargetParameters.hpp index 03fd7918..f5994a5a 100644 --- a/src/Targets/Microchip/AVR/AVR8/TargetParameters.hpp +++ b/src/Targets/Microchip/AVR/AVR8/TargetParameters.hpp @@ -33,7 +33,7 @@ namespace Bloom::Targets::Microchip::Avr::Avr8Bit std::optional statusRegisterSize; std::optional stackPointerRegisterStartAddress; std::optional stackPointerRegisterSize; - std::optional spmcsRegisterStartAddress; + std::optional spmcRegisterStartAddress; std::optional osccalAddress; // XMega/PDI specific target params