Check if Microchip hybrid devices (Snap and PICkit 4) are not in AVR mode and report back to the user.
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
#include "MplabPickit4.hpp"
|
||||
|
||||
#include "src/TargetController/Exceptions/DeviceNotFound.hpp"
|
||||
#include "src/Services/PathService.hpp"
|
||||
|
||||
namespace Bloom::DebugToolDrivers
|
||||
{
|
||||
MplabPickit4::MplabPickit4()
|
||||
@@ -9,4 +12,31 @@ namespace Bloom::DebugToolDrivers
|
||||
MplabPickit4::CMSIS_HID_INTERFACE_NUMBER
|
||||
)
|
||||
{}
|
||||
|
||||
void MplabPickit4::init() {
|
||||
using Exceptions::DeviceNotFound;
|
||||
|
||||
try {
|
||||
EdbgDevice::init();
|
||||
|
||||
} catch (const DeviceNotFound& exception) {
|
||||
/*
|
||||
* The MPLAB PICkit 4 could be connected but not in AVR mode - if this is the case, inform the user and
|
||||
* direct them to the AVR mode article.
|
||||
*/
|
||||
const auto nonEdbgDevices = this->findMatchingDevices(
|
||||
MplabPickit4::NON_EDBG_USB_VENDOR_ID,
|
||||
MplabPickit4::NON_EDBG_USB_PRODUCT_ID
|
||||
);
|
||||
|
||||
if (!nonEdbgDevices.empty()) {
|
||||
throw DeviceNotFound(
|
||||
"The connected MPLAB PICkit 4 device is not in \"AVR mode\". Please follow the instructions at "
|
||||
+ Services::PathService::homeDomainName() + "/docs/avr-mode"
|
||||
);
|
||||
}
|
||||
|
||||
throw exception;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,10 +26,15 @@ namespace Bloom::DebugToolDrivers
|
||||
static const inline std::uint16_t USB_PRODUCT_ID = 0x2177;
|
||||
static const inline std::uint8_t CMSIS_HID_INTERFACE_NUMBER = 0;
|
||||
|
||||
static const inline std::uint16_t NON_EDBG_USB_VENDOR_ID = 0x04d8;
|
||||
static const inline std::uint16_t NON_EDBG_USB_PRODUCT_ID = 0x9012;
|
||||
|
||||
MplabPickit4();
|
||||
|
||||
std::string getName() override {
|
||||
return "MPLAB PICkit 4";
|
||||
}
|
||||
|
||||
void init() override;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
#include "MplabSnap.hpp"
|
||||
|
||||
#include "src/TargetController/Exceptions/DeviceNotFound.hpp"
|
||||
#include "src/Services/PathService.hpp"
|
||||
|
||||
namespace Bloom::DebugToolDrivers
|
||||
{
|
||||
MplabSnap::MplabSnap()
|
||||
@@ -9,4 +12,39 @@ namespace Bloom::DebugToolDrivers
|
||||
MplabSnap::CMSIS_HID_INTERFACE_NUMBER
|
||||
)
|
||||
{}
|
||||
|
||||
void MplabSnap::init() {
|
||||
using Exceptions::DeviceNotFound;
|
||||
|
||||
try {
|
||||
EdbgDevice::init();
|
||||
|
||||
} catch (const DeviceNotFound& exception) {
|
||||
/*
|
||||
* The MPLAB Snap could be connected but not in AVR mode - if this is the case, inform the user and direct
|
||||
* them to the AVR mode article.
|
||||
*/
|
||||
auto nonEdbgDevices = this->findMatchingDevices(
|
||||
MplabSnap::NON_EDBG_USB_VENDOR_ID,
|
||||
MplabSnap::NON_EDBG_USB_PRODUCT_ID
|
||||
);
|
||||
|
||||
if (nonEdbgDevices.empty()) {
|
||||
// The MPLAB Snap sometimes uses another product ID when not in AVR mode.
|
||||
nonEdbgDevices = this->findMatchingDevices(
|
||||
MplabSnap::NON_EDBG_USB_VENDOR_ID,
|
||||
MplabSnap::NON_EDBG_USB_PRODUCT_ID_ALTERNATIVE
|
||||
);
|
||||
}
|
||||
|
||||
if (!nonEdbgDevices.empty()) {
|
||||
throw DeviceNotFound(
|
||||
"The connected MPLAB Snap device is not in \"AVR mode\". Please follow the instructions at "
|
||||
+ Services::PathService::homeDomainName() + "/docs/avr-mode"
|
||||
);
|
||||
}
|
||||
|
||||
throw exception;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,10 +28,16 @@ namespace Bloom::DebugToolDrivers
|
||||
static const inline std::uint16_t USB_PRODUCT_ID = 0x2180;
|
||||
static const inline std::uint8_t CMSIS_HID_INTERFACE_NUMBER = 0;
|
||||
|
||||
static const inline std::uint16_t NON_EDBG_USB_VENDOR_ID = 0x04d8;
|
||||
static const inline std::uint16_t NON_EDBG_USB_PRODUCT_ID = 0x9018;
|
||||
static const inline std::uint16_t NON_EDBG_USB_PRODUCT_ID_ALTERNATIVE = 0x9017;
|
||||
|
||||
MplabSnap();
|
||||
|
||||
std::string getName() override {
|
||||
return "MPLAB Snap";
|
||||
}
|
||||
|
||||
void init() override;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include "src/Logger/Logger.hpp"
|
||||
#include "src/TargetController/Exceptions/DeviceInitializationFailure.hpp"
|
||||
#include "src/TargetController/Exceptions/DeviceNotFound.hpp"
|
||||
|
||||
namespace Bloom::Usb
|
||||
{
|
||||
@@ -25,7 +26,7 @@ namespace Bloom::Usb
|
||||
auto devices = this->findMatchingDevices(this->vendorId, this->productId);
|
||||
|
||||
if (devices.empty()) {
|
||||
throw DeviceInitializationFailure(
|
||||
throw DeviceNotFound(
|
||||
"Failed to find USB device with matching vendor and product ID. Please examine the debug tool's USB "
|
||||
"connection, as well as the selected environment's debug tool configuration, in bloom.yaml"
|
||||
);
|
||||
|
||||
18
src/TargetController/Exceptions/DeviceNotFound.hpp
Normal file
18
src/TargetController/Exceptions/DeviceNotFound.hpp
Normal file
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include "src/Exceptions/Exception.hpp"
|
||||
|
||||
namespace Bloom::Exceptions
|
||||
{
|
||||
class DeviceNotFound: public Exception
|
||||
{
|
||||
public:
|
||||
explicit DeviceNotFound(const std::string& message): Exception(message) {
|
||||
this->message = message;
|
||||
}
|
||||
|
||||
explicit DeviceNotFound(const char* message): Exception(message) {
|
||||
this->message = std::string(message);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -9,9 +9,6 @@
|
||||
#include "src/Services/ProcessService.hpp"
|
||||
#include "src/Logger/Logger.hpp"
|
||||
|
||||
#include "src/TargetController/Exceptions/DeviceFailure.hpp"
|
||||
#include "src/TargetController/Exceptions/TargetOperationFailure.hpp"
|
||||
#include "src/Exceptions/TargetControllerStartupFailure.hpp"
|
||||
#include "src/Exceptions/InvalidConfig.hpp"
|
||||
|
||||
namespace Bloom::TargetController
|
||||
@@ -97,14 +94,6 @@ namespace Bloom::TargetController
|
||||
}
|
||||
}
|
||||
|
||||
} catch (const TargetControllerStartupFailure& exception) {
|
||||
Logger::error("TargetController failed to start up. See below for errors:");
|
||||
Logger::error(exception.getMessage());
|
||||
|
||||
} catch (const Exception& exception) {
|
||||
Logger::error("The TargetController encountered a fatal error. See below for errors:");
|
||||
Logger::error(exception.getMessage());
|
||||
|
||||
} catch (const std::exception& exception) {
|
||||
Logger::error("The TargetController encountered a fatal error. See below for errors:");
|
||||
Logger::error(std::string(exception.what()));
|
||||
|
||||
Reference in New Issue
Block a user