Made physical interface enum more generic (moved out of AVR8-specific context)

This commit is contained in:
Nav
2024-02-15 21:24:41 +00:00
parent f33b4d8c70
commit 7e9e28286f
20 changed files with 156 additions and 160 deletions

View File

@@ -2,7 +2,7 @@
#include <map> #include <map>
#include "src/Targets/Microchip/AVR/AVR8/PhysicalInterface.hpp" #include "src/Targets/TargetPhysicalInterface.hpp"
namespace DebugToolDrivers::Microchip::Protocols::Edbg::Avr namespace DebugToolDrivers::Microchip::Protocols::Edbg::Avr
{ {
@@ -103,14 +103,14 @@ namespace DebugToolDrivers::Microchip::Protocols::Edbg::Avr
DEBUGGING = 0x02, DEBUGGING = 0x02,
}; };
static inline auto getAvr8PhysicalInterfaceToIdMapping() { static inline auto getPhysicalInterfaceToAvr8IdMapping() {
using Targets::Microchip::Avr::Avr8Bit::PhysicalInterface; using Targets::TargetPhysicalInterface;
return std::map<PhysicalInterface, unsigned char>({ return std::map<TargetPhysicalInterface, unsigned char>({
{PhysicalInterface::DEBUG_WIRE, 0x05}, {TargetPhysicalInterface::DEBUG_WIRE, 0x05},
{PhysicalInterface::PDI, 0x06}, {TargetPhysicalInterface::PDI, 0x06},
{PhysicalInterface::JTAG, 0x04}, {TargetPhysicalInterface::JTAG, 0x04},
{PhysicalInterface::UPDI, 0x08}, {TargetPhysicalInterface::UPDI, 0x08},
}); });
} }

View File

