Moved AVR8 physicalInterface config extraction out of EDBG driver
This commit is contained in:
@@ -52,39 +52,6 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
|
||||
using Bloom::Targets::TargetRegisters;
|
||||
|
||||
void EdbgAvr8Interface::configure(const TargetConfig& targetConfig) {
|
||||
auto physicalInterface = targetConfig.jsonObject.find("physicalInterface")->toString().toLower().toStdString();
|
||||
|
||||
auto availablePhysicalInterfaces = this->getPhysicalInterfacesByName();
|
||||
|
||||
if (physicalInterface.empty()
|
||||
|| availablePhysicalInterfaces.find(physicalInterface) == availablePhysicalInterfaces.end()
|
||||
) {
|
||||
throw InvalidConfig("Invalid or missing physical interface config parameter for AVR8 target.");
|
||||
}
|
||||
|
||||
auto selectedPhysicalInterface = availablePhysicalInterfaces.find(physicalInterface)->second;
|
||||
|
||||
if (selectedPhysicalInterface == PhysicalInterface::DEBUG_WIRE) {
|
||||
Logger::warning("AVR8 debugWire interface selected - the DWEN fuse will need to be enabled");
|
||||
}
|
||||
|
||||
this->physicalInterface = selectedPhysicalInterface;
|
||||
|
||||
if (!this->family.has_value()) {
|
||||
if (this->physicalInterface == PhysicalInterface::JTAG) {
|
||||
throw InvalidConfig("The JTAG physical interface cannot be used with an ambiguous target name"
|
||||
" - please specify the exact name of the target in your configuration file. "
|
||||
"See " + Paths::homeDomainName() + "/docs/supported-targets"
|
||||
);
|
||||
|
||||
} else if (this->physicalInterface == PhysicalInterface::UPDI) {
|
||||
throw InvalidConfig("The UPDI physical interface cannot be used with an ambiguous target name"
|
||||
" - please specify the exact name of the target in your configuration file. "
|
||||
"See " + Paths::homeDomainName() + "/docs/supported-targets"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
this->configVariant = this->resolveConfigVariant().value_or(Avr8ConfigVariant::NONE);
|
||||
|
||||
if (targetConfig.jsonObject.contains("disableDebugWirePreDisconnect")) {
|
||||
|
||||
@@ -83,6 +83,10 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
|
||||
*/
|
||||
void configure(const TargetConfig& targetConfig) override;
|
||||
|
||||
void setPhysicalInterface(Targets::Microchip::Avr::Avr8Bit::PhysicalInterface physicalInterface) override {
|
||||
this->physicalInterface = physicalInterface;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the target family. For some physical interfaces, the target family is required in order
|
||||
* properly configure the EDBG tool. See EdbgAvr8Interface::resolveConfigVariant() for more.
|
||||
@@ -346,22 +350,6 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
|
||||
*/
|
||||
bool disableDebugWireOnDeactivate = false;
|
||||
|
||||
/**
|
||||
* Users are required to set their desired physical interface in their Bloom configuration. This would take
|
||||
* the form of a string, so we map the available options to the appropriate enums.
|
||||
*/
|
||||
static inline auto getPhysicalInterfacesByName() {
|
||||
using Targets::Microchip::Avr::Avr8Bit::PhysicalInterface;
|
||||
|
||||
return std::map<std::string, PhysicalInterface>({
|
||||
{"debugwire", PhysicalInterface::DEBUG_WIRE},
|
||||
{"debug-wire", PhysicalInterface::DEBUG_WIRE},
|
||||
{"pdi", PhysicalInterface::PDI},
|
||||
{"jtag", PhysicalInterface::JTAG},
|
||||
{"updi", PhysicalInterface::UPDI},
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* This mapping allows us to determine which config variant to select, based on the target family and the
|
||||
* selected physical interface.
|
||||
|
||||
@@ -4,8 +4,10 @@
|
||||
#include <set>
|
||||
|
||||
#include "src/Targets/Microchip/AVR/TargetSignature.hpp"
|
||||
#include "src/Targets/Microchip/AVR/AVR8/TargetParameters.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/TargetState.hpp"
|
||||
#include "src/Targets/TargetRegister.hpp"
|
||||
#include "src/Targets/TargetMemory.hpp"
|
||||
@@ -54,6 +56,13 @@ namespace Bloom::DebugToolDrivers::TargetInterfaces::Microchip::Avr::Avr8
|
||||
*/
|
||||
virtual void setFamily(Targets::Microchip::Avr::Avr8Bit::Family family) = 0;
|
||||
|
||||
/**
|
||||
* Sets the selected physical interface.
|
||||
*
|
||||
* @param physicalInterface
|
||||
*/
|
||||
virtual void setPhysicalInterface(Targets::Microchip::Avr::Avr8Bit::PhysicalInterface physicalInterface) = 0;
|
||||
|
||||
/**
|
||||
* Should accept Avr8 target parameters for configuration of the interface.
|
||||
*
|
||||
|
||||
@@ -7,11 +7,11 @@
|
||||
#include <bitset>
|
||||
#include <limits>
|
||||
|
||||
#include "PadDescriptor.hpp"
|
||||
#include "src/Logger/Logger.hpp"
|
||||
#include "src/Helpers/Paths.hpp"
|
||||
|
||||
#include "src/Exceptions/InvalidConfig.hpp"
|
||||
#include "src/Targets/TargetRegister.hpp"
|
||||
#include "src/Targets/Microchip/AVR/AVR8/TargetDescription/TargetDescriptionFile.hpp"
|
||||
|
||||
// Derived AVR8 targets
|
||||
#include "XMega/XMega.hpp"
|
||||
@@ -25,8 +25,42 @@ namespace Bloom::Targets::Microchip::Avr::Avr8Bit
|
||||
void Avr8::preActivationConfigure(const TargetConfig& targetConfig) {
|
||||
Target::preActivationConfigure(targetConfig);
|
||||
|
||||
auto physicalInterface = targetConfig.jsonObject.find("physicalInterface")->toString().toLower().toStdString();
|
||||
auto availablePhysicalInterfaces = Avr8::getPhysicalInterfacesByName();
|
||||
|
||||
if (physicalInterface.empty() || !availablePhysicalInterfaces.contains(physicalInterface)) {
|
||||
throw InvalidConfig("Invalid or missing physical interface config parameter for AVR8 target.");
|
||||
}
|
||||
|
||||
const auto selectedPhysicalInterface = availablePhysicalInterfaces.at(physicalInterface);
|
||||
|
||||
if (selectedPhysicalInterface == PhysicalInterface::DEBUG_WIRE) {
|
||||
Logger::warning("AVR8 debugWire interface selected - the DWEN fuse will need to be enabled");
|
||||
}
|
||||
|
||||
this->physicalInterface = selectedPhysicalInterface;
|
||||
this->avr8DebugInterface->setPhysicalInterface(this->physicalInterface.value());
|
||||
|
||||
if (this->family.has_value()) {
|
||||
this->avr8DebugInterface->setFamily(this->family.value());
|
||||
|
||||
} else {
|
||||
if (this->physicalInterface == PhysicalInterface::JTAG) {
|
||||
throw InvalidConfig(
|
||||
"The JTAG physical interface cannot be used with an ambiguous target name"
|
||||
" - please specify the exact name of the target in your configuration file. "
|
||||
"See " + Paths::homeDomainName() + "/docs/supported-targets"
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
if (this->physicalInterface == PhysicalInterface::UPDI) {
|
||||
throw InvalidConfig(
|
||||
"The UPDI physical interface cannot be used with an ambiguous target name"
|
||||
" - please specify the exact name of the target in your configuration file. "
|
||||
"See " + Paths::homeDomainName() + "/docs/supported-targets"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
this->avr8DebugInterface->configure(targetConfig);
|
||||
|
||||
@@ -122,13 +122,30 @@ namespace Bloom::Targets::Microchip::Avr::Avr8Bit
|
||||
DebugToolDrivers::TargetInterfaces::Microchip::Avr::Avr8::Avr8DebugInterface* avr8DebugInterface = nullptr;
|
||||
std::string name;
|
||||
std::optional<Family> family;
|
||||
std::optional<PhysicalInterface> physicalInterface;
|
||||
std::optional<TargetDescription::TargetDescriptionFile> targetDescriptionFile;
|
||||
|
||||
std::optional<TargetParameters> targetParameters;
|
||||
std::map<std::string, PadDescriptor> padDescriptorsByName;
|
||||
std::map<int, TargetVariant> targetVariantsById;
|
||||
std::map<TargetRegisterType, TargetRegisterDescriptors> targetRegisterDescriptorsByType;
|
||||
std::map<TargetMemoryType, TargetMemoryDescriptor> targetMemoryDescriptorsByType;
|
||||
|
||||
/**
|
||||
* Users are required to set their desired physical interface in their Bloom configuration. This would take
|
||||
* the form of a string, so we map the available options to the appropriate enums.
|
||||
*/
|
||||
static inline auto getPhysicalInterfacesByName() {
|
||||
using Targets::Microchip::Avr::Avr8Bit::PhysicalInterface;
|
||||
|
||||
return std::map<std::string, PhysicalInterface>({
|
||||
{"debugwire", PhysicalInterface::DEBUG_WIRE},
|
||||
{"debug-wire", PhysicalInterface::DEBUG_WIRE},
|
||||
{"pdi", PhysicalInterface::PDI},
|
||||
{"jtag", PhysicalInterface::JTAG},
|
||||
{"updi", PhysicalInterface::UPDI},
|
||||
});
|
||||
};
|
||||
/**
|
||||
* Resolves the appropriate TDF for the AVR8 target and populates this->targetDescriptionFile.
|
||||
*/
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
|
||||
#include "../../Target.hpp"
|
||||
#include "src/Targets/Target.hpp"
|
||||
|
||||
#include "TargetSignature.hpp"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user