Tidying low-level debug tool driver code:

- Use automatic objects for libusb/hidapi resources, where possible (to reduce manual resource management)
- Removed unused/redundant code
- Tidied HidInterface class
- Tidied debug tool initialisation code
- Other bits of tidying
This commit is contained in:
Nav
2022-10-01 16:50:57 +01:00
parent ef4eb4f768
commit a5b0097036
36 changed files with 448 additions and 727 deletions

View File

@@ -8,22 +8,23 @@ namespace Bloom::DebugToolDrivers
using namespace Protocols::CmsisDap::Edbg::Avr;
using namespace Bloom::Exceptions;
using Protocols::CmsisDap::Edbg::EdbgInterface;
AtmelIce::AtmelIce()
: UsbDevice(AtmelIce::USB_VENDOR_ID, AtmelIce::USB_PRODUCT_ID)
{}
void AtmelIce::init() {
UsbDevice::init();
// TODO: Move away from hard-coding the CMSIS-DAP/EDBG interface number
auto& usbHidInterface = this->getEdbgInterface().getUsbHidInterface();
usbHidInterface.setNumber(0);
usbHidInterface.setLibUsbDevice(this->libUsbDevice);
usbHidInterface.setLibUsbDeviceHandle(this->libUsbDeviceHandle);
usbHidInterface.setVendorId(this->vendorId);
usbHidInterface.setProductId(this->productId);
auto usbHidInterface = Usb::HidInterface(0, this->vendorId, this->productId);
if (!usbHidInterface.isInitialised()) {
usbHidInterface.detachKernelDriver();
this->setConfiguration(0);
usbHidInterface.init();
}
this->detachKernelDriverFromInterface(usbHidInterface.interfaceNumber);
this->setConfiguration(0);
usbHidInterface.init();
this->edbgInterface = std::make_unique<EdbgInterface>(std::move(usbHidInterface));
/*
* The Atmel-ICE EDBG/CMSIS-DAP interface doesn't operate properly when sending commands too quickly.
@@ -31,15 +32,15 @@ namespace Bloom::DebugToolDrivers
* Because of this, we have to enforce a minimum time gap between commands. See comment
* in CmsisDapInterface class declaration for more info.
*/
this->getEdbgInterface().setMinimumCommandTimeGap(std::chrono::milliseconds(35));
this->edbgInterface->setMinimumCommandTimeGap(std::chrono::milliseconds(35));
// We don't need to claim the CMSISDAP interface here as the HIDAPI will have already done so.
if (!this->sessionStarted) {
this->startSession();
}
this->edbgAvr8Interface = std::make_unique<EdbgAvr8Interface>(this->edbgInterface);
this->edbgAvrIspInterface = std::make_unique<EdbgAvrIspInterface>(this->edbgInterface);
this->edbgAvr8Interface = std::make_unique<EdbgAvr8Interface>(this->edbgInterface.get());
this->edbgAvrIspInterface = std::make_unique<EdbgAvrIspInterface>(this->edbgInterface.get());
this->setInitialised(true);
}
@@ -49,7 +50,7 @@ namespace Bloom::DebugToolDrivers
this->endSession();
}
this->getEdbgInterface().getUsbHidInterface().close();
this->edbgInterface->getUsbHidInterface().close();
UsbDevice::close();
}
@@ -57,7 +58,7 @@ namespace Bloom::DebugToolDrivers
using namespace CommandFrames::Discovery;
using ResponseFrames::Discovery::ResponseId;
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
auto response = this->edbgInterface->sendAvrCommandFrameAndWaitForResponseFrame(
Query(QueryContext::SERIAL_NUMBER)
);
@@ -67,7 +68,7 @@ namespace Bloom::DebugToolDrivers
);
}
auto data = response.getPayloadData();
const auto data = response.getPayloadData();
return std::string(data.begin(), data.end());
}
@@ -75,7 +76,7 @@ namespace Bloom::DebugToolDrivers
using namespace CommandFrames::HouseKeeping;
using ResponseFrames::HouseKeeping::ResponseId;
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
auto response = this->edbgInterface->sendAvrCommandFrameAndWaitForResponseFrame(
StartSession()
);
@@ -91,7 +92,7 @@ namespace Bloom::DebugToolDrivers
using namespace CommandFrames::HouseKeeping;
using ResponseFrames::HouseKeeping::ResponseId;
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
auto response = this->edbgInterface->sendAvrCommandFrameAndWaitForResponseFrame(
EndSession()
);

View File

