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 * file (which it would, if the user specified the exact target name in their project config - see
* Avr8::getId() and TargetControllerComponent::getSupportedTargets() for more). * Avr8::getId() and TargetControllerComponent::getSupportedTargets() for more).
*/ */
auto targetSignature = this->avr8DebugInterface->getDeviceId(); const auto targetSignature = this->avr8DebugInterface->getDeviceId();
auto tdSignature = this->targetDescriptionFile->getTargetSignature(); const auto tdSignature = this->targetDescriptionFile->getTargetSignature();
if (targetSignature != tdSignature) { if (targetSignature != tdSignature) {
throw Exception( throw Exception(
@@ -149,7 +149,7 @@ namespace Bloom::Targets::Microchip::Avr::Avr8Bit
this->avr8DebugInterface->init(); this->avr8DebugInterface->init();
if (this->targetDescriptionFile.has_value()) { if (this->targetParameters.has_value()) {
this->avr8DebugInterface->setTargetParameters(this->targetParameters.value()); this->avr8DebugInterface->setTargetParameters(this->targetParameters.value());
} }
@@ -157,6 +157,8 @@ namespace Bloom::Targets::Microchip::Avr::Avr8Bit
this->avr8DebugInterface->activate(); this->avr8DebugInterface->activate();
} catch (const Exceptions::DebugWirePhysicalInterfaceError& debugWireException) { } catch (const Exceptions::DebugWirePhysicalInterfaceError& debugWireException) {
// We failed to activate the debugWire physical interface. DWEN fuse bit may need updating.
if (!this->targetConfig->manageDwenFuseBit) { if (!this->targetConfig->manageDwenFuseBit) {
throw TargetOperationFailure( throw TargetOperationFailure(
"Failed to activate debugWire physical interface - check target connection and DWEN fuse " "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 " "Failed to activate the debugWire physical interface - attempting to access target via "
"the ISP interface, for DWEN fuse bit inspection." "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 the debug tool provides a TargetPowerManagementInterface, attempt to cycle the target power
if ( if (
@@ -763,7 +765,7 @@ namespace Bloom::Targets::Microchip::Avr::Avr8Bit
return this->id.value(); return this->id.value();
} }
void Avr8::writeDwenFuseBit(bool setFuse) { void Avr8::updateDwenFuseBit(bool enable) {
if (this->avrIspInterface == nullptr) { if (this->avrIspInterface == nullptr) {
throw Exception( throw Exception(
"Debug tool or driver does not provide access to an ISP interface - please confirm that the " "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"); 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 * 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. * in the TDF, but we're not taking any chances.
@@ -922,7 +924,7 @@ namespace Bloom::Targets::Microchip::Avr::Avr8Bit
const auto newFuse = Fuse( const auto newFuse = Fuse(
dwenFuseBitsDescriptor->fuseType, 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) : 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. * Updates the debugWire enable (DWEN) fuse bit on the AVR target.
* *
* @param setFuse * @param enable
* True to set the fuse, false to clear it. * 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. * 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; unsigned char byteTwo = 0x00;
TargetSignature() = default; TargetSignature() = default;
TargetSignature(unsigned char byteZero, unsigned char byteOne, unsigned char byteTwo) : TargetSignature(unsigned char byteZero, unsigned char byteOne, unsigned char byteTwo)
byteZero(byteZero), byteOne(byteOne), byteTwo(byteTwo) {}; : byteZero(byteZero)
, byteOne(byteOne)
, byteTwo(byteTwo)
{};
explicit TargetSignature(const std::string& hex) { 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->byteZero = static_cast<unsigned char>(signature >> 16);
this->byteOne = static_cast<unsigned char>(signature >> 8); this->byteOne = static_cast<unsigned char>(signature >> 8);
this->byteTwo = static_cast<unsigned char>(signature); this->byteTwo = static_cast<unsigned char>(signature);
@@ -48,7 +53,8 @@ namespace Bloom::Targets::Microchip::Avr
} }
bool operator == (const TargetSignature& signature) const { bool operator == (const TargetSignature& signature) const {
return signature.byteZero == this->byteZero return
signature.byteZero == this->byteZero
&& signature.byteOne == this->byteOne && signature.byteOne == this->byteOne
&& signature.byteTwo == this->byteTwo; && signature.byteTwo == this->byteTwo;
} }