Deactivated ISP interface in exception handler

This commit is contained in:
Nav
2022-03-15 11:26:16 +00:00
parent cdd35c46c1
commit df23701fe7

View File

@@ -791,6 +791,7 @@ namespace Bloom::Targets::Microchip::Avr::Avr8Bit
"see the Bloom license at " + Paths::homeDomainName() + "/license"
);
try {
Logger::info("Reading target signature via ISP");
const auto ispDeviceId = this->avrIspInterface->getDeviceId();
@@ -809,15 +810,15 @@ namespace Bloom::Targets::Microchip::Avr::Avr8Bit
: this->avrIspInterface->readFuse(spienFuseBitsDescriptor->fuseType).value;
/*
* Keep in mind that, for AVR fuses and lock bits, a set bit (1) means the fuse/lock is cleared, and a cleared
* bit (0), means the fuse/lock is set.
* Keep in mind that, for AVR fuses and lock bits, a set bit (0b1) means the fuse/lock is cleared, and a
* cleared bit (0b0), means the fuse/lock is set.
*/
if ((spienFuseByte & spienFuseBitsDescriptor->bitMask) != 0) {
/*
* If we get here, something is very wrong. The SPIEN (SPI enable) fuse bit appears to be cleared, but this
* is not possible because we're connected to the target via the SPI (the ISP interface uses a physical SPI
* between the debug tool and the target).
* If we get here, something is very wrong. The SPIEN (SPI enable) fuse bit appears to be cleared, but
* this is not possible because we're connected to the target via the SPI (the ISP interface uses a
* physical SPI between the debug tool and the target).
*
* This could be (and likely is) caused by incorrect data for the SPIEN fuse bit, in the TDF (which was
* used to construct the spienFuseBitsDescriptor). And if the data for the SPIEN fuse bit is incorrect,
@@ -835,24 +836,27 @@ namespace Bloom::Targets::Microchip::Avr::Avr8Bit
if (static_cast<bool>(dwenFuseByte & dwenFuseBitsDescriptor->bitMask) == !setFuse) {
/*
* 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.
* 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.
*
* We don't throw an exception here, because we don't know if this is due to an error, or if the fuse bit
* is simply already set to the desired value.
* We don't throw an exception here, because we don't know if this is due to an error, or if the fuse
* bit is simply already set to the desired value.
*/
Logger::debug("DWEN fuse bit already set to desired value - aborting update operation");
this->avrIspInterface->deactivate();
return;
}
const auto lockBitByte = this->avrIspInterface->readLockBitByte();
if (lockBitByte != 0xFF) {
/*
* There is at least one lock bit that is set. Setting the DWEN fuse bit with the lock bits set will
* There is at least one lock bit that is set. Setting the DWEN fuse bit with the lock bits set may
* brick the device. We must abort.
*/
throw Exception(
"At least one lock bit has been set - updating the DWEN fuse bit could potentially brick the "
"target."
"At least one lock bit has been set - updating the DWEN fuse bit could potentially brick "
"the target."
);
}
@@ -868,11 +872,16 @@ namespace Bloom::Targets::Microchip::Avr::Avr8Bit
this->avrIspInterface->programFuse(newFuse);
if (this->avrIspInterface->readFuse(dwenFuseBitsDescriptor->fuseType).value != newFuse.value) {
Logger::error("Failed to program fuse bit - post-program value check failed");
throw Exception("Failed to program fuse bit - post-program value check failed");
}
Logger::info("DWEN fuse bit successfully updated");
this->avrIspInterface->deactivate();
} catch (const Exception& exception) {
this->avrIspInterface->deactivate();
throw exception;
}
}
}