2021-11-28 22:41:41 +00:00
|
|
|
#include "MplabPickit4.hpp"
|
|
|
|
|
|
2024-12-30 15:41:52 +00:00
|
|
|
#include "src/Logger/Logger.hpp"
|
|
|
|
|
|
|
|
|
|
#include "src/TargetController/Exceptions/DeviceInitializationFailure.hpp"
|
2023-05-07 16:44:15 +01:00
|
|
|
|
2023-11-18 23:50:08 +00:00
|
|
|
namespace DebugToolDrivers::Microchip
|
2022-02-05 15:32:08 +00:00
|
|
|
{
|
Made the EDBG CMSIS-DAP command delay optional for all debug tools, and disabled it by default.
The command delay was really choking Bloom's EDBG driver, causing a very noticeable drag on Bloom's performance. It's much faster with the command delay disabled.
There was a good reason for why I introduced this some time ago. Without it, some EDBG debug tools were misbehaving - I remember that for certain. But now, I cannot seem to reproduce these issues. Very odd.
If the issues do reappear, I may have to enable the command delay by default, again, for some debug tools.
For now, if any users experience issues, I'll just suggest they manually enable the command delay via their project config.
Also, I'm not going to document this new config option, as I would prefer the user to approach me if they experience issues as a result of this, so that I'll know if it needs revisiting.
2024-10-27 00:25:42 +01:00
|
|
|
MplabPickit4::MplabPickit4(const DebugToolConfig& debugToolConfig)
|
2022-10-02 15:29:17 +01:00
|
|
|
: EdbgDevice(
|
Made the EDBG CMSIS-DAP command delay optional for all debug tools, and disabled it by default.
The command delay was really choking Bloom's EDBG driver, causing a very noticeable drag on Bloom's performance. It's much faster with the command delay disabled.
There was a good reason for why I introduced this some time ago. Without it, some EDBG debug tools were misbehaving - I remember that for certain. But now, I cannot seem to reproduce these issues. Very odd.
If the issues do reappear, I may have to enable the command delay by default, again, for some debug tools.
For now, if any users experience issues, I'll just suggest they manually enable the command delay via their project config.
Also, I'm not going to document this new config option, as I would prefer the user to approach me if they experience issues as a result of this, so that I'll know if it needs revisiting.
2024-10-27 00:25:42 +01:00
|
|
|
debugToolConfig,
|
2022-10-02 15:29:17 +01:00
|
|
|
MplabPickit4::USB_VENDOR_ID,
|
|
|
|
|
MplabPickit4::USB_PRODUCT_ID,
|
|
|
|
|
MplabPickit4::CMSIS_HID_INTERFACE_NUMBER
|
|
|
|
|
)
|
2022-10-01 16:50:57 +01:00
|
|
|
{}
|
2023-05-07 16:44:15 +01:00
|
|
|
|
|
|
|
|
void MplabPickit4::init() {
|
2024-12-30 15:41:52 +00:00
|
|
|
using Exceptions::DeviceInitializationFailure;
|
|
|
|
|
|
|
|
|
|
if (!UsbDevice::devicePresent(this->vendorId, this->productId)) {
|
|
|
|
|
auto blDevice = Usb::UsbDevice::tryDevice(
|
|
|
|
|
MplabPickit4::PIC_MODE_USB_VENDOR_ID,
|
|
|
|
|
MplabPickit4::BL_MODE_USB_PRODUCT_ID
|
2023-05-07 16:44:15 +01:00
|
|
|
);
|
|
|
|
|
|
2024-12-30 15:41:52 +00:00
|
|
|
if (blDevice.has_value()) {
|
|
|
|
|
if (!this->toolConfig.exitBootloaderMode) {
|
|
|
|
|
throw DeviceInitializationFailure{"Device is currently in bootloader mode"};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Logger::warning("Found device in bootloader mode - attempting exit operation");
|
|
|
|
|
this->exitBootloaderMode(*blDevice);
|
|
|
|
|
|
|
|
|
|
Logger::info("Waiting for device to re-enumerate...");
|
|
|
|
|
if (
|
|
|
|
|
!Usb::UsbDevice::waitForDevice(
|
|
|
|
|
MplabPickit4::PIC_MODE_USB_VENDOR_ID,
|
|
|
|
|
MplabPickit4::PIC_MODE_USB_PRODUCT_ID,
|
|
|
|
|
std::chrono::seconds{8}
|
|
|
|
|
)
|
|
|
|
|
) {
|
|
|
|
|
throw DeviceInitializationFailure{"Timeout exceeded whilst waiting for device to re-enumerate"};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Logger::info("Re-enumerated device found - exit operation was successful");
|
2023-05-07 16:44:15 +01:00
|
|
|
}
|
|
|
|
|
|
2024-12-30 15:41:52 +00:00
|
|
|
auto picDevice = Usb::UsbDevice::tryDevice(
|
|
|
|
|
MplabPickit4::PIC_MODE_USB_VENDOR_ID,
|
|
|
|
|
MplabPickit4::PIC_MODE_USB_PRODUCT_ID
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (picDevice.has_value()) {
|
|
|
|
|
if (!this->toolConfig.enableEdbgMode) {
|
|
|
|
|
throw DeviceInitializationFailure{"Device is currently in PIC mode"};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Logger::warning("Found device in PIC mode - attempting to switch to EDBG (AVR) mode");
|
|
|
|
|
this->enableEdbgMode(*picDevice);
|
|
|
|
|
|
|
|
|
|
Logger::info("Waiting for device to re-enumerate...");
|
|
|
|
|
if (!Usb::UsbDevice::waitForDevice(this->vendorId, this->productId, std::chrono::seconds{8})) {
|
|
|
|
|
throw DeviceInitializationFailure{"Timeout exceeded whilst waiting for device to re-enumerate"};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Logger::info("Re-enumerated device found - mode switch operation was successful");
|
|
|
|
|
}
|
2023-05-07 16:44:15 +01:00
|
|
|
}
|
2024-12-30 15:41:52 +00:00
|
|
|
|
|
|
|
|
EdbgDevice::init();
|
2023-05-07 16:44:15 +01:00
|
|
|
}
|
2023-05-21 21:08:25 +01:00
|
|
|
|
|
|
|
|
void MplabPickit4::configureAvr8Interface() {
|
|
|
|
|
this->edbgAvr8Interface->setReactivateJtagTargetPostProgrammingMode(true);
|
|
|
|
|
}
|
2021-11-28 22:41:41 +00:00
|
|
|
}
|