diff --git a/src/DebugToolDrivers/Microchip/Protocols/EDBG/AVR/Avr8Generic.hpp b/src/DebugToolDrivers/Microchip/Protocols/EDBG/AVR/Avr8Generic.hpp index b8c54250..328e5bd6 100644 --- a/src/DebugToolDrivers/Microchip/Protocols/EDBG/AVR/Avr8Generic.hpp +++ b/src/DebugToolDrivers/Microchip/Protocols/EDBG/AVR/Avr8Generic.hpp @@ -2,7 +2,7 @@ #include -#include "src/Targets/Microchip/AVR/AVR8/PhysicalInterface.hpp" +#include "src/Targets/TargetPhysicalInterface.hpp" namespace DebugToolDrivers::Microchip::Protocols::Edbg::Avr { @@ -103,14 +103,14 @@ namespace DebugToolDrivers::Microchip::Protocols::Edbg::Avr DEBUGGING = 0x02, }; - static inline auto getAvr8PhysicalInterfaceToIdMapping() { - using Targets::Microchip::Avr::Avr8Bit::PhysicalInterface; + static inline auto getPhysicalInterfaceToAvr8IdMapping() { + using Targets::TargetPhysicalInterface; - return std::map({ - {PhysicalInterface::DEBUG_WIRE, 0x05}, - {PhysicalInterface::PDI, 0x06}, - {PhysicalInterface::JTAG, 0x04}, - {PhysicalInterface::UPDI, 0x08}, + return std::map({ + {TargetPhysicalInterface::DEBUG_WIRE, 0x05}, + {TargetPhysicalInterface::PDI, 0x06}, + {TargetPhysicalInterface::JTAG, 0x04}, + {TargetPhysicalInterface::UPDI, 0x08}, }); } diff --git a/src/DebugToolDrivers/Microchip/Protocols/EDBG/AVR/EdbgAvr8Interface.cpp b/src/DebugToolDrivers/Microchip/Protocols/EDBG/AVR/EdbgAvr8Interface.cpp index d8761f6b..179883bf 100644 --- a/src/DebugToolDrivers/Microchip/Protocols/EDBG/AVR/EdbgAvr8Interface.cpp +++ b/src/DebugToolDrivers/Microchip/Protocols/EDBG/AVR/EdbgAvr8Interface.cpp @@ -76,6 +76,7 @@ namespace DebugToolDrivers::Microchip::Protocols::Edbg::Avr using CommandFrames::Avr8Generic::DisableDebugWire; using Targets::TargetState; + using Targets::TargetPhysicalInterface; using Targets::TargetMemoryType; using Targets::TargetMemoryBuffer; using Targets::TargetMemoryAddress; @@ -135,7 +136,7 @@ namespace DebugToolDrivers::Microchip::Protocols::Edbg::Avr this->setParameter( Avr8EdbgParameters::PHYSICAL_INTERFACE, - getAvr8PhysicalInterfaceToIdMapping().at(this->targetConfig.physicalInterface) + getPhysicalInterfaceToAvr8IdMapping().at(this->targetConfig.physicalInterface) ); this->setTargetParameters(); @@ -227,7 +228,7 @@ namespace DebugToolDrivers::Microchip::Protocols::Edbg::Avr } catch (const Avr8CommandFailure& activationException) { if ( - this->targetConfig.physicalInterface == PhysicalInterface::DEBUG_WIRE + this->targetConfig.physicalInterface == TargetPhysicalInterface::DEBUG_WIRE && ( activationException.code == Avr8CommandFailureCode::DEBUGWIRE_PHYSICAL_ERROR || activationException.code == Avr8CommandFailureCode::FAILED_TO_ENABLE_OCD @@ -252,7 +253,7 @@ namespace DebugToolDrivers::Microchip::Protocols::Edbg::Avr void EdbgAvr8Interface::deactivate() { if (this->targetAttached) { if ( - this->targetConfig.physicalInterface == PhysicalInterface::DEBUG_WIRE + this->targetConfig.physicalInterface == TargetPhysicalInterface::DEBUG_WIRE && this->targetConfig.disableDebugWireOnDeactivate ) { try { @@ -947,54 +948,54 @@ namespace DebugToolDrivers::Microchip::Protocols::Edbg::Avr } } - std::map> + std::map> EdbgAvr8Interface::getConfigVariantsByFamilyAndPhysicalInterface() { - return std::map>({ + return std::map>({ { Family::MEGA, { - {PhysicalInterface::JTAG, Avr8ConfigVariant::MEGAJTAG}, - {PhysicalInterface::DEBUG_WIRE, Avr8ConfigVariant::DEBUG_WIRE}, - {PhysicalInterface::UPDI, Avr8ConfigVariant::UPDI}, + {TargetPhysicalInterface::JTAG, Avr8ConfigVariant::MEGAJTAG}, + {TargetPhysicalInterface::DEBUG_WIRE, Avr8ConfigVariant::DEBUG_WIRE}, + {TargetPhysicalInterface::UPDI, Avr8ConfigVariant::UPDI}, } }, { Family::TINY, { - {PhysicalInterface::JTAG, Avr8ConfigVariant::MEGAJTAG}, - {PhysicalInterface::DEBUG_WIRE, Avr8ConfigVariant::DEBUG_WIRE}, - {PhysicalInterface::UPDI, Avr8ConfigVariant::UPDI}, + {TargetPhysicalInterface::JTAG, Avr8ConfigVariant::MEGAJTAG}, + {TargetPhysicalInterface::DEBUG_WIRE, Avr8ConfigVariant::DEBUG_WIRE}, + {TargetPhysicalInterface::UPDI, Avr8ConfigVariant::UPDI}, } }, { Family::XMEGA, { - {PhysicalInterface::JTAG, Avr8ConfigVariant::XMEGA}, - {PhysicalInterface::PDI, Avr8ConfigVariant::XMEGA}, + {TargetPhysicalInterface::JTAG, Avr8ConfigVariant::XMEGA}, + {TargetPhysicalInterface::PDI, Avr8ConfigVariant::XMEGA}, } }, { Family::DA, { - {PhysicalInterface::UPDI, Avr8ConfigVariant::UPDI}, + {TargetPhysicalInterface::UPDI, Avr8ConfigVariant::UPDI}, } }, { Family::DB, { - {PhysicalInterface::UPDI, Avr8ConfigVariant::UPDI}, + {TargetPhysicalInterface::UPDI, Avr8ConfigVariant::UPDI}, } }, { Family::DD, { - {PhysicalInterface::UPDI, Avr8ConfigVariant::UPDI}, + {TargetPhysicalInterface::UPDI, Avr8ConfigVariant::UPDI}, } }, { Family::EA, { - {PhysicalInterface::UPDI, Avr8ConfigVariant::UPDI}, + {TargetPhysicalInterface::UPDI, Avr8ConfigVariant::UPDI}, } }, }); @@ -1002,7 +1003,7 @@ namespace DebugToolDrivers::Microchip::Protocols::Edbg::Avr Avr8ConfigVariant EdbgAvr8Interface::resolveConfigVariant( Targets::Microchip::Avr::Avr8Bit::Family targetFamily, - Targets::Microchip::Avr::Avr8Bit::PhysicalInterface physicalInterface + TargetPhysicalInterface physicalInterface ) { const auto configVariantsByFamily = EdbgAvr8Interface::getConfigVariantsByFamilyAndPhysicalInterface(); const auto configVariantsByPhysicalInterfaceIt = configVariantsByFamily.find(targetFamily); diff --git a/src/DebugToolDrivers/Microchip/Protocols/EDBG/AVR/EdbgAvr8Interface.hpp b/src/DebugToolDrivers/Microchip/Protocols/EDBG/AVR/EdbgAvr8Interface.hpp index 3b26fcca..422466ea 100644 --- a/src/DebugToolDrivers/Microchip/Protocols/EDBG/AVR/EdbgAvr8Interface.hpp +++ b/src/DebugToolDrivers/Microchip/Protocols/EDBG/AVR/EdbgAvr8Interface.hpp @@ -11,10 +11,10 @@ #include "Avr8Generic.hpp" +#include "src/Targets/TargetPhysicalInterface.hpp" #include "src/Targets/TargetMemory.hpp" #include "src/Targets/TargetRegister.hpp" #include "src/Targets/Microchip/AVR/AVR8/Family.hpp" -#include "src/Targets/Microchip/AVR/AVR8/PhysicalInterface.hpp" #include "src/Targets/Microchip/AVR/AVR8/TargetParameters.hpp" namespace DebugToolDrivers::Microchip::Protocols::Edbg::Avr @@ -384,7 +384,7 @@ namespace DebugToolDrivers::Microchip::Protocols::Edbg::Avr */ static std::map< Targets::Microchip::Avr::Avr8Bit::Family, - std::map + std::map > getConfigVariantsByFamilyAndPhysicalInterface(); /** @@ -394,7 +394,7 @@ namespace DebugToolDrivers::Microchip::Protocols::Edbg::Avr */ static Avr8ConfigVariant resolveConfigVariant( Targets::Microchip::Avr::Avr8Bit::Family targetFamily, - Targets::Microchip::Avr::Avr8Bit::PhysicalInterface physicalInterface + Targets::TargetPhysicalInterface physicalInterface ); /** diff --git a/src/DebugToolDrivers/Microchip/Protocols/EDBG/AVR/ResponseFrames/AVR8Generic/GetDeviceId.cpp b/src/DebugToolDrivers/Microchip/Protocols/EDBG/AVR/ResponseFrames/AVR8Generic/GetDeviceId.cpp index 7425ba92..528b88a9 100644 --- a/src/DebugToolDrivers/Microchip/Protocols/EDBG/AVR/ResponseFrames/AVR8Generic/GetDeviceId.cpp +++ b/src/DebugToolDrivers/Microchip/Protocols/EDBG/AVR/ResponseFrames/AVR8Generic/GetDeviceId.cpp @@ -7,27 +7,27 @@ namespace DebugToolDrivers::Microchip::Protocols::Edbg::Avr::ResponseFrames::Avr {} Targets::Microchip::Avr::TargetSignature GetDeviceId::extractSignature( - Targets::Microchip::Avr::Avr8Bit::PhysicalInterface physicalInterface + Targets::TargetPhysicalInterface physicalInterface ) const { - using Targets::Microchip::Avr::Avr8Bit::PhysicalInterface; + using Targets::TargetPhysicalInterface; const auto payloadData = this->getPayloadData(); switch (physicalInterface) { - case PhysicalInterface::DEBUG_WIRE: { + case TargetPhysicalInterface::DEBUG_WIRE: { /* * When using the DebugWire physical interface, the get device ID command will return * four bytes, where the first can be ignored. */ return Targets::Microchip::Avr::TargetSignature(payloadData[1], payloadData[2], payloadData[3]); } - case PhysicalInterface::PDI: - case PhysicalInterface::UPDI: { + case TargetPhysicalInterface::PDI: + case TargetPhysicalInterface::UPDI: { /* * When using the PDI physical interface, the signature is returned in LSB format. */ return Targets::Microchip::Avr::TargetSignature(payloadData[3], payloadData[2], payloadData[1]); } - case PhysicalInterface::JTAG: { + case TargetPhysicalInterface::JTAG: { /* * When using the JTAG interface, the get device ID command returns a 32 bit JTAG ID. This takes * the following form: diff --git a/src/DebugToolDrivers/Microchip/Protocols/EDBG/AVR/ResponseFrames/AVR8Generic/GetDeviceId.hpp b/src/DebugToolDrivers/Microchip/Protocols/EDBG/AVR/ResponseFrames/AVR8Generic/GetDeviceId.hpp index 03f77337..2817a0b2 100644 --- a/src/DebugToolDrivers/Microchip/Protocols/EDBG/AVR/ResponseFrames/AVR8Generic/GetDeviceId.hpp +++ b/src/DebugToolDrivers/Microchip/Protocols/EDBG/AVR/ResponseFrames/AVR8Generic/GetDeviceId.hpp @@ -3,7 +3,7 @@ #include "Avr8GenericResponseFrame.hpp" #include "src/Targets/Microchip/AVR/TargetSignature.hpp" -#include "src/Targets/Microchip/AVR/AVR8/PhysicalInterface.hpp" +#include "src/Targets/TargetPhysicalInterface.hpp" namespace DebugToolDrivers::Microchip::Protocols::Edbg::Avr::ResponseFrames::Avr8Generic { @@ -13,7 +13,7 @@ namespace DebugToolDrivers::Microchip::Protocols::Edbg::Avr::ResponseFrames::Avr explicit GetDeviceId(const std::vector& AvrResponses); Targets::Microchip::Avr::TargetSignature extractSignature( - Targets::Microchip::Avr::Avr8Bit::PhysicalInterface physicalInterface + Targets::TargetPhysicalInterface physicalInterface ) const; }; } diff --git a/src/DebugToolDrivers/TargetInterfaces/Microchip/AVR/AVR8/Avr8DebugInterface.hpp b/src/DebugToolDrivers/TargetInterfaces/Microchip/AVR/AVR8/Avr8DebugInterface.hpp index 72b4e689..65c73209 100644 --- a/src/DebugToolDrivers/TargetInterfaces/Microchip/AVR/AVR8/Avr8DebugInterface.hpp +++ b/src/DebugToolDrivers/TargetInterfaces/Microchip/AVR/AVR8/Avr8DebugInterface.hpp @@ -8,7 +8,6 @@ #include "src/Targets/Microchip/AVR/TargetSignature.hpp" #include "src/Targets/Microchip/AVR/AVR8/Family.hpp" -#include "src/Targets/Microchip/AVR/AVR8/PhysicalInterface.hpp" #include "src/Targets/Microchip/AVR/AVR8/ProgramMemorySection.hpp" #include "src/Targets/Microchip/AVR/AVR8/TargetParameters.hpp" diff --git a/src/ProjectConfig.cpp b/src/ProjectConfig.cpp index 4777adf6..6697d31c 100644 --- a/src/ProjectConfig.cpp +++ b/src/ProjectConfig.cpp @@ -153,6 +153,8 @@ EnvironmentConfig::EnvironmentConfig(std::string name, const YAML::Node& environ } TargetConfig::TargetConfig(const YAML::Node& targetNode) { + using Targets::TargetPhysicalInterface; + if (!targetNode.IsMap()) { throw Exceptions::InvalidConfig( "Invalid target configuration provided - node must take the form of a YAML mapping." @@ -165,6 +167,31 @@ TargetConfig::TargetConfig(const YAML::Node& targetNode) { this->name = StringService::asciiToLower(targetNode["name"].as()); + static auto physicalInterfacesByConfigName = std::map({ + {"debugwire", TargetPhysicalInterface::DEBUG_WIRE}, // Deprecated - left here for backwards compatibility + {"debug-wire", TargetPhysicalInterface::DEBUG_WIRE}, + {"pdi", TargetPhysicalInterface::PDI}, + {"jtag", TargetPhysicalInterface::JTAG}, + {"updi", TargetPhysicalInterface::UPDI}, + }); + + if (!targetNode["physicalInterface"]) { + throw Exceptions::InvalidConfig("No physical interface specified."); + } + + const auto physicalInterfaceName = StringService::asciiToLower(targetNode["physicalInterface"].as()); + const auto physicalInterfaceIt = physicalInterfacesByConfigName.find(physicalInterfaceName); + + if (physicalInterfaceIt == physicalInterfacesByConfigName.end()) { + throw Exceptions::InvalidConfig( + "Invalid physical interface provided (\"" + physicalInterfaceName + "\") for target. " + "See " + Services::PathService::homeDomainName() + "/docs/configuration/target-physical-interfaces " + "for valid physical interface configuration values." + ); + } + + this->physicalInterface = physicalInterfaceIt->second; + if (targetNode["variantName"]) { this->variantName = StringService::asciiToLower(targetNode["variantName"].as()); } diff --git a/src/ProjectConfig.hpp b/src/ProjectConfig.hpp index fd394848..d52f7f44 100644 --- a/src/ProjectConfig.hpp +++ b/src/ProjectConfig.hpp @@ -6,6 +6,8 @@ #include #include +#include "src/Targets/TargetPhysicalInterface.hpp" + /* * Currently, all user configuration is stored in a YAML file (bloom.yaml), in the user's project directory. * @@ -44,6 +46,12 @@ struct TargetConfig */ std::string name; + /** + * The physical interface is the interface used for communication between the debug tool and the connected + * target. + */ + Targets::TargetPhysicalInterface physicalInterface; + /** * The name of the selected target variant. * diff --git a/src/Targets/CMakeLists.txt b/src/Targets/CMakeLists.txt index c5f77f39..4d8cea1a 100755 --- a/src/Targets/CMakeLists.txt +++ b/src/Targets/CMakeLists.txt @@ -4,9 +4,9 @@ target_sources( ${CMAKE_CURRENT_SOURCE_DIR}/TargetDescription/TargetDescriptionFile.cpp ${CMAKE_CURRENT_SOURCE_DIR}/TargetRegister.cpp ${CMAKE_CURRENT_SOURCE_DIR}/TargetMemoryCache.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/TargetPhysicalInterface.cpp ${CMAKE_CURRENT_SOURCE_DIR}/Microchip/AVR/AVR8/Avr8.cpp ${CMAKE_CURRENT_SOURCE_DIR}/Microchip/AVR/AVR8/Avr8TargetConfig.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/Microchip/AVR/AVR8/PhysicalInterface.cpp ${CMAKE_CURRENT_SOURCE_DIR}/Microchip/AVR/AVR8/TargetDescription/TargetDescriptionFile.cpp ${CMAKE_CURRENT_SOURCE_DIR}/Microchip/AVR/AVR8/OpcodeDecoder/Decoder.cpp ${CMAKE_CURRENT_SOURCE_DIR}/RiscV/RiscV.cpp diff --git a/src/Targets/Microchip/AVR/AVR8/Avr8.cpp b/src/Targets/Microchip/AVR/AVR8/Avr8.cpp index 70fb55d3..76a279c5 100644 --- a/src/Targets/Microchip/AVR/AVR8/Avr8.cpp +++ b/src/Targets/Microchip/AVR/AVR8/Avr8.cpp @@ -25,7 +25,7 @@ namespace Targets::Microchip::Avr::Avr8Bit , name(this->targetDescriptionFile.getTargetName()) , family(this->targetDescriptionFile.getAvrFamily()) , targetParameters(this->targetDescriptionFile.getTargetParameters()) - , supportedPhysicalInterfaces(this->targetDescriptionFile.getSupportedPhysicalInterfaces()) + , physicalInterfaces(this->targetDescriptionFile.getPhysicalInterfaces()) , padDescriptorsByName(this->targetDescriptionFile.getPadDescriptorsMappedByName()) , targetVariantsById(this->targetDescriptionFile.getVariantsMappedById()) , stackPointerRegisterDescriptor( @@ -54,24 +54,24 @@ namespace Targets::Microchip::Avr::Avr8Bit ) , fuseEnableStrategy(this->targetDescriptionFile.getFuseEnableStrategy().value_or(FuseEnableStrategy::CLEAR)) { - if (!this->supportedPhysicalInterfaces.contains(this->targetConfig.physicalInterface)) { + if (!this->physicalInterfaces.contains(this->targetConfig.physicalInterface)) { /* * The user has selected a physical interface that does not appear to be supported by the selected * target. * * Bloom's target description files provide a list of supported physical interfaces for each target - * (which is how this->supportedPhysicalInterfaces is populated), but it's possible that this list may + * (which is how this->physicalInterfaces is populated), but it's possible that this list may * be wrong/incomplete. For this reason, we don't throw an exception here. Instead, we just present the * user with a warning and a list of physical interfaces known to be supported by their selected target. */ const auto physicalInterfaceNames = getPhysicalInterfaceNames(); const auto supportedPhysicalInterfaceList = std::accumulate( - this->supportedPhysicalInterfaces.begin(), - this->supportedPhysicalInterfaces.end(), + this->physicalInterfaces.begin(), + this->physicalInterfaces.end(), std::string(), - [&physicalInterfaceNames] (const std::string& string, PhysicalInterface physicalInterface) { - if (physicalInterface == PhysicalInterface::ISP) { + [&physicalInterfaceNames] (const std::string& string, TargetPhysicalInterface physicalInterface) { + if (physicalInterface == TargetPhysicalInterface::ISP) { /* * Don't include the ISP interface in the list of supported interfaces, as doing so may * mislead the user into thinking the ISP interface can be used for debugging operations. @@ -88,15 +88,13 @@ namespace Targets::Microchip::Avr::Avr8Bit + physicalInterfaceNames.at(this->targetConfig.physicalInterface) + "). Target activation " "will likely fail. The target supports the following physical interfaces: \n" + supportedPhysicalInterfaceList + "\n\nFor physical interface configuration values, see " - + Services::PathService::homeDomainName() + "/docs/configuration/avr8-physical-interfaces. \n\n" - + "If this information is incorrect, please report this to Bloom developers via " - + Services::PathService::homeDomainName() + "/report-issue.\n" + + Services::PathService::homeDomainName() + "/docs/configuration/target-physical-interfaces." ); } if ( this->targetConfig.manageOcdenFuseBit - && this->targetConfig.physicalInterface != PhysicalInterface::JTAG + && this->targetConfig.physicalInterface != TargetPhysicalInterface::JTAG ) { Logger::warning( "The 'manageOcdenFuseBit' parameter only applies to JTAG targets. It will be ignored in this session." @@ -136,7 +134,7 @@ namespace Targets::Microchip::Avr::Avr8Bit if ( this->targetConfig.manageDwenFuseBit && this->avrIspInterface == nullptr - && this->targetConfig.physicalInterface == PhysicalInterface::DEBUG_WIRE + && this->targetConfig.physicalInterface == TargetPhysicalInterface::DEBUG_WIRE ) { Logger::warning( "The connected debug tool (or associated driver) does not provide any ISP interface. " @@ -210,7 +208,7 @@ namespace Targets::Microchip::Avr::Avr8Bit } if ( - this->targetConfig.physicalInterface == PhysicalInterface::JTAG + this->targetConfig.physicalInterface == TargetPhysicalInterface::JTAG && this->targetConfig.manageOcdenFuseBit ) { Logger::debug("Attempting OCDEN fuse bit management"); @@ -248,7 +246,7 @@ namespace Targets::Microchip::Avr::Avr8Bit this->clearAllBreakpoints(); if ( - this->targetConfig.physicalInterface == PhysicalInterface::JTAG + this->targetConfig.physicalInterface == TargetPhysicalInterface::JTAG && this->targetConfig.manageOcdenFuseBit ) { Logger::debug("Attempting OCDEN fuse bit management"); @@ -357,7 +355,7 @@ namespace Targets::Microchip::Avr::Avr8Bit void Avr8::eraseMemory(TargetMemoryType memoryType) { if (memoryType == TargetMemoryType::FLASH) { - if (this->targetConfig.physicalInterface == PhysicalInterface::DEBUG_WIRE) { + if (this->targetConfig.physicalInterface == TargetPhysicalInterface::DEBUG_WIRE) { // debugWire targets do not need to be erased return; } @@ -374,8 +372,8 @@ namespace Targets::Microchip::Avr::Avr8Bit * the chip erase. The fuse will be restored to its original value at the end of the programming session. */ if ( - this->targetConfig.physicalInterface == PhysicalInterface::JTAG - || this->targetConfig.physicalInterface == PhysicalInterface::UPDI + this->targetConfig.physicalInterface == TargetPhysicalInterface::JTAG + || this->targetConfig.physicalInterface == TargetPhysicalInterface::UPDI ) { if (this->targetConfig.preserveEeprom) { Logger::debug("Inspecting EESAVE fuse bit"); @@ -705,15 +703,15 @@ namespace Targets::Microchip::Avr::Avr8Bit auto maxHardwareBreakpoints = static_cast(0); switch (this->targetConfig.physicalInterface) { - case PhysicalInterface::JTAG: { + case TargetPhysicalInterface::JTAG: { maxHardwareBreakpoints = this->family == Family::XMEGA ? 2 : 3; break; } - case PhysicalInterface::PDI: { + case TargetPhysicalInterface::PDI: { maxHardwareBreakpoints = 2; break; } - case PhysicalInterface::UPDI: { + case TargetPhysicalInterface::UPDI: { maxHardwareBreakpoints = 1; break; } @@ -763,7 +761,7 @@ namespace Targets::Microchip::Avr::Avr8Bit ); } - if (!this->supportedPhysicalInterfaces.contains(PhysicalInterface::DEBUG_WIRE)) { + if (!this->physicalInterfaces.contains(TargetPhysicalInterface::DEBUG_WIRE)) { throw Exception( "Target does not support debugWire physical interface - check target configuration or " "report this issue via " + Services::PathService::homeDomainName() + "/report-issue" @@ -932,7 +930,7 @@ namespace Targets::Microchip::Avr::Avr8Bit using Services::PathService; using Services::StringService; - if (!this->supportedPhysicalInterfaces.contains(PhysicalInterface::JTAG)) { + if (!this->physicalInterfaces.contains(TargetPhysicalInterface::JTAG)) { throw Exception( "Target does not support JTAG physical interface - check target configuration or " "report this issue via " + PathService::homeDomainName() + "/report-issue" diff --git a/src/Targets/Microchip/AVR/AVR8/Avr8.hpp b/src/Targets/Microchip/AVR/AVR8/Avr8.hpp index d27d68fc..3fec75a2 100644 --- a/src/Targets/Microchip/AVR/AVR8/Avr8.hpp +++ b/src/Targets/Microchip/AVR/AVR8/Avr8.hpp @@ -18,6 +18,7 @@ #include "ProgrammingSession.hpp" #include "src/Targets/Microchip/AVR/Fuse.hpp" +#include "src/Targets/TargetPhysicalInterface.hpp" #include "src/Targets/TargetRegister.hpp" #include "src/Targets/TargetBreakpoint.hpp" @@ -119,7 +120,7 @@ namespace Targets::Microchip::Avr::Avr8Bit TargetParameters targetParameters; - std::set supportedPhysicalInterfaces; + std::set physicalInterfaces; std::map padDescriptorsByName; std::map targetVariantsById; diff --git a/src/Targets/Microchip/AVR/AVR8/Avr8TargetConfig.cpp b/src/Targets/Microchip/AVR/AVR8/Avr8TargetConfig.cpp index 746c33e5..d8bdaba6 100644 --- a/src/Targets/Microchip/AVR/AVR8/Avr8TargetConfig.cpp +++ b/src/Targets/Microchip/AVR/AVR8/Avr8TargetConfig.cpp @@ -14,25 +14,6 @@ namespace Targets::Microchip::Avr::Avr8Bit const auto& targetNode = targetConfig.targetNode; - if (!targetNode["physicalInterface"]) { - throw InvalidConfig("Missing physical interface config parameter for AVR8 target."); - } - - const auto physicalInterfaceName = Services::StringService::asciiToLower(targetNode["physicalInterface"].as()); - const auto physicalInterfaceIt = Avr8TargetConfig::debugPhysicalInterfacesByConfigName.find( - physicalInterfaceName - ); - - if (physicalInterfaceIt == Avr8TargetConfig::debugPhysicalInterfacesByConfigName.end()) { - throw InvalidConfig( - "Invalid physical interface provided (\"" + physicalInterfaceName + "\") for AVR8 target. " - "See " + Services::PathService::homeDomainName() + "/docs/configuration/avr8-physical-interfaces for valid physical " - "interface configuration values." - ); - } - - this->physicalInterface = physicalInterfaceIt->second; - // The 'manageDwenFuseBit' param used to be 'updateDwenFuseBit' - we still support the old, for now. if (targetNode["updateDwenFuseBit"]) { this->manageDwenFuseBit = targetNode["updateDwenFuseBit"].as( diff --git a/src/Targets/Microchip/AVR/AVR8/Avr8TargetConfig.hpp b/src/Targets/Microchip/AVR/AVR8/Avr8TargetConfig.hpp index 2c11d73d..8ad8bd20 100644 --- a/src/Targets/Microchip/AVR/AVR8/Avr8TargetConfig.hpp +++ b/src/Targets/Microchip/AVR/AVR8/Avr8TargetConfig.hpp @@ -6,8 +6,6 @@ #include "src/ProjectConfig.hpp" -#include "PhysicalInterface.hpp" - namespace Targets::Microchip::Avr::Avr8Bit { /** @@ -16,12 +14,6 @@ namespace Targets::Microchip::Avr::Avr8Bit struct Avr8TargetConfig: public TargetConfig { public: - /** - * The physical interface is the interface used for communication between the debug tool and the connected - * target. - */ - PhysicalInterface physicalInterface = PhysicalInterface::DEBUG_WIRE; - /** * Because the debugWire module requires control of the reset pin on the target, enabling this module will * effectively mean losing control of the reset pin. This means users won't be able to use other @@ -99,14 +91,5 @@ namespace Targets::Microchip::Avr::Avr8Bit bool reserveSteppingBreakpoint = true; explicit Avr8TargetConfig(const TargetConfig& targetConfig); - - private: - static inline auto debugPhysicalInterfacesByConfigName = std::map({ - {"debugwire", PhysicalInterface::DEBUG_WIRE}, // Deprecated - left here for backwards compatibility - {"debug-wire", PhysicalInterface::DEBUG_WIRE}, - {"pdi", PhysicalInterface::PDI}, - {"jtag", PhysicalInterface::JTAG}, - {"updi", PhysicalInterface::UPDI}, - }); }; } diff --git a/src/Targets/Microchip/AVR/AVR8/PhysicalInterface.cpp b/src/Targets/Microchip/AVR/AVR8/PhysicalInterface.cpp deleted file mode 100644 index 3332835e..00000000 --- a/src/Targets/Microchip/AVR/AVR8/PhysicalInterface.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "PhysicalInterface.hpp" - -namespace Targets::Microchip::Avr::Avr8Bit -{ - std::map getPhysicalInterfaceNames() { - return std::map({ - {PhysicalInterface::ISP, "ISP"}, - {PhysicalInterface::DEBUG_WIRE, "debugWire"}, - {PhysicalInterface::PDI, "PDI"}, - {PhysicalInterface::JTAG, "JTAG"}, - {PhysicalInterface::UPDI, "UPDI"}, - }); - } -} diff --git a/src/Targets/Microchip/AVR/AVR8/TargetDescription/TargetDescriptionFile.cpp b/src/Targets/Microchip/AVR/AVR8/TargetDescription/TargetDescriptionFile.cpp index 9997cc06..071b9727 100644 --- a/src/Targets/Microchip/AVR/AVR8/TargetDescription/TargetDescriptionFile.cpp +++ b/src/Targets/Microchip/AVR/AVR8/TargetDescription/TargetDescriptionFile.cpp @@ -21,7 +21,6 @@ namespace Targets::Microchip::Avr::Avr8Bit::TargetDescription TargetDescriptionFile::TargetDescriptionFile(const std::string& xmlFilePath) : Targets::TargetDescription::TargetDescriptionFile(xmlFilePath) { - this->loadSupportedPhysicalInterfaces(); this->loadPadDescriptors(); this->loadTargetVariants(); this->loadTargetRegisterDescriptors(); @@ -162,22 +161,22 @@ namespace Targets::Microchip::Avr::Avr8Bit::TargetDescription } } - const auto& supportedPhysicalInterfaces = this->getSupportedPhysicalInterfaces(); - - if ( - supportedPhysicalInterfaces.contains(PhysicalInterface::DEBUG_WIRE) - || supportedPhysicalInterfaces.contains(PhysicalInterface::JTAG) - ) { - this->loadDebugWireAndJtagTargetParameters(targetParameters); - } - - if (supportedPhysicalInterfaces.contains(PhysicalInterface::PDI)) { - this->loadPdiTargetParameters(targetParameters); - } - - if (supportedPhysicalInterfaces.contains(PhysicalInterface::UPDI)) { - this->loadUpdiTargetParameters(targetParameters); - } +// const auto& supportedPhysicalInterfaces = this->getSupportedPhysicalInterfaces(); +// +// if ( +// supportedPhysicalInterfaces.contains(PhysicalInterface::DEBUG_WIRE) +// || supportedPhysicalInterfaces.contains(PhysicalInterface::JTAG) +// ) { +// this->loadDebugWireAndJtagTargetParameters(targetParameters); +// } +// +// if (supportedPhysicalInterfaces.contains(PhysicalInterface::PDI)) { +// this->loadPdiTargetParameters(targetParameters); +// } +// +// if (supportedPhysicalInterfaces.contains(PhysicalInterface::UPDI)) { +// this->loadUpdiTargetParameters(targetParameters); +// } return targetParameters; } @@ -327,23 +326,6 @@ namespace Targets::Microchip::Avr::Avr8Bit::TargetDescription return this->getFuseBitsDescriptorByName("eesave"); } - void TargetDescriptionFile::loadSupportedPhysicalInterfaces() { - auto interfaceNamesToInterfaces = std::map({ - {"updi", PhysicalInterface::UPDI}, - {"debugwire", PhysicalInterface::DEBUG_WIRE}, - {"jtag", PhysicalInterface::JTAG}, - {"pdi", PhysicalInterface::PDI}, - {"isp", PhysicalInterface::ISP}, - }); - - for (const auto& [interfaceName, interface]: this->interfacesByName) { - const auto interfaceIt = interfaceNamesToInterfaces.find(interfaceName); - if (interfaceIt != interfaceNamesToInterfaces.end()) { - this->supportedPhysicalInterfaces.insert(interfaceIt->second); - } - } - } - void TargetDescriptionFile::loadPadDescriptors() { const auto portModuleIt = this->modulesMappedByName.find("port"); const auto portModule = (portModuleIt != this->modulesMappedByName.end()) diff --git a/src/Targets/Microchip/AVR/AVR8/TargetDescription/TargetDescriptionFile.hpp b/src/Targets/Microchip/AVR/AVR8/TargetDescription/TargetDescriptionFile.hpp index be5935bd..4a03977a 100644 --- a/src/Targets/Microchip/AVR/AVR8/TargetDescription/TargetDescriptionFile.hpp +++ b/src/Targets/Microchip/AVR/AVR8/TargetDescription/TargetDescriptionFile.hpp @@ -13,7 +13,6 @@ #include "src/Targets/Microchip/AVR/Fuse.hpp" #include "src/Targets/Microchip/AVR/AVR8/Family.hpp" -#include "src/Targets/Microchip/AVR/AVR8/PhysicalInterface.hpp" #include "src/Targets/Microchip/AVR/AVR8/TargetParameters.hpp" #include "src/Targets/Microchip/AVR/AVR8/PadDescriptor.hpp" @@ -122,15 +121,6 @@ namespace Targets::Microchip::Avr::Avr8Bit::TargetDescription */ [[nodiscard]] std::optional getEesaveFuseBitsDescriptor() const; - /** - * Returns a set of all supported physical interfaces for debugging. - * - * @return - */ - [[nodiscard]] const auto& getSupportedPhysicalInterfaces() const { - return this->supportedPhysicalInterfaces; - } - /** * Returns a mapping of all pad descriptors extracted from TDF, mapped by name. * @@ -184,7 +174,6 @@ namespace Targets::Microchip::Avr::Avr8Bit::TargetDescription }; std::string avrFamilyName; - std::set supportedPhysicalInterfaces; std::map padDescriptorsByName; std::map targetVariantsById; diff --git a/src/Targets/TargetDescription/TargetDescriptionFile.cpp b/src/Targets/TargetDescription/TargetDescriptionFile.cpp index 7ba926f5..afdbd77d 100644 --- a/src/Targets/TargetDescription/TargetDescriptionFile.cpp +++ b/src/Targets/TargetDescription/TargetDescriptionFile.cpp @@ -97,6 +97,30 @@ namespace Targets::TargetDescription return addressSpace->get(); } + std::set TargetDescriptionFile::getPhysicalInterfaces() const { + static const auto physicalInterfacesByName = BiMap({ + {"updi", TargetPhysicalInterface::UPDI}, + {"debugwire", TargetPhysicalInterface::DEBUG_WIRE}, + {"jtag", TargetPhysicalInterface::JTAG}, + {"pdi", TargetPhysicalInterface::PDI}, + {"isp", TargetPhysicalInterface::ISP}, + }); + + auto output = std::set(); + + for (const auto& physicalInterface : this->physicalInterfaces) { + const auto interface = physicalInterfacesByName.valueAt( + StringService::asciiToLower(physicalInterface.name) + ); + + if (interface.has_value()) { + output.insert(*interface); + } + } + + return output; + } + void TargetDescriptionFile::init(const std::string& xmlFilePath) { auto file = QFile(QString::fromStdString(xmlFilePath)); if (!file.exists()) { diff --git a/src/Targets/TargetDescription/TargetDescriptionFile.hpp b/src/Targets/TargetDescription/TargetDescriptionFile.hpp index 5e9209a4..ef998f23 100644 --- a/src/Targets/TargetDescription/TargetDescriptionFile.hpp +++ b/src/Targets/TargetDescription/TargetDescriptionFile.hpp @@ -20,6 +20,7 @@ #include "Pinout.hpp" #include "src/Targets/TargetFamily.hpp" +#include "src/Targets/TargetPhysicalInterface.hpp" #include GENERATED_TDF_MAPPING_PATH @@ -99,6 +100,8 @@ namespace Targets::TargetDescription ) const; [[nodiscard]] const AddressSpace& getAddressSpace(std::string_view key) const; + [[nodiscard]] std::set getPhysicalInterfaces() const; + protected: std::map deviceAttributesByName; std::map> addressSpacesByKey; diff --git a/src/Targets/TargetPhysicalInterface.cpp b/src/Targets/TargetPhysicalInterface.cpp new file mode 100644 index 00000000..013054f2 --- /dev/null +++ b/src/Targets/TargetPhysicalInterface.cpp @@ -0,0 +1,14 @@ +#include "TargetPhysicalInterface.hpp" + +namespace Targets +{ + std::map getPhysicalInterfaceNames() { + return std::map({ + {TargetPhysicalInterface::ISP, "ISP"}, + {TargetPhysicalInterface::DEBUG_WIRE, "debugWire"}, + {TargetPhysicalInterface::PDI, "PDI"}, + {TargetPhysicalInterface::JTAG, "JTAG"}, + {TargetPhysicalInterface::UPDI, "UPDI"}, + }); + } +} diff --git a/src/Targets/Microchip/AVR/AVR8/PhysicalInterface.hpp b/src/Targets/TargetPhysicalInterface.hpp similarity index 62% rename from src/Targets/Microchip/AVR/AVR8/PhysicalInterface.hpp rename to src/Targets/TargetPhysicalInterface.hpp index 6450ae60..93a590f6 100644 --- a/src/Targets/Microchip/AVR/AVR8/PhysicalInterface.hpp +++ b/src/Targets/TargetPhysicalInterface.hpp @@ -4,9 +4,9 @@ #include #include -namespace Targets::Microchip::Avr::Avr8Bit +namespace Targets { - enum class PhysicalInterface: std::uint8_t + enum class TargetPhysicalInterface: std::uint8_t { ISP, JTAG, @@ -20,5 +20,5 @@ namespace Targets::Microchip::Avr::Avr8Bit * * @return */ - std::map getPhysicalInterfaceNames(); + std::map getPhysicalInterfaceNames(); }