@@ -76,6 +76,7 @@ namespace DebugToolDrivers::Microchip::Protocols::Edbg::Avr
using CommandFrames::Avr8Generic::DisableDebugWire; using CommandFrames::Avr8Generic::DisableDebugWire;
using Targets::TargetState; using Targets::TargetState;
using Targets::TargetPhysicalInterface;
using Targets::TargetMemoryType; using Targets::TargetMemoryType;
using Targets::TargetMemoryBuffer; using Targets::TargetMemoryBuffer;
using Targets::TargetMemoryAddress; using Targets::TargetMemoryAddress;
@@ -135,7 +136,7 @@ namespace DebugToolDrivers::Microchip::Protocols::Edbg::Avr
this->setParameter( this->setParameter(
Avr8EdbgParameters::PHYSICAL_INTERFACE, Avr8EdbgParameters::PHYSICAL_INTERFACE,
getAvr8PhysicalInterfaceToIdMapping().at(this->targetConfig.physicalInterface) getPhysicalInterfaceToAvr8IdMapping().at(this->targetConfig.physicalInterface)
); );
this->setTargetParameters(); this->setTargetParameters();
@@ -227,7 +228,7 @@ namespace DebugToolDrivers::Microchip::Protocols::Edbg::Avr
} catch (const Avr8CommandFailure& activationException) { } catch (const Avr8CommandFailure& activationException) {
if ( if (
this->targetConfig.physicalInterface == PhysicalInterface::DEBUG_WIRE this->targetConfig.physicalInterface == TargetPhysicalInterface::DEBUG_WIRE
&& ( && (
activationException.code == Avr8CommandFailureCode::DEBUGWIRE_PHYSICAL_ERROR activationException.code == Avr8CommandFailureCode::DEBUGWIRE_PHYSICAL_ERROR
|| activationException.code == Avr8CommandFailureCode::FAILED_TO_ENABLE_OCD || activationException.code == Avr8CommandFailureCode::FAILED_TO_ENABLE_OCD
@@ -252,7 +253,7 @@ namespace DebugToolDrivers::Microchip::Protocols::Edbg::Avr
void EdbgAvr8Interface::deactivate() { void EdbgAvr8Interface::deactivate() {
if (this->targetAttached) { if (this->targetAttached) {
if ( if (
this->targetConfig.physicalInterface == PhysicalInterface::DEBUG_WIRE this->targetConfig.physicalInterface == TargetPhysicalInterface::DEBUG_WIRE
&& this->targetConfig.disableDebugWireOnDeactivate && this->targetConfig.disableDebugWireOnDeactivate
) { ) {
try { try {
@@ -947,54 +948,54 @@ namespace DebugToolDrivers::Microchip::Protocols::Edbg::Avr
} }
} }
std::map<Family, std::map<PhysicalInterface, Avr8ConfigVariant>> std::map<Family, std::map<TargetPhysicalInterface, Avr8ConfigVariant>>
EdbgAvr8Interface::getConfigVariantsByFamilyAndPhysicalInterface() { EdbgAvr8Interface::getConfigVariantsByFamilyAndPhysicalInterface() {
return std::map<Family, std::map<PhysicalInterface, Avr8ConfigVariant>>({ return std::map<Family, std::map<TargetPhysicalInterface, Avr8ConfigVariant>>({
{ {
Family::MEGA, Family::MEGA,
{ {
{PhysicalInterface::JTAG, Avr8ConfigVariant::MEGAJTAG}, {TargetPhysicalInterface::JTAG, Avr8ConfigVariant::MEGAJTAG},
{PhysicalInterface::DEBUG_WIRE, Avr8ConfigVariant::DEBUG_WIRE}, {TargetPhysicalInterface::DEBUG_WIRE, Avr8ConfigVariant::DEBUG_WIRE},
{PhysicalInterface::UPDI, Avr8ConfigVariant::UPDI}, {TargetPhysicalInterface::UPDI, Avr8ConfigVariant::UPDI},
} }
}, },
{ {
Family::TINY, Family::TINY,
{ {
{PhysicalInterface::JTAG, Avr8ConfigVariant::MEGAJTAG}, {TargetPhysicalInterface::JTAG, Avr8ConfigVariant::MEGAJTAG},
{PhysicalInterface::DEBUG_WIRE, Avr8ConfigVariant::DEBUG_WIRE}, {TargetPhysicalInterface::DEBUG_WIRE, Avr8ConfigVariant::DEBUG_WIRE},
{PhysicalInterface::UPDI, Avr8ConfigVariant::UPDI}, {TargetPhysicalInterface::UPDI, Avr8ConfigVariant::UPDI},
} }
}, },
{ {
Family::XMEGA, Family::XMEGA,
{ {
{PhysicalInterface::JTAG, Avr8ConfigVariant::XMEGA}, {TargetPhysicalInterface::JTAG, Avr8ConfigVariant::XMEGA},
{PhysicalInterface::PDI, Avr8ConfigVariant::XMEGA}, {TargetPhysicalInterface::PDI, Avr8ConfigVariant::XMEGA},
} }
}, },
{ {
Family::DA, Family::DA,
{ {
{PhysicalInterface::UPDI, Avr8ConfigVariant::UPDI}, {TargetPhysicalInterface::UPDI, Avr8ConfigVariant::UPDI},
} }
}, },
{ {
Family::DB, Family::DB,
{ {
{PhysicalInterface::UPDI, Avr8ConfigVariant::UPDI}, {TargetPhysicalInterface::UPDI, Avr8ConfigVariant::UPDI},
} }
}, },
{ {
Family::DD, Family::DD,
{ {
{PhysicalInterface::UPDI, Avr8ConfigVariant::UPDI}, {TargetPhysicalInterface::UPDI, Avr8ConfigVariant::UPDI},
} }
}, },
{ {
Family::EA, Family::EA,
{ {
{PhysicalInterface::UPDI, Avr8ConfigVariant::UPDI}, {TargetPhysicalInterface::UPDI, Avr8ConfigVariant::UPDI},
} }
}, },
}); });
@@ -1002,7 +1003,7 @@ namespace DebugToolDrivers::Microchip::Protocols::Edbg::Avr
Avr8ConfigVariant EdbgAvr8Interface::resolveConfigVariant( Avr8ConfigVariant EdbgAvr8Interface::resolveConfigVariant(
Targets::Microchip::Avr::Avr8Bit::Family targetFamily, Targets::Microchip::Avr::Avr8Bit::Family targetFamily,
Targets::Microchip::Avr::Avr8Bit::PhysicalInterface physicalInterface TargetPhysicalInterface physicalInterface
) { ) {
const auto configVariantsByFamily = EdbgAvr8Interface::getConfigVariantsByFamilyAndPhysicalInterface(); const auto configVariantsByFamily = EdbgAvr8Interface::getConfigVariantsByFamilyAndPhysicalInterface();
const auto configVariantsByPhysicalInterfaceIt = configVariantsByFamily.find(targetFamily); const auto configVariantsByPhysicalInterfaceIt = configVariantsByFamily.find(targetFamily);

View File

@@ -11,10 +11,10 @@
#include "Avr8Generic.hpp" #include "Avr8Generic.hpp"
#include "src/Targets/TargetPhysicalInterface.hpp"
#include "src/Targets/TargetMemory.hpp" #include "src/Targets/TargetMemory.hpp"
#include "src/Targets/TargetRegister.hpp" #include "src/Targets/TargetRegister.hpp"
#include "src/Targets/Microchip/AVR/AVR8/Family.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/TargetParameters.hpp"
namespace DebugToolDrivers::Microchip::Protocols::Edbg::Avr namespace DebugToolDrivers::Microchip::Protocols::Edbg::Avr
@@ -384,7 +384,7 @@ namespace DebugToolDrivers::Microchip::Protocols::Edbg::Avr
*/ */
static std::map< static std::map<
Targets::Microchip::Avr::Avr8Bit::Family, Targets::Microchip::Avr::Avr8Bit::Family,
std::map<Targets::Microchip::Avr::Avr8Bit::PhysicalInterface, Avr8ConfigVariant> std::map<Targets::TargetPhysicalInterface, Avr8ConfigVariant>
> getConfigVariantsByFamilyAndPhysicalInterface(); > getConfigVariantsByFamilyAndPhysicalInterface();
/** /**
@@ -394,7 +394,7 @@ namespace DebugToolDrivers::Microchip::Protocols::Edbg::Avr
*/ */
static Avr8ConfigVariant resolveConfigVariant( static Avr8ConfigVariant resolveConfigVariant(
Targets::Microchip::Avr::Avr8Bit::Family targetFamily, Targets::Microchip::Avr::Avr8Bit::Family targetFamily,
Targets::Microchip::Avr::Avr8Bit::PhysicalInterface physicalInterface Targets::TargetPhysicalInterface physicalInterface
); );
/** /**

View File

@@ -7,27 +7,27 @@ namespace DebugToolDrivers::Microchip::Protocols::Edbg::Avr::ResponseFrames::Avr
{} {}
Targets::Microchip::Avr::TargetSignature GetDeviceId::extractSignature( Targets::Microchip::Avr::TargetSignature GetDeviceId::extractSignature(
Targets::Microchip::Avr::Avr8Bit::PhysicalInterface physicalInterface Targets::TargetPhysicalInterface physicalInterface
) const { ) const {
using Targets::Microchip::Avr::Avr8Bit::PhysicalInterface; using Targets::TargetPhysicalInterface;
const auto payloadData = this->getPayloadData(); const auto payloadData = this->getPayloadData();
switch (physicalInterface) { switch (physicalInterface) {
case PhysicalInterface::DEBUG_WIRE: { case TargetPhysicalInterface::DEBUG_WIRE: {
/* /*
* When using the DebugWire physical interface, the get device ID command will return * When using the DebugWire physical interface, the get device ID command will return
* four bytes, where the first can be ignored. * four bytes, where the first can be ignored.
*/ */
return Targets::Microchip::Avr::TargetSignature(payloadData[1], payloadData[2], payloadData[3]); return Targets::Microchip::Avr::TargetSignature(payloadData[1], payloadData[2], payloadData[3]);
} }
case PhysicalInterface::PDI: case TargetPhysicalInterface::PDI:
case PhysicalInterface::UPDI: { case TargetPhysicalInterface::UPDI: {
/* /*
* When using the PDI physical interface, the signature is returned in LSB format. * When using the PDI physical interface, the signature is returned in LSB format.
*/ */
return Targets::Microchip::Avr::TargetSignature(payloadData[3], payloadData[2], payloadData[1]); 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 * When using the JTAG interface, the get device ID command returns a 32 bit JTAG ID. This takes
* the following form: * the following form:

View File

@@ -3,7 +3,7 @@
#include "Avr8GenericResponseFrame.hpp" #include "Avr8GenericResponseFrame.hpp"
#include "src/Targets/Microchip/AVR/TargetSignature.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 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<AvrResponse>& AvrResponses); explicit GetDeviceId(const std::vector<AvrResponse>& AvrResponses);
Targets::Microchip::Avr::TargetSignature extractSignature( Targets::Microchip::Avr::TargetSignature extractSignature(
Targets::Microchip::Avr::Avr8Bit::PhysicalInterface physicalInterface Targets::TargetPhysicalInterface physicalInterface
) const; ) const;
}; };
} }

View File

@@ -8,7 +8,6 @@
#include "src/Targets/Microchip/AVR/TargetSignature.hpp" #include "src/Targets/Microchip/AVR/TargetSignature.hpp"
#include "src/Targets/Microchip/AVR/AVR8/Family.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/ProgramMemorySection.hpp"
#include "src/Targets/Microchip/AVR/AVR8/TargetParameters.hpp" #include "src/Targets/Microchip/AVR/AVR8/TargetParameters.hpp"

View File

@@ -153,6 +153,8 @@ EnvironmentConfig::EnvironmentConfig(std::string name, const YAML::Node& environ
} }
TargetConfig::TargetConfig(const YAML::Node& targetNode) { TargetConfig::TargetConfig(const YAML::Node& targetNode) {
using Targets::TargetPhysicalInterface;
if (!targetNode.IsMap()) { if (!targetNode.IsMap()) {
throw Exceptions::InvalidConfig( throw Exceptions::InvalidConfig(
"Invalid target configuration provided - node must take the form of a YAML mapping." "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<std::string>()); this->name = StringService::asciiToLower(targetNode["name"].as<std::string>());
static auto physicalInterfacesByConfigName = std::map<std::string, TargetPhysicalInterface>({
{"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<std::string>());
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"]) { if (targetNode["variantName"]) {
this->variantName = StringService::asciiToLower(targetNode["variantName"].as<std::string>()); this->variantName = StringService::asciiToLower(targetNode["variantName"].as<std::string>());
} }

View File

@@ -6,6 +6,8 @@
#include <optional> #include <optional>
#include <yaml-cpp/yaml.h> #include <yaml-cpp/yaml.h>
#include "src/Targets/TargetPhysicalInterface.hpp"
/* /*
* Currently, all user configuration is stored in a YAML file (bloom.yaml), in the user's project directory. * 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; 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. * The name of the selected target variant.
* *

View File

@@ -4,9 +4,9 @@ target_sources(
${CMAKE_CURRENT_SOURCE_DIR}/TargetDescription/TargetDescriptionFile.cpp ${CMAKE_CURRENT_SOURCE_DIR}/TargetDescription/TargetDescriptionFile.cpp
${CMAKE_CURRENT_SOURCE_DIR}/TargetRegister.cpp ${CMAKE_CURRENT_SOURCE_DIR}/TargetRegister.cpp
${CMAKE_CURRENT_SOURCE_DIR}/TargetMemoryCache.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/Avr8.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Microchip/AVR/AVR8/Avr8TargetConfig.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/TargetDescription/TargetDescriptionFile.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Microchip/AVR/AVR8/OpcodeDecoder/Decoder.cpp ${CMAKE_CURRENT_SOURCE_DIR}/Microchip/AVR/AVR8/OpcodeDecoder/Decoder.cpp
${CMAKE_CURRENT_SOURCE_DIR}/RiscV/RiscV.cpp ${CMAKE_CURRENT_SOURCE_DIR}/RiscV/RiscV.cpp

View File

@@ -25,7 +25,7 @@ namespace Targets::Microchip::Avr::Avr8Bit
, name(this->targetDescriptionFile.getTargetName()) , name(this->targetDescriptionFile.getTargetName())
, family(this->targetDescriptionFile.getAvrFamily()) , family(this->targetDescriptionFile.getAvrFamily())
, targetParameters(this->targetDescriptionFile.getTargetParameters()) , targetParameters(this->targetDescriptionFile.getTargetParameters())
, supportedPhysicalInterfaces(this->targetDescriptionFile.getSupportedPhysicalInterfaces()) , physicalInterfaces(this->targetDescriptionFile.getPhysicalInterfaces())
, padDescriptorsByName(this->targetDescriptionFile.getPadDescriptorsMappedByName()) , padDescriptorsByName(this->targetDescriptionFile.getPadDescriptorsMappedByName())
, targetVariantsById(this->targetDescriptionFile.getVariantsMappedById()) , targetVariantsById(this->targetDescriptionFile.getVariantsMappedById())
, stackPointerRegisterDescriptor( , stackPointerRegisterDescriptor(
@@ -54,24 +54,24 @@ namespace Targets::Microchip::Avr::Avr8Bit
) )
, fuseEnableStrategy(this->targetDescriptionFile.getFuseEnableStrategy().value_or(FuseEnableStrategy::CLEAR)) , 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 * The user has selected a physical interface that does not appear to be supported by the selected
* target. * target.
* *
* Bloom's target description files provide a list of supported physical interfaces for each 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 * 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. * user with a warning and a list of physical interfaces known to be supported by their selected target.
*/ */
const auto physicalInterfaceNames = getPhysicalInterfaceNames(); const auto physicalInterfaceNames = getPhysicalInterfaceNames();
const auto supportedPhysicalInterfaceList = std::accumulate( const auto supportedPhysicalInterfaceList = std::accumulate(
this->supportedPhysicalInterfaces.begin(), this->physicalInterfaces.begin(),
this->supportedPhysicalInterfaces.end(), this->physicalInterfaces.end(),
std::string(), std::string(),
[&physicalInterfaceNames] (const std::string& string, PhysicalInterface physicalInterface) { [&physicalInterfaceNames] (const std::string& string, TargetPhysicalInterface physicalInterface) {
if (physicalInterface == PhysicalInterface::ISP) { if (physicalInterface == TargetPhysicalInterface::ISP) {
/* /*
* Don't include the ISP interface in the list of supported interfaces, as doing so may * 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. * 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 " + physicalInterfaceNames.at(this->targetConfig.physicalInterface) + "). Target activation "
"will likely fail. The target supports the following physical interfaces: \n" "will likely fail. The target supports the following physical interfaces: \n"
+ supportedPhysicalInterfaceList + "\n\nFor physical interface configuration values, see " + supportedPhysicalInterfaceList + "\n\nFor physical interface configuration values, see "
+ Services::PathService::homeDomainName() + "/docs/configuration/avr8-physical-interfaces. \n\n" + Services::PathService::homeDomainName() + "/docs/configuration/target-physical-interfaces."
+ "If this information is incorrect, please report this to Bloom developers via "
+ Services::PathService::homeDomainName() + "/report-issue.\n"
); );
} }
if ( if (
this->targetConfig.manageOcdenFuseBit this->targetConfig.manageOcdenFuseBit
&& this->targetConfig.physicalInterface != PhysicalInterface::JTAG && this->targetConfig.physicalInterface != TargetPhysicalInterface::JTAG
) { ) {
Logger::warning( Logger::warning(
"The 'manageOcdenFuseBit' parameter only applies to JTAG targets. It will be ignored in this session." "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 ( if (
this->targetConfig.manageDwenFuseBit this->targetConfig.manageDwenFuseBit
&& this->avrIspInterface == nullptr && this->avrIspInterface == nullptr
&& this->targetConfig.physicalInterface == PhysicalInterface::DEBUG_WIRE && this->targetConfig.physicalInterface == TargetPhysicalInterface::DEBUG_WIRE
) { ) {
Logger::warning( Logger::warning(
"The connected debug tool (or associated driver) does not provide any ISP interface. " "The connected debug tool (or associated driver) does not provide any ISP interface. "
@@ -210,7 +208,7 @@ namespace Targets::Microchip::Avr::Avr8Bit
} }
if ( if (
this->targetConfig.physicalInterface == PhysicalInterface::JTAG this->targetConfig.physicalInterface == TargetPhysicalInterface::JTAG
&& this->targetConfig.manageOcdenFuseBit && this->targetConfig.manageOcdenFuseBit
) { ) {
Logger::debug("Attempting OCDEN fuse bit management"); Logger::debug("Attempting OCDEN fuse bit management");
@@ -248,7 +246,7 @@ namespace Targets::Microchip::Avr::Avr8Bit
this->clearAllBreakpoints(); this->clearAllBreakpoints();
if ( if (
this->targetConfig.physicalInterface == PhysicalInterface::JTAG this->targetConfig.physicalInterface == TargetPhysicalInterface::JTAG
&& this->targetConfig.manageOcdenFuseBit && this->targetConfig.manageOcdenFuseBit
) { ) {
Logger::debug("Attempting OCDEN fuse bit management"); Logger::debug("Attempting OCDEN fuse bit management");
@@ -357,7 +355,7 @@ namespace Targets::Microchip::Avr::Avr8Bit
void Avr8::eraseMemory(TargetMemoryType memoryType) { void Avr8::eraseMemory(TargetMemoryType memoryType) {
if (memoryType == TargetMemoryType::FLASH) { 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 // debugWire targets do not need to be erased
return; 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. * the chip erase. The fuse will be restored to its original value at the end of the programming session.
*/ */
if ( if (
this->targetConfig.physicalInterface == PhysicalInterface::JTAG this->targetConfig.physicalInterface == TargetPhysicalInterface::JTAG
|| this->targetConfig.physicalInterface == PhysicalInterface::UPDI || this->targetConfig.physicalInterface == TargetPhysicalInterface::UPDI
) { ) {
if (this->targetConfig.preserveEeprom) { if (this->targetConfig.preserveEeprom) {
Logger::debug("Inspecting EESAVE fuse bit"); Logger::debug("Inspecting EESAVE fuse bit");
@@ -705,15 +703,15 @@ namespace Targets::Microchip::Avr::Avr8Bit
auto maxHardwareBreakpoints = static_cast<std::uint16_t>(0); auto maxHardwareBreakpoints = static_cast<std::uint16_t>(0);
switch (this->targetConfig.physicalInterface) { switch (this->targetConfig.physicalInterface) {
case PhysicalInterface::JTAG: { case TargetPhysicalInterface::JTAG: {
maxHardwareBreakpoints = this->family == Family::XMEGA ? 2 : 3; maxHardwareBreakpoints = this->family == Family::XMEGA ? 2 : 3;
break; break;
} }
case PhysicalInterface::PDI: { case TargetPhysicalInterface::PDI: {
maxHardwareBreakpoints = 2; maxHardwareBreakpoints = 2;
break; break;
} }
case PhysicalInterface::UPDI: { case TargetPhysicalInterface::UPDI: {
maxHardwareBreakpoints = 1; maxHardwareBreakpoints = 1;
break; 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( throw Exception(
"Target does not support debugWire physical interface - check target configuration or " "Target does not support debugWire physical interface - check target configuration or "
"report this issue via " + Services::PathService::homeDomainName() + "/report-issue" "report this issue via " + Services::PathService::homeDomainName() + "/report-issue"
@@ -932,7 +930,7 @@ namespace Targets::Microchip::Avr::Avr8Bit
using Services::PathService; using Services::PathService;
using Services::StringService; using Services::StringService;
if (!this->supportedPhysicalInterfaces.contains(PhysicalInterface::JTAG)) { if (!this->physicalInterfaces.contains(TargetPhysicalInterface::JTAG)) {
throw Exception( throw Exception(
"Target does not support JTAG physical interface - check target configuration or " "Target does not support JTAG physical interface - check target configuration or "
"report this issue via " + PathService::homeDomainName() + "/report-issue" "report this issue via " + PathService::homeDomainName() + "/report-issue"

View File

@@ -18,6 +18,7 @@
#include "ProgrammingSession.hpp" #include "ProgrammingSession.hpp"
#include "src/Targets/Microchip/AVR/Fuse.hpp" #include "src/Targets/Microchip/AVR/Fuse.hpp"
#include "src/Targets/TargetPhysicalInterface.hpp"
#include "src/Targets/TargetRegister.hpp" #include "src/Targets/TargetRegister.hpp"
#include "src/Targets/TargetBreakpoint.hpp" #include "src/Targets/TargetBreakpoint.hpp"
@@ -119,7 +120,7 @@ namespace Targets::Microchip::Avr::Avr8Bit
TargetParameters targetParameters; TargetParameters targetParameters;
std::set<PhysicalInterface> supportedPhysicalInterfaces; std::set<Targets::TargetPhysicalInterface> physicalInterfaces;
std::map<std::string, PadDescriptor> padDescriptorsByName; std::map<std::string, PadDescriptor> padDescriptorsByName;
std::map<int, TargetVariant> targetVariantsById; std::map<int, TargetVariant> targetVariantsById;

View File

@@ -14,25 +14,6 @@ namespace Targets::Microchip::Avr::Avr8Bit
const auto& targetNode = targetConfig.targetNode; 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<std::string>());
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. // The 'manageDwenFuseBit' param used to be 'updateDwenFuseBit' - we still support the old, for now.
if (targetNode["updateDwenFuseBit"]) { if (targetNode["updateDwenFuseBit"]) {
this->manageDwenFuseBit = targetNode["updateDwenFuseBit"].as<bool>( this->manageDwenFuseBit = targetNode["updateDwenFuseBit"].as<bool>(

View File

@@ -6,8 +6,6 @@
#include "src/ProjectConfig.hpp" #include "src/ProjectConfig.hpp"
#include "PhysicalInterface.hpp"
namespace Targets::Microchip::Avr::Avr8Bit namespace Targets::Microchip::Avr::Avr8Bit
{ {
/** /**
@@ -16,12 +14,6 @@ namespace Targets::Microchip::Avr::Avr8Bit
struct Avr8TargetConfig: public TargetConfig struct Avr8TargetConfig: public TargetConfig
{ {
public: 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 * 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 * 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; bool reserveSteppingBreakpoint = true;
explicit Avr8TargetConfig(const TargetConfig& targetConfig); explicit Avr8TargetConfig(const TargetConfig& targetConfig);
private:
static inline auto debugPhysicalInterfacesByConfigName = std::map<std::string, PhysicalInterface>({
{"debugwire", PhysicalInterface::DEBUG_WIRE}, // Deprecated - left here for backwards compatibility
{"debug-wire", PhysicalInterface::DEBUG_WIRE},
{"pdi", PhysicalInterface::PDI},
{"jtag", PhysicalInterface::JTAG},
{"updi", PhysicalInterface::UPDI},
});
}; };
} }

View File

@@ -1,14 +0,0 @@
#include "PhysicalInterface.hpp"
namespace Targets::Microchip::Avr::Avr8Bit
{
std::map<PhysicalInterface, std::string> getPhysicalInterfaceNames() {
return std::map<PhysicalInterface, std::string>({
{PhysicalInterface::ISP, "ISP"},
{PhysicalInterface::DEBUG_WIRE, "debugWire"},
{PhysicalInterface::PDI, "PDI"},
{PhysicalInterface::JTAG, "JTAG"},
{PhysicalInterface::UPDI, "UPDI"},
});
}
}

View File

@@ -21,7 +21,6 @@ namespace Targets::Microchip::Avr::Avr8Bit::TargetDescription
TargetDescriptionFile::TargetDescriptionFile(const std::string& xmlFilePath) TargetDescriptionFile::TargetDescriptionFile(const std::string& xmlFilePath)
: Targets::TargetDescription::TargetDescriptionFile(xmlFilePath) : Targets::TargetDescription::TargetDescriptionFile(xmlFilePath)
{ {
this->loadSupportedPhysicalInterfaces();
this->loadPadDescriptors(); this->loadPadDescriptors();
this->loadTargetVariants(); this->loadTargetVariants();
this->loadTargetRegisterDescriptors(); this->loadTargetRegisterDescriptors();
@@ -162,22 +161,22 @@ namespace Targets::Microchip::Avr::Avr8Bit::TargetDescription
} }
} }
const auto& supportedPhysicalInterfaces = this->getSupportedPhysicalInterfaces(); // const auto& supportedPhysicalInterfaces = this->getSupportedPhysicalInterfaces();
//
if ( // if (
supportedPhysicalInterfaces.contains(PhysicalInterface::DEBUG_WIRE) // supportedPhysicalInterfaces.contains(PhysicalInterface::DEBUG_WIRE)
|| supportedPhysicalInterfaces.contains(PhysicalInterface::JTAG) // || supportedPhysicalInterfaces.contains(PhysicalInterface::JTAG)
) { // ) {
this->loadDebugWireAndJtagTargetParameters(targetParameters); // this->loadDebugWireAndJtagTargetParameters(targetParameters);
} // }
//
if (supportedPhysicalInterfaces.contains(PhysicalInterface::PDI)) { // if (supportedPhysicalInterfaces.contains(PhysicalInterface::PDI)) {
this->loadPdiTargetParameters(targetParameters); // this->loadPdiTargetParameters(targetParameters);
} // }
//
if (supportedPhysicalInterfaces.contains(PhysicalInterface::UPDI)) { // if (supportedPhysicalInterfaces.contains(PhysicalInterface::UPDI)) {
this->loadUpdiTargetParameters(targetParameters); // this->loadUpdiTargetParameters(targetParameters);
} // }
return targetParameters; return targetParameters;
} }
@@ -327,23 +326,6 @@ namespace Targets::Microchip::Avr::Avr8Bit::TargetDescription
return this->getFuseBitsDescriptorByName("eesave"); return this->getFuseBitsDescriptorByName("eesave");
} }
void TargetDescriptionFile::loadSupportedPhysicalInterfaces() {
auto interfaceNamesToInterfaces = std::map<std::string, PhysicalInterface>({
{"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() { void TargetDescriptionFile::loadPadDescriptors() {
const auto portModuleIt = this->modulesMappedByName.find("port"); const auto portModuleIt = this->modulesMappedByName.find("port");
const auto portModule = (portModuleIt != this->modulesMappedByName.end()) const auto portModule = (portModuleIt != this->modulesMappedByName.end())

View File

@@ -13,7 +13,6 @@
#include "src/Targets/Microchip/AVR/Fuse.hpp" #include "src/Targets/Microchip/AVR/Fuse.hpp"
#include "src/Targets/Microchip/AVR/AVR8/Family.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/TargetParameters.hpp"
#include "src/Targets/Microchip/AVR/AVR8/PadDescriptor.hpp" #include "src/Targets/Microchip/AVR/AVR8/PadDescriptor.hpp"
@@ -122,15 +121,6 @@ namespace Targets::Microchip::Avr::Avr8Bit::TargetDescription
*/ */
[[nodiscard]] std::optional<FuseBitsDescriptor> getEesaveFuseBitsDescriptor() const; [[nodiscard]] std::optional<FuseBitsDescriptor> 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. * 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::string avrFamilyName;
std::set<PhysicalInterface> supportedPhysicalInterfaces;
std::map<std::string, PadDescriptor> padDescriptorsByName; std::map<std::string, PadDescriptor> padDescriptorsByName;
std::map<int, TargetVariant> targetVariantsById; std::map<int, TargetVariant> targetVariantsById;

View File

@@ -97,6 +97,30 @@ namespace Targets::TargetDescription
return addressSpace->get(); return addressSpace->get();
} }
std::set<TargetPhysicalInterface> TargetDescriptionFile::getPhysicalInterfaces() const {
static const auto physicalInterfacesByName = BiMap<std::string, TargetPhysicalInterface>({
{"updi", TargetPhysicalInterface::UPDI},
{"debugwire", TargetPhysicalInterface::DEBUG_WIRE},
{"jtag", TargetPhysicalInterface::JTAG},
{"pdi", TargetPhysicalInterface::PDI},
{"isp", TargetPhysicalInterface::ISP},
});
auto output = std::set<TargetPhysicalInterface>();
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) { void TargetDescriptionFile::init(const std::string& xmlFilePath) {
auto file = QFile(QString::fromStdString(xmlFilePath)); auto file = QFile(QString::fromStdString(xmlFilePath));
if (!file.exists()) { if (!file.exists()) {

View File

@@ -20,6 +20,7 @@
#include "Pinout.hpp" #include "Pinout.hpp"
#include "src/Targets/TargetFamily.hpp" #include "src/Targets/TargetFamily.hpp"
#include "src/Targets/TargetPhysicalInterface.hpp"
#include GENERATED_TDF_MAPPING_PATH #include GENERATED_TDF_MAPPING_PATH
@@ -99,6 +100,8 @@ namespace Targets::TargetDescription
) const; ) const;
[[nodiscard]] const AddressSpace& getAddressSpace(std::string_view key) const; [[nodiscard]] const AddressSpace& getAddressSpace(std::string_view key) const;
[[nodiscard]] std::set<Targets::TargetPhysicalInterface> getPhysicalInterfaces() const;
protected: protected:
std::map<std::string, std::string> deviceAttributesByName; std::map<std::string, std::string> deviceAttributesByName;
std::map<std::string, AddressSpace, std::less<void>> addressSpacesByKey; std::map<std::string, AddressSpace, std::less<void>> addressSpacesByKey;

View File

@@ -0,0 +1,14 @@
#include "TargetPhysicalInterface.hpp"
namespace Targets
{
std::map<TargetPhysicalInterface, std::string> getPhysicalInterfaceNames() {
return std::map<TargetPhysicalInterface, std::string>({
{TargetPhysicalInterface::ISP, "ISP"},
{TargetPhysicalInterface::DEBUG_WIRE, "debugWire"},
{TargetPhysicalInterface::PDI, "PDI"},
{TargetPhysicalInterface::JTAG, "JTAG"},
{TargetPhysicalInterface::UPDI, "UPDI"},
});
}
}

View File

@@ -4,9 +4,9 @@
#include <map> #include <map>
#include <string> #include <string>
namespace Targets::Microchip::Avr::Avr8Bit namespace Targets
{ {
enum class PhysicalInterface: std::uint8_t enum class TargetPhysicalInterface: std::uint8_t
{ {
ISP, ISP,
JTAG, JTAG,
@@ -20,5 +20,5 @@ namespace Targets::Microchip::Avr::Avr8Bit
* *
* @return * @return
*/ */
std::map<PhysicalInterface, std::string> getPhysicalInterfaceNames(); std::map<TargetPhysicalInterface, std::string> getPhysicalInterfaceNames();
} }