2023-11-18 22:58:48 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
|
#include <memory>
|
|
|
|
|
#include <optional>
|
|
|
|
|
|
|
|
|
|
#include "src/DebugToolDrivers/DebugTool.hpp"
|
|
|
|
|
#include "src/DebugToolDrivers/USB/UsbDevice.hpp"
|
2024-07-23 21:14:22 +01:00
|
|
|
#include "src/DebugToolDrivers/USB/UsbInterface.hpp"
|
2023-11-18 22:58:48 +00:00
|
|
|
|
2024-10-06 23:32:36 +01:00
|
|
|
#include "WchLinkToolConfig.hpp"
|
|
|
|
|
#include "src/ProjectConfig.hpp"
|
|
|
|
|
|
2023-11-18 22:58:48 +00:00
|
|
|
#include "Protocols/WchLink/WchLinkInterface.hpp"
|
2024-11-16 20:05:26 +00:00
|
|
|
#include "Protocols/WchLink/WchLinkProgrammingInterface.hpp"
|
2024-07-23 21:14:22 +01:00
|
|
|
#include "src/DebugToolDrivers/Protocols/RiscVDebugSpec/DebugTranslator.hpp"
|
2023-11-18 22:58:48 +00:00
|
|
|
|
2024-11-16 20:05:26 +00:00
|
|
|
#include "src/Targets/RiscV/Wch/TargetDescriptionFile.hpp"
|
|
|
|
|
|
2023-11-18 22:58:48 +00:00
|
|
|
#include "WchGeneric.hpp"
|
|
|
|
|
#include "DeviceInfo.hpp"
|
|
|
|
|
|
|
|
|
|
namespace DebugToolDrivers::Wch
|
|
|
|
|
{
|
|
|
|
|
class WchLinkBase: public DebugTool, public Usb::UsbDevice
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
WchLinkBase(
|
2024-10-06 23:32:36 +01:00
|
|
|
const DebugToolConfig& toolConfig,
|
2023-11-18 22:58:48 +00:00
|
|
|
WchLinkVariant variant,
|
|
|
|
|
std::uint16_t vendorId,
|
|
|
|
|
std::uint16_t productId,
|
|
|
|
|
std::uint8_t wchLinkUsbInterfaceNumber
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
void init() override;
|
|
|
|
|
|
|
|
|
|
void close() override;
|
|
|
|
|
|
2024-07-23 21:44:15 +01:00
|
|
|
void postInit() override;
|
|
|
|
|
|
2024-07-23 21:14:22 +01:00
|
|
|
[[nodiscard]] bool isInitialised() const override;
|
|
|
|
|
|
2023-11-18 22:58:48 +00:00
|
|
|
std::string getSerialNumber() override;
|
|
|
|
|
|
2024-07-23 21:14:22 +01:00
|
|
|
::DebugToolDrivers::Protocols::RiscVDebugSpec::DebugTranslator* getRiscVDebugInterface(
|
|
|
|
|
const Targets::RiscV::TargetDescriptionFile& targetDescriptionFile,
|
|
|
|
|
const Targets::RiscV::RiscVTargetConfig& targetConfig
|
|
|
|
|
) override;
|
2023-11-21 22:04:27 +00:00
|
|
|
|
2023-12-09 18:22:32 +00:00
|
|
|
/**
|
|
|
|
|
* WCH-Link debug tools cannot write to flash memory via the RISC-V debug interface (RiscVDebugInterface).
|
|
|
|
|
* Flash memory writes via abstract commands fail silently.
|
|
|
|
|
*
|
|
|
|
|
* We have to send a vendor-specific command to the debug tool, in order to program the target.
|
|
|
|
|
*
|
|
|
|
|
* For this reason, we have to provide an implementation of the RiscVProgramInterface, so that the RISC-V
|
|
|
|
|
* target driver forwards any flash memory writes to this implementation (instead of relying on the debug
|
|
|
|
|
* interface).
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
2024-11-16 20:05:26 +00:00
|
|
|
Protocols::WchLink::WchLinkProgrammingInterface* getRiscVProgramInterface(
|
2024-07-23 21:14:22 +01:00
|
|
|
const Targets::RiscV::TargetDescriptionFile& targetDescriptionFile,
|
|
|
|
|
const Targets::RiscV::RiscVTargetConfig& targetConfig
|
|
|
|
|
) override;
|
|
|
|
|
|
|
|
|
|
Protocols::WchLink::WchLinkInterface* getRiscVIdentificationInterface(
|
|
|
|
|
const Targets::RiscV::TargetDescriptionFile& targetDescriptionFile,
|
|
|
|
|
const Targets::RiscV::RiscVTargetConfig& targetConfig
|
|
|
|
|
) override;
|
2023-12-09 18:22:32 +00:00
|
|
|
|
2023-11-18 22:58:48 +00:00
|
|
|
protected:
|
2024-10-06 23:32:36 +01:00
|
|
|
WchLinkToolConfig toolConfig;
|
2024-07-23 21:14:22 +01:00
|
|
|
bool initialised = false;
|
|
|
|
|
|
2023-11-18 22:58:48 +00:00
|
|
|
WchLinkVariant variant;
|
|
|
|
|
|
|
|
|
|
std::uint8_t wchLinkUsbInterfaceNumber;
|
|
|
|
|
std::unique_ptr<Usb::UsbInterface> wchLinkUsbInterface = nullptr;
|
|
|
|
|
std::unique_ptr<Protocols::WchLink::WchLinkInterface> wchLinkInterface = nullptr;
|
2024-11-16 20:05:26 +00:00
|
|
|
std::unique_ptr<Protocols::WchLink::WchLinkProgrammingInterface> wchLinkProgrammingInterface = nullptr;
|
2024-07-23 21:14:22 +01:00
|
|
|
std::unique_ptr<::DebugToolDrivers::Protocols::RiscVDebugSpec::DebugTranslator> wchRiscVTranslator = nullptr;
|
2023-11-18 22:58:48 +00:00
|
|
|
|
|
|
|
|
mutable std::optional<DeviceInfo> cachedDeviceInfo = std::nullopt;
|
|
|
|
|
|
|
|
|
|
const DeviceInfo& getDeviceInfo() const;
|
|
|
|
|
};
|
|
|
|
|
}
|