Debug tool device driver for Xplained Mini

This commit is contained in:
Nav
2021-11-28 20:27:02 +00:00
parent a6ffd3cecc
commit 3748173877
5 changed files with 167 additions and 0 deletions

View File

@@ -87,6 +87,7 @@ add_executable(Bloom
src/DebugToolDrivers/Microchip/PowerDebugger/PowerDebugger.cpp src/DebugToolDrivers/Microchip/PowerDebugger/PowerDebugger.cpp
src/DebugToolDrivers/Microchip/MplabSnap/MplabSnap.cpp src/DebugToolDrivers/Microchip/MplabSnap/MplabSnap.cpp
src/DebugToolDrivers/Microchip/XplainedPro/XplainedPro.cpp src/DebugToolDrivers/Microchip/XplainedPro/XplainedPro.cpp
src/DebugToolDrivers/Microchip/XplainedMini/XplainedMini.cpp
src/DebugToolDrivers/Microchip/CuriosityNano/CuriosityNano.cpp src/DebugToolDrivers/Microchip/CuriosityNano/CuriosityNano.cpp
src/DebugToolDrivers/Protocols/CMSIS-DAP/Command.cpp src/DebugToolDrivers/Protocols/CMSIS-DAP/Command.cpp
src/DebugToolDrivers/Protocols/CMSIS-DAP/Response.cpp src/DebugToolDrivers/Protocols/CMSIS-DAP/Response.cpp

View File

@@ -6,4 +6,5 @@
#include "src/DebugToolDrivers/Microchip/PowerDebugger/PowerDebugger.hpp" #include "src/DebugToolDrivers/Microchip/PowerDebugger/PowerDebugger.hpp"
#include "src/DebugToolDrivers/Microchip/MplabSnap/MplabSnap.hpp" #include "src/DebugToolDrivers/Microchip/MplabSnap/MplabSnap.hpp"
#include "src/DebugToolDrivers/Microchip/XplainedPro/XplainedPro.hpp" #include "src/DebugToolDrivers/Microchip/XplainedPro/XplainedPro.hpp"
#include "src/DebugToolDrivers/Microchip/XplainedMini/XplainedMini.hpp"
#include "src/DebugToolDrivers/Microchip/CuriosityNano/CuriosityNano.hpp" #include "src/DebugToolDrivers/Microchip/CuriosityNano/CuriosityNano.hpp"

View File

@@ -0,0 +1,85 @@
#include "XplainedMini.hpp"
#include "src/TargetController/Exceptions/DeviceFailure.hpp"
#include "src/TargetController/Exceptions/DeviceInitializationFailure.hpp"
using namespace Bloom::DebugToolDrivers;
using namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr;
using namespace Bloom::Exceptions;
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);
if (!usbHidInterface.isInitialised()) {
usbHidInterface.detachKernelDriver();
usbHidInterface.init();
}
this->getEdbgInterface().setMinimumCommandTimeGap(std::chrono::milliseconds(35));
if (!this->sessionStarted) {
this->startSession();
}
this->edbgAvr8Interface = std::make_unique<EdbgAvr8Interface>(this->edbgInterface);
this->edbgAvr8Interface->setAvoidMaskedMemoryRead(true);
this->setInitialised(true);
}
void XplainedMini::close() {
if (this->sessionStarted) {
this->endSession();
}
this->getEdbgInterface().getUsbHidInterface().close();
UsbDevice::close();
}
std::string XplainedMini::getSerialNumber() {
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
CommandFrames::Discovery::Query(CommandFrames::Discovery::QueryContext::SERIAL_NUMBER)
);
if (response.getResponseId() != CommandFrames::Discovery::ResponseId::OK) {
throw DeviceInitializationFailure(
"Failed to fetch serial number from device - invalid Discovery Protocol response ID."
);
}
auto data = response.getPayloadData();
return std::string(data.begin(), data.end());
}
void XplainedMini::startSession() {
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
CommandFrames::HouseKeeping::StartSession()
);
if (response.getResponseId() == CommandFrames::HouseKeeping::ResponseId::FAILED) {
// Failed response returned!
throw DeviceInitializationFailure("Failed to start session with Xplained Mini!");
}
this->sessionStarted = true;
}
void XplainedMini::endSession() {
auto response = this->getEdbgInterface().sendAvrCommandFrameAndWaitForResponseFrame(
CommandFrames::HouseKeeping::EndSession()
);
if (response.getResponseId() == CommandFrames::HouseKeeping::ResponseId::FAILED) {
// Failed response returned!
throw DeviceFailure("Failed to end session with Xplained Mini!");
}
this->sessionStarted = false;
}

View File

@@ -0,0 +1,74 @@
#pragma once
#include <cstdint>
#include <vector>
#include <memory>
#include "src/DebugToolDrivers/DebugTool.hpp"
#include "src/DebugToolDrivers/USB/UsbDevice.hpp"
#include "src/DebugToolDrivers/USB/HID/HidInterface.hpp"
#include "src/DebugToolDrivers/Protocols/CMSIS-DAP/CmsisDapInterface.hpp"
#include "src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/EdbgInterface.hpp"
#include "src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/EdbgAvr8Interface.hpp"
#include "src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AvrCommandFrames.hpp"
namespace Bloom::DebugToolDrivers
{
/**
* The Xplained Mini is an evaluation board featuring an on-board debugger. The debugger is EDBG-based.
*
* Because the on-board debugger is EDBG-based, we can employ the same AVR8 driver implementation as we do with
* other EDBG-based debuggers. See the EdbgAvr8Interface class for more.
*
* USB Setup:
* Vendor ID: 0x03eb (1003)
* Product ID: 0x2145 (8517)
*/
class XplainedMini: public DebugTool, public Usb::UsbDevice
{
public:
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) {}
void init() override;
void close() override;
Protocols::CmsisDap::Edbg::EdbgInterface& getEdbgInterface() {
return this->edbgInterface;
}
TargetInterfaces::Microchip::Avr::Avr8::Avr8Interface* getAvr8Interface() override {
return this->edbgAvr8Interface.get();
}
std::string getName() override {
return "Xplained Mini";
};
/**
* Retrieves the device serial number via the Discovery Protocol.
*
* @return
*/
std::string getSerialNumber() override;
/**
* Starts a session with the EDBG-based tool using the Housekeeping protocol.
*/
void startSession();
/**
* Ends the active session with the debug tool.
*/
void endSession();
private:
Protocols::CmsisDap::Edbg::EdbgInterface edbgInterface = Protocols::CmsisDap::Edbg::EdbgInterface();
std::unique_ptr<Protocols::CmsisDap::Edbg::Avr::EdbgAvr8Interface> edbgAvr8Interface = nullptr;
bool sessionStarted = false;
};
}

View File

@@ -124,6 +124,12 @@ namespace Bloom
return std::make_unique<DebugToolDrivers::XplainedPro>(); return std::make_unique<DebugToolDrivers::XplainedPro>();
} }
}, },
{
"xplained-mini",
[] {
return std::make_unique<DebugToolDrivers::XplainedMini>();
}
},
{ {
"curiosity-nano", "curiosity-nano",
[] { [] {