2021-06-26 15:24:07 +02:00
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
2021-06-19 17:28:48 +02:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2021 Gwenhael Goavec-Merou <gwenhael.goavec-merou@trabucayre.com>
|
2021-06-26 15:24:07 +02:00
|
|
|
*/
|
2021-06-19 17:28:48 +02:00
|
|
|
|
|
|
|
|
#ifndef SRC_CMSISDAP_HPP_
|
|
|
|
|
#define SRC_CMSISDAP_HPP_
|
|
|
|
|
|
|
|
|
|
#include <hidapi.h>
|
|
|
|
|
#include <libusb.h>
|
|
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
2022-10-15 16:17:32 +02:00
|
|
|
#include "cable.hpp"
|
2021-06-19 17:28:48 +02:00
|
|
|
#include "jtagInterface.hpp"
|
|
|
|
|
|
|
|
|
|
class CmsisDAP: public JtagInterface {
|
|
|
|
|
public:
|
|
|
|
|
/*!
|
|
|
|
|
* \brief contructor: open device with vid/pid if != 0
|
|
|
|
|
* else search for a compatible device
|
|
|
|
|
* \param[in] vid: vendor id
|
|
|
|
|
* \param[in] pid: product id
|
2022-08-29 20:58:51 +02:00
|
|
|
* \param[in] index: interface number
|
2021-11-11 17:42:51 +01:00
|
|
|
* \param[in] verbose: verbose level 0 normal, 1 verbose
|
2021-06-19 17:28:48 +02:00
|
|
|
*/
|
2022-10-15 16:17:32 +02:00
|
|
|
CmsisDAP(const cable_t &cable, int index, uint8_t verbose);
|
2021-06-19 17:28:48 +02:00
|
|
|
|
|
|
|
|
~CmsisDAP();
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \brief configure probe clk frequency
|
|
|
|
|
* \param[in] clkHZ: frequency in Hertz
|
|
|
|
|
* \return <= 0 if something wrong, clkHZ otherwise
|
|
|
|
|
*/
|
|
|
|
|
int setClkFreq(uint32_t clkHZ) override;
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \brief store a len tms bits in a buffer. send is only done if
|
|
|
|
|
* flush_buffer
|
|
|
|
|
* \param[in] tms: serie of tms state
|
|
|
|
|
* \param[in] len: number of tms bits
|
|
|
|
|
* \param[in] flush_buffer: force buffer to be send or not
|
|
|
|
|
* \return <= 0 if something wrong, len otherwise
|
|
|
|
|
*/
|
2021-11-06 10:31:00 +01:00
|
|
|
int writeTMS(uint8_t *tms, uint32_t len, bool flush_buffer) override;
|
2021-06-19 17:28:48 +02:00
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \brief write and read len bits with optional tms set to 1 if end
|
|
|
|
|
* \param[in] tx: serie of tdi state to send
|
|
|
|
|
* \param[out] rx: buffer to store tdo bits from device
|
|
|
|
|
* \param[in] len: number of bit to read/write
|
|
|
|
|
* \param[in] end: if true tms is set to one with the last tdi bit
|
|
|
|
|
* \return <= 0 if something wrong, len otherwise
|
|
|
|
|
*/
|
|
|
|
|
int writeTDI(uint8_t *tx, uint8_t *rx, uint32_t len, bool end) override;
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \brief send a serie of clock cycle with constant TMS and TDI
|
|
|
|
|
* \param[in] tms: tms state
|
|
|
|
|
* \param[in] tdi: tdi state
|
|
|
|
|
* \param[in] clk_len: number of clock cycle
|
|
|
|
|
* \return <= 0 if something wrong, clk_len otherwise
|
|
|
|
|
*/
|
|
|
|
|
int toggleClk(uint8_t tms, uint8_t tdi, uint32_t clk_len) override;
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \brief flush TMS buffer
|
|
|
|
|
* \return <=0 if something fail, > 0 otherwise
|
|
|
|
|
*/
|
|
|
|
|
int flush() override;
|
|
|
|
|
|
|
|
|
|
/* not used */
|
|
|
|
|
int get_buffer_size() override { return 0;}
|
|
|
|
|
/* not used */
|
|
|
|
|
bool isFull() override {return false;}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
/*!
|
|
|
|
|
* \brief connect device in JTAG mode
|
|
|
|
|
* \return 1 if success <= 0 otherwhise
|
|
|
|
|
*/
|
|
|
|
|
int dapConnect();
|
2021-10-12 07:52:38 +02:00
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \brief disconnect device
|
|
|
|
|
* \return 1 if success <= 0 otherwhise
|
|
|
|
|
*/
|
|
|
|
|
int dapDisconnect();
|
|
|
|
|
int dapResetTarget();
|
2021-06-19 17:28:48 +02:00
|
|
|
int read_info(uint8_t info, uint8_t *rd_info, int max_len);
|
|
|
|
|
int xfer(int tx_len, uint8_t *rx_buff, int rx_len);
|
|
|
|
|
int xfer(uint8_t instruction, int tx_len,
|
|
|
|
|
uint8_t *rx_buff, int rx_len);
|
|
|
|
|
|
|
|
|
|
void display_info(uint8_t info, uint8_t type);
|
|
|
|
|
int writeJtagSequence(uint8_t tms, uint8_t *tx, uint8_t *rx,
|
|
|
|
|
uint32_t len, bool end);
|
|
|
|
|
|
2021-11-11 17:42:51 +01:00
|
|
|
uint8_t _verbose; /**< display more message */
|
2021-06-19 17:28:48 +02:00
|
|
|
int16_t _device_idx; /**< device index */
|
|
|
|
|
uint16_t _vid; /**< device Vendor ID */
|
|
|
|
|
uint16_t _pid; /**< device Product ID */
|
|
|
|
|
std::wstring _serial_number; /**< device serial number */
|
|
|
|
|
|
|
|
|
|
hid_device *_dev; /**< hid device used to communicate */
|
|
|
|
|
|
|
|
|
|
unsigned char *_ll_buffer; /**< message buffer */
|
|
|
|
|
unsigned char *_buffer; /**< subset of _ll_buffer */
|
|
|
|
|
int _num_tms; /**< current tms length */
|
2021-10-12 07:52:38 +02:00
|
|
|
int _is_connect; /**< device status ((dis)connected) */
|
2021-06-19 17:28:48 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif // SRC_CMSISDAP_HPP_
|