From 81457088512bf87b108734c86da1c6504544e800 Mon Sep 17 00:00:00 2001 From: Nav Date: Sun, 4 Jul 2021 00:29:43 +0100 Subject: [PATCH] Corrected issue with JTAG/debugWire AVR8 parameters including mapped IO memory address offset --- .../EDBG/AVR/EdbgAvr8Interface.cpp | 37 ++++++++++++++++--- src/Targets/Microchip/AVR/AVR8/Avr8.cpp | 7 +++- .../TargetDescriptionFile.cpp | 20 ++++++++++ .../TargetDescriptionFile.hpp | 1 + .../Microchip/AVR/AVR8/TargetParameters.hpp | 3 +- 5 files changed, 61 insertions(+), 7 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 2234f579..4ef073c9 100644 --- a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/EdbgAvr8Interface.cpp +++ b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/EdbgAvr8Interface.cpp @@ -123,6 +123,23 @@ void EdbgAvr8Interface::setDebugWireAndJtagParameters() { ); } + /* + * All addresses for registers that reside in the mapped IO memory segment include the mapped IO segment offset + * (start address). But the EDBG protocol requires *some* of these addresses to be stripped of this offset before + * sending them as target parameters. + * + * This applies to the following addresses: + * + * - OSCALL Address + * - EEARL Address + * - EEARH Address + * - EECR Address + * - EEDR Address + * + * It *doesn't* seem to apply to the SPMCR address. + */ + auto mappedIoStartAddress = this->targetParameters.mappedIoStartAddress.value_or(0); + if (this->targetParameters.ocdDataRegister.has_value()) { Logger::debug("Setting DEVICE_OCD_DATA_REGISTER AVR8 parameter"); this->setParameter( @@ -143,7 +160,9 @@ void EdbgAvr8Interface::setDebugWireAndJtagParameters() { Logger::debug("Setting DEVICE_OSCCAL_ADDR AVR8 parameter"); this->setParameter( Avr8EdbgParameters::DEVICE_OSCCAL_ADDR, - this->targetParameters.osccalAddress.value() + static_cast( + this->targetParameters.osccalAddress.value() - mappedIoStartAddress + ) ); } @@ -151,7 +170,9 @@ void EdbgAvr8Interface::setDebugWireAndJtagParameters() { Logger::debug("Setting DEVICE_EEARL_ADDR AVR8 parameter"); this->setParameter( Avr8EdbgParameters::DEVICE_EEARL_ADDR, - this->targetParameters.eepromAddressRegisterLow.value() + static_cast( + this->targetParameters.eepromAddressRegisterLow.value() - mappedIoStartAddress + ) ); } @@ -159,7 +180,9 @@ void EdbgAvr8Interface::setDebugWireAndJtagParameters() { Logger::debug("Setting DEVICE_EEARH_ADDR AVR8 parameter"); this->setParameter( Avr8EdbgParameters::DEVICE_EEARH_ADDR, - this->targetParameters.eepromAddressRegisterHigh.value() + static_cast( + this->targetParameters.eepromAddressRegisterHigh.value() - mappedIoStartAddress + ) ); } @@ -167,7 +190,9 @@ void EdbgAvr8Interface::setDebugWireAndJtagParameters() { Logger::debug("Setting DEVICE_EECR_ADDR AVR8 parameter"); this->setParameter( Avr8EdbgParameters::DEVICE_EECR_ADDR, - this->targetParameters.eepromControlRegisterAddress.value() + static_cast( + this->targetParameters.eepromControlRegisterAddress.value() - mappedIoStartAddress + ) ); } @@ -175,7 +200,9 @@ void EdbgAvr8Interface::setDebugWireAndJtagParameters() { Logger::debug("Setting DEVICE_EEDR_ADDR AVR8 parameter"); this->setParameter( Avr8EdbgParameters::DEVICE_EEDR_ADDR, - this->targetParameters.eepromDataRegisterAddress.value() + static_cast( + this->targetParameters.eepromDataRegisterAddress.value() - mappedIoStartAddress + ) ); } diff --git a/src/Targets/Microchip/AVR/AVR8/Avr8.cpp b/src/Targets/Microchip/AVR/AVR8/Avr8.cpp index ad1c2aff..1a156f62 100644 --- a/src/Targets/Microchip/AVR/AVR8/Avr8.cpp +++ b/src/Targets/Microchip/AVR/AVR8/Avr8.cpp @@ -62,6 +62,11 @@ void Avr8::loadTargetParameters() { this->targetParameters->ramStartAddress = ramMemorySegment->startAddress; } + auto ioMemorySegment = this->targetDescriptionFile->getIoMemorySegment(); + if (ioMemorySegment.has_value()) { + this->targetParameters->mappedIoStartAddress = ioMemorySegment->startAddress; + } + auto registerMemorySegment = this->targetDescriptionFile->getRegisterMemorySegment(); if (registerMemorySegment.has_value()) { this->targetParameters->gpRegisterSize = registerMemorySegment->size; @@ -183,7 +188,7 @@ void Avr8::loadDebugWireAndJtagTargetParameters() { if (eepromAddressRegister.has_value()) { this->targetParameters->eepromAddressRegisterLow = eepromAddressRegister->offset; this->targetParameters->eepromAddressRegisterHigh = (eepromAddressRegister->size == 2) - ? eepromAddressRegister->offset + 1 : eepromAddressRegister->offset; + ? eepromAddressRegister->offset + 1 : eepromAddressRegister->offset; } else { auto eepromAddressLowRegister = this->targetDescriptionFile->getEepromAddressLowRegister(); diff --git a/src/Targets/Microchip/AVR/AVR8/TargetDescription/TargetDescriptionFile.cpp b/src/Targets/Microchip/AVR/AVR8/TargetDescription/TargetDescriptionFile.cpp index f39128b9..075ef4f1 100644 --- a/src/Targets/Microchip/AVR/AVR8/TargetDescription/TargetDescriptionFile.cpp +++ b/src/Targets/Microchip/AVR/AVR8/TargetDescription/TargetDescriptionFile.cpp @@ -226,6 +226,26 @@ std::optional TargetDescriptionFile::getRamMemorySegment() const return std::nullopt; } +std::optional TargetDescriptionFile::getIoMemorySegment() const { + auto& addressMapping = this->addressSpacesMappedById; + + if (addressMapping.contains("data")) { + auto& dataAddressSpace = addressMapping.at("data"); + auto& dataMemorySegments = dataAddressSpace.memorySegmentsByTypeAndName; + + if (dataMemorySegments.contains(MemorySegmentType::IO)) { + auto& ramMemorySegments = dataMemorySegments.at(MemorySegmentType::IO); + auto ramMemorySegmentIt = ramMemorySegments.begin(); + + if (ramMemorySegmentIt != ramMemorySegments.end()) { + return ramMemorySegmentIt->second; + } + } + } + + return std::nullopt; +} + std::optional TargetDescriptionFile::getRegisterMemorySegment() const { auto& addressMapping = this->addressSpacesMappedById; diff --git a/src/Targets/Microchip/AVR/AVR8/TargetDescription/TargetDescriptionFile.hpp b/src/Targets/Microchip/AVR/AVR8/TargetDescription/TargetDescriptionFile.hpp index 528a5e9e..ab967897 100644 --- a/src/Targets/Microchip/AVR/AVR8/TargetDescription/TargetDescriptionFile.hpp +++ b/src/Targets/Microchip/AVR/AVR8/TargetDescription/TargetDescriptionFile.hpp @@ -94,6 +94,7 @@ namespace Bloom::Targets::Microchip::Avr::Avr8Bit::TargetDescription [[nodiscard]] std::optional getFlashMemorySegment() const; [[nodiscard]] std::optional getRamMemorySegment() const; + [[nodiscard]] std::optional getIoMemorySegment() const; [[nodiscard]] std::optional getRegisterMemorySegment() const; [[nodiscard]] std::optional getEepromMemorySegment() const; [[nodiscard]] std::optional getFirstBootSectionMemorySegment() const; diff --git a/src/Targets/Microchip/AVR/AVR8/TargetParameters.hpp b/src/Targets/Microchip/AVR/AVR8/TargetParameters.hpp index 0706afa4..c710b88f 100644 --- a/src/Targets/Microchip/AVR/AVR8/TargetParameters.hpp +++ b/src/Targets/Microchip/AVR/AVR8/TargetParameters.hpp @@ -10,6 +10,7 @@ namespace Bloom::Targets::Microchip::Avr::Avr8Bit { struct TargetParameters { + std::optional mappedIoStartAddress; std::optional bootSectionStartAddress; std::optional gpRegisterStartAddress; std::optional gpRegisterSize; @@ -20,7 +21,7 @@ namespace Bloom::Targets::Microchip::Avr::Avr8Bit std::optional ramSize; std::optional eepromStartAddress; std::optional eepromSize; - std::optional eepromPageSize; + std::optional eepromPageSize; std::optional eepromAddressRegisterHigh; std::optional eepromAddressRegisterLow; std::optional eepromDataRegisterAddress;