2021-04-04 21:04:12 +01:00
|
|
|
#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 Atmel-ICE device is an EDBG (Embedded Debugger) device. It implements the CMSIS-DAP layer as well
|
|
|
|
|
* as an Atmel Data Gateway Interface (DGI).
|
|
|
|
|
*
|
|
|
|
|
* Communication:
|
|
|
|
|
* Using the Atmel-ICE device for AVR debugging/programming requires the AVR communication protocol, which
|
|
|
|
|
* is a sub-protocol of the CMSIS-DAP (AVR communication protocol commands are wrapped in CMSIS-DAP vendor
|
|
|
|
|
* commands). AVR communication protocol commands contain AVR frames, in which commands for numerous
|
|
|
|
|
* sub-protocols are enveloped.
|
|
|
|
|
*
|
|
|
|
|
* So to summarise, issuing an AVR command to the EDBG device, involves:
|
|
|
|
|
* Actual command data -> AVR sub-protocol -> AVR Frames -> CMSIS-DAP Vendor commands -> EDBG Device
|
|
|
|
|
*
|
|
|
|
|
* For more information on protocols and sub-protocols employed by Microchip EDBG devices, see
|
|
|
|
|
* the 'Embedded Debugger-Based Tools Protocols User's Guide' document by Microchip.
|
|
|
|
|
* @link http://ww1.microchip.com/downloads/en/DeviceDoc/50002630A.pdf
|
|
|
|
|
*
|
|
|
|
|
* USB Setup:
|
|
|
|
|
* Vendor ID: 0x03eb (1003)
|
|
|
|
|
* Product ID: 0x2141 (8513)
|
|
|
|
|
*
|
|
|
|
|
* The Atmel-ICE consists of two USB interfaces. One HID interface for CMSIS-DAP and one vendor specific
|
|
|
|
|
* interface for the DGI. We only work with the CMSIS-DAP interface, for now.
|
|
|
|
|
*/
|
|
|
|
|
class AtmelIce: public DebugTool, public Usb::UsbDevice
|
|
|
|
|
{
|
|
|
|
|
private:
|
|
|
|
|
/**
|
|
|
|
|
* The EDBG interface implements additional functionality via vendor specific CMSIS-DAP commands.
|
|
|
|
|
* In other words, all EDBG commands are just CMSIS-DAP vendor commands that allow the debug tool
|
|
|
|
|
* to support additional functionality, like AVR programming and debugging.
|
|
|
|
|
*
|
|
|
|
|
* Any non-EDBG CMSIS-DAP commands for the Atmel-ICE can be sent through the EdbgInterface (as the
|
|
|
|
|
* EdbgInterface extends the CmsisDapInterface).
|
|
|
|
|
*/
|
2021-05-24 20:58:49 +01:00
|
|
|
Protocols::CmsisDap::Edbg::EdbgInterface edbgInterface = Protocols::CmsisDap::Edbg::EdbgInterface();
|
2021-04-04 21:04:12 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The Atmel-ICE employs the EDBG AVR8 Generic protocol, for debugging AVR8 targets. This protocol is
|
|
|
|
|
* implemented in EdbgAvr8Interface. See the EdbgAvr8Interface class for more information.
|
|
|
|
|
*/
|
2021-05-24 20:58:49 +01:00
|
|
|
std::unique_ptr<Protocols::CmsisDap::Edbg::Avr::EdbgAvr8Interface> edbgAvr8Interface = nullptr;
|
2021-04-04 21:04:12 +01:00
|
|
|
|
|
|
|
|
bool sessionStarted = false;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
static const std::uint16_t USB_VENDOR_ID = 1003;
|
|
|
|
|
static const std::uint16_t USB_PRODUCT_ID = 8513;
|
|
|
|
|
|
2021-04-06 02:10:14 +01:00
|
|
|
AtmelIce(): UsbDevice(AtmelIce::USB_VENDOR_ID, AtmelIce::USB_PRODUCT_ID) {}
|
2021-04-04 21:04:12 +01:00
|
|
|
|
|
|
|
|
void init() override;
|
2021-05-24 20:58:49 +01:00
|
|
|
|
2021-04-04 21:04:12 +01:00
|
|
|
void close() override;
|
|
|
|
|
|
2021-05-24 20:58:49 +01:00
|
|
|
Protocols::CmsisDap::Edbg::EdbgInterface& getEdbgInterface() {
|
2021-04-04 21:04:12 +01:00
|
|
|
return this->edbgInterface;
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-24 20:58:49 +01:00
|
|
|
TargetInterfaces::Microchip::Avr::Avr8::Avr8Interface* getAvr8Interface() override {
|
2021-04-04 21:04:12 +01:00
|
|
|
return this->edbgAvr8Interface.get();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string getName() override {
|
|
|
|
|
return "Atmel-ICE";
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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();
|
|
|
|
|
};
|
|
|
|
|
}
|