diff --git a/src/Targets/Microchip/AVR/AVR8/Avr8.cpp b/src/Targets/Microchip/AVR/AVR8/Avr8.cpp index 458ce8b5..7cc10630 100644 --- a/src/Targets/Microchip/AVR/AVR8/Avr8.cpp +++ b/src/Targets/Microchip/AVR/AVR8/Avr8.cpp @@ -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(dwenFuseByte & dwenFuseBitsDescriptor->bitMask) == !setFuse) { + if (static_cast(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(dwenFuseByte & ~(dwenFuseBitsDescriptor->bitMask)) + (enable) ? static_cast(dwenFuseByte & ~(dwenFuseBitsDescriptor->bitMask)) : static_cast(dwenFuseByte | dwenFuseBitsDescriptor->bitMask) ); diff --git a/src/Targets/Microchip/AVR/AVR8/Avr8.hpp b/src/Targets/Microchip/AVR/AVR8/Avr8.hpp index 4ed0543a..8205d7ff 100644 --- a/src/Targets/Microchip/AVR/AVR8/Avr8.hpp +++ b/src/Targets/Microchip/AVR/AVR8/Avr8.hpp @@ -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. diff --git a/src/Targets/Microchip/AVR/TargetSignature.hpp b/src/Targets/Microchip/AVR/TargetSignature.hpp index 7a245d40..18a916d9 100644 --- a/src/Targets/Microchip/AVR/TargetSignature.hpp +++ b/src/Targets/Microchip/AVR/TargetSignature.hpp @@ -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::stoul(hex, nullptr, 16)); + const auto signature = static_cast(std::stoul(hex, nullptr, 16)); + this->byteZero = static_cast(signature >> 16); this->byteOne = static_cast(signature >> 8); this->byteTwo = static_cast(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 {