This commit is contained in:
Nav
2022-10-09 13:10:30 +01:00
parent bc8206ccc7
commit 87e230c589
3 changed files with 24 additions and 16 deletions

View File

@@ -120,8 +120,8 @@ namespace Bloom::Targets::Microchip::Avr::Avr8Bit
* file (which it would, if the user specified the exact target name in their project config - see
* Avr8::getId() and TargetControllerComponent::getSupportedTargets() for more).
*/
auto targetSignature = this->avr8DebugInterface->getDeviceId();
auto tdSignature = this->targetDescriptionFile->getTargetSignature();
const auto targetSignature = this->avr8DebugInterface->getDeviceId();
const auto tdSignature = this->targetDescriptionFile->getTargetSignature();
if (targetSignature != tdSignature) {
throw Exception(
@@ -149,7 +149,7 @@ namespace Bloom::Targets::Microchip::Avr::Avr8Bit
this->avr8DebugInterface->init();
if (this->targetDescriptionFile.has_value()) {
if (this->targetParameters.has_value()) {
this->avr8DebugInterface->setTargetParameters(this->targetParameters.value());
}
@@ -157,6 +157,8 @@ namespace Bloom::Targets::Microchip::Avr::Avr8Bit
this->avr8DebugInterface->activate();
} catch (const Exceptions::DebugWirePhysicalInterfaceError& debugWireException) {
// We failed to activate the debugWire physical interface. DWEN fuse bit may need updating.
if (!this->targetConfig->manageDwenFuseBit) {
throw TargetOperationFailure(
"Failed to activate debugWire physical interface - check target connection and DWEN fuse "
@@ -170,7 +172,7 @@ namespace Bloom::Targets::Microchip::Avr::Avr8Bit
"Failed to activate the debugWire physical interface - attempting to access target via "
"the ISP interface, for DWEN fuse bit inspection."
);
this->writeDwenFuseBit(true);
this->updateDwenFuseBit(true);
// If the debug tool provides a TargetPowerManagementInterface, attempt to cycle the target power
if (
@@ -763,7 +765,7 @@ namespace Bloom::Targets::Microchip::Avr::Avr8Bit
return this->id.value();
}
void Avr8::writeDwenFuseBit(bool setFuse) {
void Avr8::updateDwenFuseBit(bool enable) {
if (this->avrIspInterface == nullptr) {
throw Exception(
"Debug tool or driver does not provide access to an ISP interface - please confirm that the "
@@ -892,7 +894,7 @@ namespace Bloom::Targets::Microchip::Avr::Avr8Bit
Logger::info("Current SPIEN fuse bit value confirmed");
if (static_cast<bool>(dwenFuseByte & dwenFuseBitsDescriptor->bitMask) == !setFuse) {
if (static_cast<bool>(dwenFuseByte & dwenFuseBitsDescriptor->bitMask) == !enable) {
/*
* The DWEN fuse appears to already be set to the desired value. This may be a result of incorrect data
* in the TDF, but we're not taking any chances.
@@ -922,7 +924,7 @@ namespace Bloom::Targets::Microchip::Avr::Avr8Bit
const auto newFuse = Fuse(
dwenFuseBitsDescriptor->fuseType,
(setFuse) ? static_cast<unsigned char>(dwenFuseByte & ~(dwenFuseBitsDescriptor->bitMask))
(enable) ? static_cast<unsigned char>(dwenFuseByte & ~(dwenFuseBitsDescriptor->bitMask))
: static_cast<unsigned char>(dwenFuseByte | dwenFuseBitsDescriptor->bitMask)
);

View File

@@ -176,10 +176,10 @@ namespace Bloom::Targets::Microchip::Avr::Avr8Bit
/**
* Updates the debugWire enable (DWEN) fuse bit on the AVR target.
*
* @param setFuse
* True to set the fuse, false to clear it.
* @param enable
* True to enable the fuse, false to disable it.
*/
void writeDwenFuseBit(bool setFuse);
void updateDwenFuseBit(bool enable);
/**
* Resolves the program memory section from a program memory address.

View File

@@ -28,10 +28,15 @@ namespace Bloom::Targets::Microchip::Avr
unsigned char byteTwo = 0x00;
TargetSignature() = default;
TargetSignature(unsigned char byteZero, unsigned char byteOne, unsigned char byteTwo) :
byteZero(byteZero), byteOne(byteOne), byteTwo(byteTwo) {};
TargetSignature(unsigned char byteZero, unsigned char byteOne, unsigned char byteTwo)
: byteZero(byteZero)
, byteOne(byteOne)
, byteTwo(byteTwo)
{};
explicit TargetSignature(const std::string& hex) {
auto signature = static_cast<std::uint32_t>(std::stoul(hex, nullptr, 16));
const auto signature = static_cast<std::uint32_t>(std::stoul(hex, nullptr, 16));
this->byteZero = static_cast<unsigned char>(signature >> 16);
this->byteOne = static_cast<unsigned char>(signature >> 8);
this->byteTwo = static_cast<unsigned char>(signature);
@@ -48,9 +53,10 @@ namespace Bloom::Targets::Microchip::Avr
}
bool operator == (const TargetSignature& signature) const {
return signature.byteZero == this->byteZero
&& signature.byteOne == this->byteOne
&& signature.byteTwo == this->byteTwo;
return
signature.byteZero == this->byteZero
&& signature.byteOne == this->byteOne
&& signature.byteTwo == this->byteTwo;
}
bool operator != (const TargetSignature& signature) const {