@@ -45,16 +45,12 @@ namespace Bloom::DebugToolDrivers
static const std::uint16_t USB_VENDOR_ID = 1003;
static const std::uint16_t USB_PRODUCT_ID = 8513;
AtmelIce(): UsbDevice(AtmelIce::USB_VENDOR_ID, AtmelIce::USB_PRODUCT_ID) {}
AtmelIce();
void init() override;
void close() override;
Protocols::CmsisDap::Edbg::EdbgInterface& getEdbgInterface() {
return this->edbgInterface;
}
TargetInterfaces::Microchip::Avr::Avr8::Avr8DebugInterface* getAvr8DebugInterface() override {
return this->edbgAvr8Interface.get();
}
@@ -65,7 +61,7 @@ namespace Bloom::DebugToolDrivers
std::string getName() override {
return "Atmel-ICE";
};
}
/**
* Retrieves the device serial number via the Discovery Protocol.
@@ -93,7 +89,7 @@ namespace Bloom::DebugToolDrivers
* Any non-EDBG CMSIS-DAP commands for the Atmel-ICE can be sent through the EdbgInterface (as the
* EdbgInterface extends the CmsisDapInterface).
*/
Protocols::CmsisDap::Edbg::EdbgInterface edbgInterface = Protocols::CmsisDap::Edbg::EdbgInterface();
std::unique_ptr<Protocols::CmsisDap::Edbg::EdbgInterface> edbgInterface = nullptr;
/**
* The Atmel-ICE employs the EDBG AVR8 Generic protocol, for debugging AVR8 targets. This protocol is

View File

@@ -8,36 +8,36 @@ namespace Bloom::DebugToolDrivers
using namespace Protocols::CmsisDap::Edbg::Avr;
using namespace Bloom::Exceptions;
using Protocols::CmsisDap::Edbg::EdbgInterface;
using Protocols::CmsisDap::Edbg::EdbgTargetPowerManagementInterface;
CuriosityNano::CuriosityNano()
: UsbDevice(CuriosityNano::USB_VENDOR_ID, CuriosityNano::USB_PRODUCT_ID)
{}
void CuriosityNano::init() {
UsbDevice::init();
// TODO: Move away from hard-coding the CMSIS-DAP/EDBG interface number
auto& usbHidInterface = this->getEdbgInterface().getUsbHidInterface();
usbHidInterface.setNumber(0);
usbHidInterface.setLibUsbDevice(this->libUsbDevice);
usbHidInterface.setLibUsbDeviceHandle(this->libUsbDeviceHandle);
usbHidInterface.setVendorId(this->vendorId);
usbHidInterface.setProductId(this->productId);
auto usbHidInterface = Usb::HidInterface(0, this->vendorId, this->productId);
if (!usbHidInterface.isInitialised()) {
usbHidInterface.detachKernelDriver();
usbHidInterface.init();
}
this->detachKernelDriverFromInterface(usbHidInterface.interfaceNumber);
usbHidInterface.init();
this->getEdbgInterface().setMinimumCommandTimeGap(std::chrono::milliseconds(35));
this->edbgInterface = std::make_unique<EdbgInterface>(std::move(usbHidInterface));
this->edbgInterface->setMinimumCommandTimeGap(std::chrono::milliseconds(35));
if (!this->sessionStarted) {
this->startSession();
}
this->targetPowerManagementInterface = std::make_unique<EdbgTargetPowerManagementInterface>(
this->edbgInterface
this->edbgInterface.get()
);
this->edbgAvr8Interface = std::make_unique<EdbgAvr8Interface>(this->edbgInterface);
this->edbgAvrIspInterface = std::make_unique<EdbgAvrIspInterface>(this->edbgInterface);
this->edbgAvr8Interface = std::make_unique<EdbgAvr8Interface>(this->edbgInterface.get());
this->edbgAvrIspInterface = std::make_unique<EdbgAvrIspInterface>(this->edbgInterface.get());
this->setInitialised(true);
}
@@ -47,7 +47,7 @@ namespace Bloom::DebugToolDrivers
this->endSession();
}
this->getEdbgInterface().getUsbHidInterface().close();
this->edbgInterface->getUsbHidInterface().close();
UsbDevice::close();
}
@@ -55,7 +55,7 @@ namespace Bloom::DebugToolDrivers
using namespace CommandFrames::Discovery;
using ResponseFrames::Discovery::ResponseId;
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
auto response = this->edbgInterface->sendAvrCommandFrameAndWaitForResponseFrame(
Query(QueryContext::SERIAL_NUMBER)
);
@@ -65,7 +65,7 @@ namespace Bloom::DebugToolDrivers
);
}
auto data = response.getPayloadData();
const auto data = response.getPayloadData();
return std::string(data.begin(), data.end());
}
@@ -73,7 +73,7 @@ namespace Bloom::DebugToolDrivers
using namespace CommandFrames::HouseKeeping;
using ResponseFrames::HouseKeeping::ResponseId;
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
auto response = this->edbgInterface->sendAvrCommandFrameAndWaitForResponseFrame(
StartSession()
);
@@ -89,7 +89,7 @@ namespace Bloom::DebugToolDrivers
using namespace CommandFrames::HouseKeeping;
using ResponseFrames::HouseKeeping::ResponseId;
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
auto response = this->edbgInterface->sendAvrCommandFrameAndWaitForResponseFrame(
EndSession()
);

View File

@@ -35,16 +35,12 @@ namespace Bloom::DebugToolDrivers
static const std::uint16_t USB_VENDOR_ID = 1003;
static const std::uint16_t USB_PRODUCT_ID = 8565;
CuriosityNano(): UsbDevice(CuriosityNano::USB_VENDOR_ID, CuriosityNano::USB_PRODUCT_ID) {}
CuriosityNano();
void init() override;
void close() override;
Protocols::CmsisDap::Edbg::EdbgInterface& getEdbgInterface() {
return this->edbgInterface;
}
DebugToolDrivers::TargetInterfaces::TargetPowerManagementInterface* getTargetPowerManagementInterface() override {
return this->targetPowerManagementInterface.get();
}
@@ -59,7 +55,7 @@ namespace Bloom::DebugToolDrivers
std::string getName() override {
return "Curiosity Nano";
};
}
/**
* Retrieves the device serial number via the Discovery Protocol.
@@ -79,7 +75,7 @@ namespace Bloom::DebugToolDrivers
void endSession();
private:
Protocols::CmsisDap::Edbg::EdbgInterface edbgInterface = Protocols::CmsisDap::Edbg::EdbgInterface();
std::unique_ptr<Protocols::CmsisDap::Edbg::EdbgInterface> edbgInterface = nullptr;
std::unique_ptr<Protocols::CmsisDap::Edbg::Avr::EdbgAvr8Interface> edbgAvr8Interface = nullptr;
std::unique_ptr<Protocols::CmsisDap::Edbg::Avr::EdbgAvrIspInterface> edbgAvrIspInterface = nullptr;
std::unique_ptr<

View File

@@ -8,32 +8,33 @@ namespace Bloom::DebugToolDrivers
using namespace Protocols::CmsisDap::Edbg::Avr;
using namespace Bloom::Exceptions;
using Protocols::CmsisDap::Edbg::EdbgInterface;
JtagIce3::JtagIce3()
: UsbDevice(JtagIce3::USB_VENDOR_ID, JtagIce3::USB_PRODUCT_ID)
{}
void JtagIce3::init() {
UsbDevice::init();
// TODO: Move away from hard-coding the CMSIS-DAP/EDBG interface number
auto& usbHidInterface = this->getEdbgInterface().getUsbHidInterface();
usbHidInterface.setNumber(0);
usbHidInterface.setLibUsbDevice(this->libUsbDevice);
usbHidInterface.setLibUsbDeviceHandle(this->libUsbDeviceHandle);
usbHidInterface.setVendorId(this->vendorId);
usbHidInterface.setProductId(this->productId);
auto usbHidInterface = Usb::HidInterface(0, this->vendorId, this->productId);
if (!usbHidInterface.isInitialised()) {
usbHidInterface.detachKernelDriver();
this->setConfiguration(0);
usbHidInterface.init();
}
this->detachKernelDriverFromInterface(usbHidInterface.interfaceNumber);
this->setConfiguration(0);
usbHidInterface.init();
this->getEdbgInterface().setMinimumCommandTimeGap(std::chrono::milliseconds(35));
this->edbgInterface = std::make_unique<EdbgInterface>(std::move(usbHidInterface));
this->edbgInterface->setMinimumCommandTimeGap(std::chrono::milliseconds(35));
// We don't need to claim the CMSISDAP interface here as the HIDAPI will have already done so.
if (!this->sessionStarted) {
this->startSession();
}
this->edbgAvr8Interface = std::make_unique<EdbgAvr8Interface>(this->edbgInterface);
this->edbgAvrIspInterface = std::make_unique<EdbgAvrIspInterface>(this->edbgInterface);
this->edbgAvr8Interface = std::make_unique<EdbgAvr8Interface>(this->edbgInterface.get());
this->edbgAvrIspInterface = std::make_unique<EdbgAvrIspInterface>(this->edbgInterface.get());
this->setInitialised(true);
}
@@ -43,7 +44,7 @@ namespace Bloom::DebugToolDrivers
this->endSession();
}
this->getEdbgInterface().getUsbHidInterface().close();
this->edbgInterface->getUsbHidInterface().close();
UsbDevice::close();
}
@@ -51,7 +52,7 @@ namespace Bloom::DebugToolDrivers
using namespace CommandFrames::Discovery;
using ResponseFrames::Discovery::ResponseId;
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
auto response = this->edbgInterface->sendAvrCommandFrameAndWaitForResponseFrame(
Query(QueryContext::SERIAL_NUMBER)
);
@@ -61,7 +62,7 @@ namespace Bloom::DebugToolDrivers
);
}
auto data = response.getPayloadData();
const auto data = response.getPayloadData();
return std::string(data.begin(), data.end());
}
@@ -69,7 +70,7 @@ namespace Bloom::DebugToolDrivers
using namespace CommandFrames::HouseKeeping;
using ResponseFrames::HouseKeeping::ResponseId;
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
auto response = this->edbgInterface->sendAvrCommandFrameAndWaitForResponseFrame(
StartSession()
);
@@ -85,7 +86,7 @@ namespace Bloom::DebugToolDrivers
using namespace CommandFrames::HouseKeeping;
using ResponseFrames::HouseKeeping::ResponseId;
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
auto response = this->edbgInterface->sendAvrCommandFrameAndWaitForResponseFrame(
EndSession()
);

View File

@@ -21,16 +21,12 @@ namespace Bloom::DebugToolDrivers
static const std::uint16_t USB_VENDOR_ID = 1003;
static const std::uint16_t USB_PRODUCT_ID = 8512;
JtagIce3(): UsbDevice(JtagIce3::USB_VENDOR_ID, JtagIce3::USB_PRODUCT_ID) {}
JtagIce3();
void init() override;
void close() override;
Protocols::CmsisDap::Edbg::EdbgInterface& getEdbgInterface() {
return this->edbgInterface;
}
TargetInterfaces::Microchip::Avr::Avr8::Avr8DebugInterface* getAvr8DebugInterface() override {
return this->edbgAvr8Interface.get();
}
@@ -41,7 +37,7 @@ namespace Bloom::DebugToolDrivers
std::string getName() override {
return "JTAGICE3";
};
}
/**
* Retrieves the device serial number via the Discovery Protocol.
@@ -61,7 +57,7 @@ namespace Bloom::DebugToolDrivers
void endSession();
private:
Protocols::CmsisDap::Edbg::EdbgInterface edbgInterface = Protocols::CmsisDap::Edbg::EdbgInterface();
std::unique_ptr<Protocols::CmsisDap::Edbg::EdbgInterface> edbgInterface = nullptr;
std::unique_ptr<Protocols::CmsisDap::Edbg::Avr::EdbgAvr8Interface> edbgAvr8Interface = nullptr;
std::unique_ptr<Protocols::CmsisDap::Edbg::Avr::EdbgAvrIspInterface> edbgAvrIspInterface = nullptr;

View File

@@ -8,30 +8,32 @@ namespace Bloom::DebugToolDrivers
using namespace Protocols::CmsisDap::Edbg::Avr;
using namespace Bloom::Exceptions;
using Protocols::CmsisDap::Edbg::EdbgInterface;
MplabPickit4::MplabPickit4()
: UsbDevice(MplabPickit4::USB_VENDOR_ID, MplabPickit4::USB_PRODUCT_ID)
{}
void MplabPickit4::init() {
UsbDevice::init();
// TODO: Move away from hard-coding the CMSIS-DAP/EDBG interface number
auto& usbHidInterface = this->getEdbgInterface().getUsbHidInterface();
usbHidInterface.setNumber(0);
usbHidInterface.setLibUsbDevice(this->libUsbDevice);
usbHidInterface.setLibUsbDeviceHandle(this->libUsbDeviceHandle);
usbHidInterface.setVendorId(this->vendorId);
usbHidInterface.setProductId(this->productId);
auto usbHidInterface = Usb::HidInterface(0, this->vendorId, this->productId);
if (!usbHidInterface.isInitialised()) {
usbHidInterface.init();
}
this->detachKernelDriverFromInterface(usbHidInterface.interfaceNumber);
usbHidInterface.init();
this->getEdbgInterface().setMinimumCommandTimeGap(std::chrono::milliseconds(35));
this->edbgInterface = std::make_unique<EdbgInterface>(std::move(usbHidInterface));
this->edbgInterface->setMinimumCommandTimeGap(std::chrono::milliseconds(35));
// We don't need to claim the CMSISDAP interface here as the HIDAPI will have already done so.
if (!this->sessionStarted) {
this->startSession();
}
this->edbgAvr8Interface = std::make_unique<EdbgAvr8Interface>(this->edbgInterface);
this->edbgAvrIspInterface = std::make_unique<EdbgAvrIspInterface>(this->edbgInterface);
this->edbgAvr8Interface = std::make_unique<EdbgAvr8Interface>(this->edbgInterface.get());
this->edbgAvrIspInterface = std::make_unique<EdbgAvrIspInterface>(this->edbgInterface.get());
this->setInitialised(true);
}
@@ -41,7 +43,7 @@ namespace Bloom::DebugToolDrivers
this->endSession();
}
this->getEdbgInterface().getUsbHidInterface().close();
this->edbgInterface->getUsbHidInterface().close();
UsbDevice::close();
}
@@ -49,7 +51,7 @@ namespace Bloom::DebugToolDrivers
using namespace CommandFrames::Discovery;
using ResponseFrames::Discovery::ResponseId;
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
auto response = this->edbgInterface->sendAvrCommandFrameAndWaitForResponseFrame(
Query(QueryContext::SERIAL_NUMBER)
);
@@ -59,7 +61,7 @@ namespace Bloom::DebugToolDrivers
);
}
auto data = response.getPayloadData();
const auto data = response.getPayloadData();
return std::string(data.begin(), data.end());
}
@@ -67,7 +69,7 @@ namespace Bloom::DebugToolDrivers
using namespace CommandFrames::HouseKeeping;
using ResponseFrames::HouseKeeping::ResponseId;
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
auto response = this->edbgInterface->sendAvrCommandFrameAndWaitForResponseFrame(
StartSession()
);
@@ -83,7 +85,7 @@ namespace Bloom::DebugToolDrivers
using namespace CommandFrames::HouseKeeping;
using ResponseFrames::HouseKeeping::ResponseId;
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
auto response = this->edbgInterface->sendAvrCommandFrameAndWaitForResponseFrame(
EndSession()
);

View File

@@ -33,16 +33,12 @@ namespace Bloom::DebugToolDrivers
static const std::uint16_t USB_VENDOR_ID = 1003;
static const std::uint16_t USB_PRODUCT_ID = 8567;
MplabPickit4(): UsbDevice(MplabPickit4::USB_VENDOR_ID, MplabPickit4::USB_PRODUCT_ID) {}
MplabPickit4();
void init() override;
void close() override;
Protocols::CmsisDap::Edbg::EdbgInterface& getEdbgInterface() {
return this->edbgInterface;
}
TargetInterfaces::Microchip::Avr::Avr8::Avr8DebugInterface* getAvr8DebugInterface() override {
return this->edbgAvr8Interface.get();
}
@@ -53,7 +49,7 @@ namespace Bloom::DebugToolDrivers
std::string getName() override {
return "MPLAB PICkit 4";
};
}
/**
* Retrieves the device serial number via the Discovery Protocol.
@@ -73,7 +69,7 @@ namespace Bloom::DebugToolDrivers
void endSession();
private:
Protocols::CmsisDap::Edbg::EdbgInterface edbgInterface = Protocols::CmsisDap::Edbg::EdbgInterface();
std::unique_ptr<Protocols::CmsisDap::Edbg::EdbgInterface> edbgInterface = nullptr;
std::unique_ptr<Protocols::CmsisDap::Edbg::Avr::EdbgAvr8Interface> edbgAvr8Interface = nullptr;
std::unique_ptr<Protocols::CmsisDap::Edbg::Avr::EdbgAvrIspInterface> edbgAvrIspInterface = nullptr;

View File

@@ -8,30 +8,32 @@ namespace Bloom::DebugToolDrivers
using namespace Protocols::CmsisDap::Edbg::Avr;
using namespace Bloom::Exceptions;
using Protocols::CmsisDap::Edbg::EdbgInterface;
MplabSnap::MplabSnap()
: UsbDevice(MplabSnap::USB_VENDOR_ID, MplabSnap::USB_PRODUCT_ID)
{}
void MplabSnap::init() {
UsbDevice::init();
// TODO: Move away from hard-coding the CMSIS-DAP/EDBG interface number
auto& usbHidInterface = this->getEdbgInterface().getUsbHidInterface();
usbHidInterface.setNumber(0);
usbHidInterface.setLibUsbDevice(this->libUsbDevice);
usbHidInterface.setLibUsbDeviceHandle(this->libUsbDeviceHandle);
usbHidInterface.setVendorId(this->vendorId);
usbHidInterface.setProductId(this->productId);
auto usbHidInterface = Usb::HidInterface(0, this->vendorId, this->productId);
if (!usbHidInterface.isInitialised()) {
usbHidInterface.init();
}
this->detachKernelDriverFromInterface(usbHidInterface.interfaceNumber);
usbHidInterface.init();
this->getEdbgInterface().setMinimumCommandTimeGap(std::chrono::milliseconds(35));
this->edbgInterface = std::make_unique<EdbgInterface>(std::move(usbHidInterface));
this->edbgInterface->setMinimumCommandTimeGap(std::chrono::milliseconds(35));
// We don't need to claim the CMSISDAP interface here as the HIDAPI will have already done so.
if (!this->sessionStarted) {
this->startSession();
}
this->edbgAvr8Interface = std::make_unique<EdbgAvr8Interface>(this->edbgInterface);
this->edbgAvrIspInterface = std::make_unique<EdbgAvrIspInterface>(this->edbgInterface);
this->edbgAvr8Interface = std::make_unique<EdbgAvr8Interface>(this->edbgInterface.get());
this->edbgAvrIspInterface = std::make_unique<EdbgAvrIspInterface>(this->edbgInterface.get());
this->setInitialised(true);
}
@@ -41,7 +43,7 @@ namespace Bloom::DebugToolDrivers
this->endSession();
}
this->getEdbgInterface().getUsbHidInterface().close();
this->edbgInterface->getUsbHidInterface().close();
UsbDevice::close();
}
@@ -49,7 +51,7 @@ namespace Bloom::DebugToolDrivers
using namespace CommandFrames::Discovery;
using ResponseFrames::Discovery::ResponseId;
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
auto response = this->edbgInterface->sendAvrCommandFrameAndWaitForResponseFrame(
Query(QueryContext::SERIAL_NUMBER)
);
@@ -59,7 +61,7 @@ namespace Bloom::DebugToolDrivers
);
}
auto data = response.getPayloadData();
const auto data = response.getPayloadData();
return std::string(data.begin(), data.end());
}
@@ -67,7 +69,7 @@ namespace Bloom::DebugToolDrivers
using namespace CommandFrames::HouseKeeping;
using ResponseFrames::HouseKeeping::ResponseId;
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
auto response = this->edbgInterface->sendAvrCommandFrameAndWaitForResponseFrame(
StartSession()
);
@@ -83,7 +85,7 @@ namespace Bloom::DebugToolDrivers
using namespace CommandFrames::HouseKeeping;
using ResponseFrames::HouseKeeping::ResponseId;
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
auto response = this->edbgInterface->sendAvrCommandFrameAndWaitForResponseFrame(
EndSession()
);

View File

@@ -39,16 +39,12 @@ namespace Bloom::DebugToolDrivers
static const std::uint16_t USB_VENDOR_ID = 1003;
static const std::uint16_t USB_PRODUCT_ID = 8576;
MplabSnap(): UsbDevice(MplabSnap::USB_VENDOR_ID, MplabSnap::USB_PRODUCT_ID) {}
MplabSnap();
void init() override;
void close() override;
Protocols::CmsisDap::Edbg::EdbgInterface& getEdbgInterface() {
return this->edbgInterface;
}
TargetInterfaces::Microchip::Avr::Avr8::Avr8DebugInterface* getAvr8DebugInterface() override {
return this->edbgAvr8Interface.get();
}
@@ -59,7 +55,7 @@ namespace Bloom::DebugToolDrivers
std::string getName() override {
return "MPLAB Snap";
};
}
/**
* Retrieves the device serial number via the Discovery Protocol.
@@ -79,7 +75,7 @@ namespace Bloom::DebugToolDrivers
void endSession();
private:
Protocols::CmsisDap::Edbg::EdbgInterface edbgInterface = Protocols::CmsisDap::Edbg::EdbgInterface();
std::unique_ptr<Protocols::CmsisDap::Edbg::EdbgInterface> edbgInterface = nullptr;
/**
* The MPLAB Snap employs the EDBG AVR8 Generic protocol, for debugging AVR8 targets. This protocol is

View File

@@ -8,36 +8,32 @@ namespace Bloom::DebugToolDrivers
using namespace Protocols::CmsisDap::Edbg::Avr;
using namespace Bloom::Exceptions;
using Protocols::CmsisDap::Edbg::EdbgInterface;
PowerDebugger::PowerDebugger()
: UsbDevice(PowerDebugger::USB_VENDOR_ID, PowerDebugger::USB_PRODUCT_ID)
{}
void PowerDebugger::init() {
UsbDevice::init();
// TODO: Move away from hard-coding the CMSIS-DAP/EDBG interface number
auto& usbHidInterface = this->getEdbgInterface().getUsbHidInterface();
usbHidInterface.setNumber(0);
usbHidInterface.setLibUsbDevice(this->libUsbDevice);
usbHidInterface.setLibUsbDeviceHandle(this->libUsbDeviceHandle);
usbHidInterface.setVendorId(this->vendorId);
usbHidInterface.setProductId(this->productId);
auto usbHidInterface = Usb::HidInterface(0, this->vendorId, this->productId);
if (!usbHidInterface.isInitialised()) {
usbHidInterface.init();
}
this->detachKernelDriverFromInterface(usbHidInterface.interfaceNumber);
usbHidInterface.init();
/*
* The Power Debugger EDBG/CMSIS-DAP interface doesn't operate properly when sending commands too quickly.
*
* Because of this, we have to enforce a minimum time gap between commands. See comment in
* CmsisDapInterface class declaration for more info.
*/
this->getEdbgInterface().setMinimumCommandTimeGap(std::chrono::milliseconds(35));
this->edbgInterface = std::make_unique<EdbgInterface>(std::move(usbHidInterface));
this->edbgInterface->setMinimumCommandTimeGap(std::chrono::milliseconds(35));
// We don't need to claim the CMSISDAP interface here as the HIDAPI will have already done so.
if (!this->sessionStarted) {
this->startSession();
}
this->edbgAvr8Interface = std::make_unique<EdbgAvr8Interface>(this->edbgInterface);
this->edbgAvrIspInterface = std::make_unique<EdbgAvrIspInterface>(this->edbgInterface);
this->edbgAvr8Interface = std::make_unique<EdbgAvr8Interface>(this->edbgInterface.get());
this->edbgAvrIspInterface = std::make_unique<EdbgAvrIspInterface>(this->edbgInterface.get());
this->setInitialised(true);
}
@@ -47,7 +43,7 @@ namespace Bloom::DebugToolDrivers
this->endSession();
}
this->getEdbgInterface().getUsbHidInterface().close();
this->edbgInterface->getUsbHidInterface().close();
UsbDevice::close();
}
@@ -55,7 +51,7 @@ namespace Bloom::DebugToolDrivers
using namespace CommandFrames::Discovery;
using ResponseFrames::Discovery::ResponseId;
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
auto response = this->edbgInterface->sendAvrCommandFrameAndWaitForResponseFrame(
Query(QueryContext::SERIAL_NUMBER)
);
@@ -65,7 +61,7 @@ namespace Bloom::DebugToolDrivers
);
}
auto data = response.getPayloadData();
const auto data = response.getPayloadData();
return std::string(data.begin(), data.end());
}
@@ -73,7 +69,7 @@ namespace Bloom::DebugToolDrivers
using namespace CommandFrames::HouseKeeping;
using ResponseFrames::HouseKeeping::ResponseId;
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
auto response = this->edbgInterface->sendAvrCommandFrameAndWaitForResponseFrame(
StartSession()
);
@@ -91,7 +87,7 @@ namespace Bloom::DebugToolDrivers
using namespace CommandFrames::HouseKeeping;
using ResponseFrames::HouseKeeping::ResponseId;
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
auto response = this->edbgInterface->sendAvrCommandFrameAndWaitForResponseFrame(
EndSession()
);

