Deactivated ISP interface in exception handler
This commit is contained in:
@@ -791,6 +791,7 @@ namespace Bloom::Targets::Microchip::Avr::Avr8Bit
|
|||||||
"see the Bloom license at " + Paths::homeDomainName() + "/license"
|
"see the Bloom license at " + Paths::homeDomainName() + "/license"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
try {
|
||||||
Logger::info("Reading target signature via ISP");
|
Logger::info("Reading target signature via ISP");
|
||||||
const auto ispDeviceId = this->avrIspInterface->getDeviceId();
|
const auto ispDeviceId = this->avrIspInterface->getDeviceId();
|
||||||
|
|
||||||
@@ -809,15 +810,15 @@ namespace Bloom::Targets::Microchip::Avr::Avr8Bit
|
|||||||
: this->avrIspInterface->readFuse(spienFuseBitsDescriptor->fuseType).value;
|
: 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
|
* Keep in mind that, for AVR fuses and lock bits, a set bit (0b1) means the fuse/lock is cleared, and a
|
||||||
* bit (0), means the fuse/lock is set.
|
* cleared bit (0b0), means the fuse/lock is set.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ((spienFuseByte & spienFuseBitsDescriptor->bitMask) != 0) {
|
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
|
* If we get here, something is very wrong. The SPIEN (SPI enable) fuse bit appears to be cleared, but
|
||||||
* is not possible because we're connected to the target via the SPI (the ISP interface uses a physical SPI
|
* this is not possible because we're connected to the target via the SPI (the ISP interface uses a
|
||||||
* between the debug tool and the target).
|
* 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
|
* 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,
|
* 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) {
|
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 DWEN fuse appears to already be set to the desired value. This may be a result of incorrect data
|
||||||
* the TDF, but we're not taking any chances.
|
* 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
|
* We don't throw an exception here, because we don't know if this is due to an error, or if the fuse
|
||||||
* is simply already set to the desired value.
|
* 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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto lockBitByte = this->avrIspInterface->readLockBitByte();
|
const auto lockBitByte = this->avrIspInterface->readLockBitByte();
|
||||||
if (lockBitByte != 0xFF) {
|
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.
|
* brick the device. We must abort.
|
||||||
*/
|
*/
|
||||||
throw Exception(
|
throw Exception(
|
||||||
"At least one lock bit has been set - updating the DWEN fuse bit could potentially brick the "
|
"At least one lock bit has been set - updating the DWEN fuse bit could potentially brick "
|
||||||
"target."
|
"the target."
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -868,11 +872,16 @@ namespace Bloom::Targets::Microchip::Avr::Avr8Bit
|
|||||||
this->avrIspInterface->programFuse(newFuse);
|
this->avrIspInterface->programFuse(newFuse);
|
||||||
|
|
||||||
if (this->avrIspInterface->readFuse(dwenFuseBitsDescriptor->fuseType).value != newFuse.value) {
|
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");
|
Logger::info("DWEN fuse bit successfully updated");
|
||||||
|
|
||||||
this->avrIspInterface->deactivate();
|
this->avrIspInterface->deactivate();
|
||||||
|
|
||||||
|
} catch (const Exception& exception) {
|
||||||
|
this->avrIspInterface->deactivate();
|
||||||
|
throw exception;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user