View File

@@ -32,16 +32,12 @@ namespace Bloom::DebugToolDrivers
static const std::uint16_t USB_VENDOR_ID = 1003;
static const std::uint16_t USB_PRODUCT_ID = 8516;
PowerDebugger(): UsbDevice(PowerDebugger::USB_VENDOR_ID, PowerDebugger::USB_PRODUCT_ID) {}
PowerDebugger();
void init() override;
void close() override;
Protocols::CmsisDap::Edbg::EdbgInterface& getEdbgInterface() {
return this->edbgInterface;
}
TargetInterfaces::Microchip::Avr::Avr8::Avr8DebugInterface* getAvr8DebugInterface() override {
return this->edbgAvr8Interface.get();
}
@@ -52,7 +48,7 @@ namespace Bloom::DebugToolDrivers
std::string getName() override {
return "Power Debugger";
};
}
/**
* Retrieves the device serial number via the Discovery Protocol.
@@ -80,7 +76,7 @@ namespace Bloom::DebugToolDrivers
* Any non-EDBG CMSIS-DAP commands for the Power Debugger can be sent through the EDBGInterface (as the
* EdbgInterface extends the CmsisDapInterface).
*/
Protocols::CmsisDap::Edbg::EdbgInterface edbgInterface = Protocols::CmsisDap::Edbg::EdbgInterface();
std::unique_ptr<Protocols::CmsisDap::Edbg::EdbgInterface> edbgInterface = nullptr;
/**
* The Power Debugger employs the EDBG AVR8Generic protocol for interfacing with AVR8 targets.

View File

@@ -8,36 +8,36 @@ namespace Bloom::DebugToolDrivers
using namespace Protocols::CmsisDap::Edbg::Avr;
using namespace Bloom::Exceptions;
using Protocols::CmsisDap::Edbg::EdbgInterface;
using Protocols::CmsisDap::Edbg::EdbgTargetPowerManagementInterface;
XplainedMini::XplainedMini()
: UsbDevice(XplainedMini::USB_VENDOR_ID, XplainedMini::USB_PRODUCT_ID)
{}
void XplainedMini::init() {
UsbDevice::init();
// TODO: Move away from hard-coding the CMSIS-DAP/EDBG interface number
auto& usbHidInterface = this->getEdbgInterface().getUsbHidInterface();
usbHidInterface.setNumber(0);
usbHidInterface.setLibUsbDevice(this->libUsbDevice);
usbHidInterface.setLibUsbDeviceHandle(this->libUsbDeviceHandle);
usbHidInterface.setVendorId(this->vendorId);
usbHidInterface.setProductId(this->productId);
auto usbHidInterface = Usb::HidInterface(0, this->vendorId, this->productId);
if (!usbHidInterface.isInitialised()) {
usbHidInterface.detachKernelDriver();
usbHidInterface.init();
}
this->detachKernelDriverFromInterface(usbHidInterface.interfaceNumber);
usbHidInterface.init();
this->getEdbgInterface().setMinimumCommandTimeGap(std::chrono::milliseconds(35));
this->edbgInterface = std::make_unique<EdbgInterface>(std::move(usbHidInterface));
this->edbgInterface->setMinimumCommandTimeGap(std::chrono::milliseconds(35));
if (!this->sessionStarted) {
this->startSession();
}
this->targetPowerManagementInterface = std::make_unique<EdbgTargetPowerManagementInterface>(
this->edbgInterface
this->edbgInterface.get()
);
this->edbgAvr8Interface = std::make_unique<EdbgAvr8Interface>(this->edbgInterface);
this->edbgAvrIspInterface = std::make_unique<EdbgAvrIspInterface>(this->edbgInterface);
this->edbgAvr8Interface = std::make_unique<EdbgAvr8Interface>(this->edbgInterface.get());
this->edbgAvrIspInterface = std::make_unique<EdbgAvrIspInterface>(this->edbgInterface.get());
this->setInitialised(true);
}
@@ -47,7 +47,7 @@ namespace Bloom::DebugToolDrivers
this->endSession();
}
this->getEdbgInterface().getUsbHidInterface().close();
this->edbgInterface->getUsbHidInterface().close();
UsbDevice::close();
}
@@ -55,7 +55,7 @@ namespace Bloom::DebugToolDrivers
using namespace CommandFrames::Discovery;
using ResponseFrames::Discovery::ResponseId;
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
auto response = this->edbgInterface->sendAvrCommandFrameAndWaitForResponseFrame(
Query(QueryContext::SERIAL_NUMBER)
);
@@ -73,7 +73,7 @@ namespace Bloom::DebugToolDrivers
using namespace CommandFrames::HouseKeeping;
using ResponseFrames::HouseKeeping::ResponseId;
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
auto response = this->edbgInterface->sendAvrCommandFrameAndWaitForResponseFrame(
StartSession()
);
@@ -89,7 +89,7 @@ namespace Bloom::DebugToolDrivers
using namespace CommandFrames::HouseKeeping;
using ResponseFrames::HouseKeeping::ResponseId;
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
auto response = this->edbgInterface->sendAvrCommandFrameAndWaitForResponseFrame(
EndSession()
);

View File

@@ -35,16 +35,12 @@ namespace Bloom::DebugToolDrivers
static const std::uint16_t USB_VENDOR_ID = 1003;
static const std::uint16_t USB_PRODUCT_ID = 8517;
XplainedMini(): UsbDevice(XplainedMini::USB_VENDOR_ID, XplainedMini::USB_PRODUCT_ID) {}
XplainedMini();
void init() override;
void close() override;
Protocols::CmsisDap::Edbg::EdbgInterface& getEdbgInterface() {
return this->edbgInterface;
}
DebugToolDrivers::TargetInterfaces::TargetPowerManagementInterface* getTargetPowerManagementInterface() override {
return this->targetPowerManagementInterface.get();
}
@@ -59,7 +55,7 @@ namespace Bloom::DebugToolDrivers
std::string getName() override {
return "Xplained Mini";
};
}
/**
* Retrieves the device serial number via the Discovery Protocol.
@@ -79,7 +75,7 @@ namespace Bloom::DebugToolDrivers
void endSession();
private:
Protocols::CmsisDap::Edbg::EdbgInterface edbgInterface = Protocols::CmsisDap::Edbg::EdbgInterface();
std::unique_ptr<Protocols::CmsisDap::Edbg::EdbgInterface> edbgInterface = nullptr;
std::unique_ptr<Protocols::CmsisDap::Edbg::Avr::EdbgAvr8Interface> edbgAvr8Interface = nullptr;
std::unique_ptr<Protocols::CmsisDap::Edbg::Avr::EdbgAvrIspInterface> edbgAvrIspInterface = nullptr;
std::unique_ptr<

View File

@@ -8,35 +8,35 @@ namespace Bloom::DebugToolDrivers
using namespace Protocols::CmsisDap::Edbg::Avr;
using namespace Bloom::Exceptions;
using Protocols::CmsisDap::Edbg::EdbgInterface;
using Protocols::CmsisDap::Edbg::EdbgTargetPowerManagementInterface;
XplainedNano::XplainedNano()
: UsbDevice(XplainedNano::USB_VENDOR_ID, XplainedNano::USB_PRODUCT_ID)
{}
void XplainedNano::init() {
UsbDevice::init();
// TODO: Move away from hard-coding the CMSIS-DAP/EDBG interface number
auto& usbHidInterface = this->getEdbgInterface().getUsbHidInterface();
usbHidInterface.setNumber(0);
usbHidInterface.setLibUsbDevice(this->libUsbDevice);
usbHidInterface.setLibUsbDeviceHandle(this->libUsbDeviceHandle);
usbHidInterface.setVendorId(this->vendorId);
usbHidInterface.setProductId(this->productId);
auto usbHidInterface = Usb::HidInterface(0, this->vendorId, this->productId);
if (!usbHidInterface.isInitialised()) {
usbHidInterface.detachKernelDriver();
usbHidInterface.init();
}
this->detachKernelDriverFromInterface(usbHidInterface.interfaceNumber);
usbHidInterface.init();
this->getEdbgInterface().setMinimumCommandTimeGap(std::chrono::milliseconds(35));
this->edbgInterface = std::make_unique<EdbgInterface>(std::move(usbHidInterface));
this->edbgInterface->setMinimumCommandTimeGap(std::chrono::milliseconds(35));
if (!this->sessionStarted) {
this->startSession();
}
this->targetPowerManagementInterface = std::make_unique<EdbgTargetPowerManagementInterface>(
this->edbgInterface
this->edbgInterface.get()
);
this->edbgAvr8Interface = std::make_unique<EdbgAvr8Interface>(this->edbgInterface);
this->edbgAvr8Interface = std::make_unique<EdbgAvr8Interface>(this->edbgInterface.get());
this->setInitialised(true);
}
@@ -45,7 +45,7 @@ namespace Bloom::DebugToolDrivers
this->endSession();
}
this->getEdbgInterface().getUsbHidInterface().close();
this->edbgInterface->getUsbHidInterface().close();
UsbDevice::close();
}
@@ -53,7 +53,7 @@ namespace Bloom::DebugToolDrivers
using namespace CommandFrames::Discovery;
using ResponseFrames::Discovery::ResponseId;
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
auto response = this->edbgInterface->sendAvrCommandFrameAndWaitForResponseFrame(
Query(QueryContext::SERIAL_NUMBER)
);
@@ -63,7 +63,7 @@ namespace Bloom::DebugToolDrivers
);
}
auto data = response.getPayloadData();
const auto data = response.getPayloadData();
return std::string(data.begin(), data.end());
}
@@ -71,7 +71,7 @@ namespace Bloom::DebugToolDrivers
using namespace CommandFrames::HouseKeeping;
using ResponseFrames::HouseKeeping::ResponseId;
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
auto response = this->edbgInterface->sendAvrCommandFrameAndWaitForResponseFrame(
StartSession()
);
@@ -87,7 +87,7 @@ namespace Bloom::DebugToolDrivers
using namespace CommandFrames::HouseKeeping;
using ResponseFrames::HouseKeeping::ResponseId;
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
auto response = this->edbgInterface->sendAvrCommandFrameAndWaitForResponseFrame(
EndSession()
);

View File

@@ -34,16 +34,12 @@ namespace Bloom::DebugToolDrivers
static const std::uint16_t USB_VENDOR_ID = 1003;
static const std::uint16_t USB_PRODUCT_ID = 8517;
XplainedNano(): UsbDevice(XplainedNano::USB_VENDOR_ID, XplainedNano::USB_PRODUCT_ID) {}
XplainedNano();
void init() override;
void close() override;
Protocols::CmsisDap::Edbg::EdbgInterface& getEdbgInterface() {
return this->edbgInterface;
}
DebugToolDrivers::TargetInterfaces::TargetPowerManagementInterface* getTargetPowerManagementInterface() override {
return this->targetPowerManagementInterface.get();
}
@@ -54,7 +50,7 @@ namespace Bloom::DebugToolDrivers
std::string getName() override {
return "Xplained Nano";
};
}
/**
* Retrieves the device serial number via the Discovery Protocol.
@@ -74,7 +70,7 @@ namespace Bloom::DebugToolDrivers
void endSession();
private:
Protocols::CmsisDap::Edbg::EdbgInterface edbgInterface = Protocols::CmsisDap::Edbg::EdbgInterface();
std::unique_ptr<Protocols::CmsisDap::Edbg::EdbgInterface> edbgInterface = nullptr;
std::unique_ptr<Protocols::CmsisDap::Edbg::Avr::EdbgAvr8Interface> edbgAvr8Interface = nullptr;
std::unique_ptr<
Protocols::CmsisDap::Edbg::EdbgTargetPowerManagementInterface

View File

@@ -8,35 +8,35 @@ namespace Bloom::DebugToolDrivers
using namespace Protocols::CmsisDap::Edbg::Avr;
using namespace Bloom::Exceptions;
using Protocols::CmsisDap::Edbg::EdbgInterface;
using Protocols::CmsisDap::Edbg::EdbgTargetPowerManagementInterface;
XplainedPro::XplainedPro()
: UsbDevice(XplainedPro::USB_VENDOR_ID, XplainedPro::USB_PRODUCT_ID)
{}
void XplainedPro::init() {
UsbDevice::init();
// TODO: Move away from hard-coding the CMSIS-DAP/EDBG interface number
auto& usbHidInterface = this->getEdbgInterface().getUsbHidInterface();
usbHidInterface.setNumber(0);
usbHidInterface.setLibUsbDevice(this->libUsbDevice);
usbHidInterface.setLibUsbDeviceHandle(this->libUsbDeviceHandle);
usbHidInterface.setVendorId(this->vendorId);
usbHidInterface.setProductId(this->productId);
auto usbHidInterface = Usb::HidInterface(0, this->vendorId, this->productId);
if (!usbHidInterface.isInitialised()) {
usbHidInterface.detachKernelDriver();
usbHidInterface.init();
}
this->detachKernelDriverFromInterface(usbHidInterface.interfaceNumber);
usbHidInterface.init();
this->getEdbgInterface().setMinimumCommandTimeGap(std::chrono::milliseconds(35));
this->edbgInterface = std::make_unique<EdbgInterface>(std::move(usbHidInterface));
this->edbgInterface->setMinimumCommandTimeGap(std::chrono::milliseconds(35));
if (!this->sessionStarted) {
this->startSession();
}
this->targetPowerManagementInterface = std::make_unique<EdbgTargetPowerManagementInterface>(
this->edbgInterface
this->edbgInterface.get()
);
this->edbgAvr8Interface = std::make_unique<EdbgAvr8Interface>(this->edbgInterface);
this->edbgAvr8Interface = std::make_unique<EdbgAvr8Interface>(this->edbgInterface.get());
/*
* The Xplained Pro debug tool returns incorrect data for any read memory command that exceeds 256 bytes in the
@@ -54,7 +54,7 @@ namespace Bloom::DebugToolDrivers
this->endSession();
}
this->getEdbgInterface().getUsbHidInterface().close();
this->edbgInterface->getUsbHidInterface().close();
UsbDevice::close();
}
@@ -62,7 +62,7 @@ namespace Bloom::DebugToolDrivers
using namespace CommandFrames::Discovery;
using ResponseFrames::Discovery::ResponseId;
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
auto response = this->edbgInterface->sendAvrCommandFrameAndWaitForResponseFrame(
Query(QueryContext::SERIAL_NUMBER)
);
@@ -80,7 +80,7 @@ namespace Bloom::DebugToolDrivers
using namespace CommandFrames::HouseKeeping;
using ResponseFrames::HouseKeeping::ResponseId;
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
auto response = this->edbgInterface->sendAvrCommandFrameAndWaitForResponseFrame(
StartSession()
);
@@ -96,7 +96,7 @@ namespace Bloom::DebugToolDrivers
using namespace CommandFrames::HouseKeeping;
using ResponseFrames::HouseKeeping::ResponseId;
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
auto response = this->edbgInterface->sendAvrCommandFrameAndWaitForResponseFrame(
EndSession()
);

View File

@@ -34,16 +34,12 @@ namespace Bloom::DebugToolDrivers
static const std::uint16_t USB_VENDOR_ID = 1003;
static const std::uint16_t USB_PRODUCT_ID = 8465;
XplainedPro(): UsbDevice(XplainedPro::USB_VENDOR_ID, XplainedPro::USB_PRODUCT_ID) {}
XplainedPro();
void init() override;
void close() override;
Protocols::CmsisDap::Edbg::EdbgInterface& getEdbgInterface() {
return this->edbgInterface;
}
DebugToolDrivers::TargetInterfaces::TargetPowerManagementInterface* getTargetPowerManagementInterface() override {
return this->targetPowerManagementInterface.get();
}
@@ -54,7 +50,7 @@ namespace Bloom::DebugToolDrivers
std::string getName() override {
return "Xplained Pro";
};
}
/**
* Retrieves the device serial number via the Discovery Protocol.
@@ -74,7 +70,7 @@ namespace Bloom::DebugToolDrivers
void endSession();
private:
Protocols::CmsisDap::Edbg::EdbgInterface edbgInterface = Protocols::CmsisDap::Edbg::EdbgInterface();
std::unique_ptr<Protocols::CmsisDap::Edbg::EdbgInterface> edbgInterface = nullptr;
std::unique_ptr<Protocols::CmsisDap::Edbg::Avr::EdbgAvr8Interface> edbgAvr8Interface = nullptr;
std::unique_ptr<