ftdiJtagMPSSE: fix toggleClk to use clk toggle instruction only with compatible device

This commit is contained in:
Gwenhael Goavec-Merou 2020-06-14 15:18:22 +02:00
parent 9a10ac4d48
commit 2cadd21f02
1 changed files with 36 additions and 11 deletions

View File

@ -158,20 +158,45 @@ int FtdiJtagMPSSE::writeTMS(uint8_t *tms, int len, bool flush_buffer)
/* need a WA for ch552 */ /* need a WA for ch552 */
int FtdiJtagMPSSE::toggleClk(uint8_t tms, uint8_t tdi, uint32_t clk_len) int FtdiJtagMPSSE::toggleClk(uint8_t tms, uint8_t tdi, uint32_t clk_len)
{ {
(void) tms;
(void) tdi; (void) tdi;
int ret;
uint32_t len = clk_len;
uint8_t buf[] = {static_cast<uint8_t>(0x8e), /* clk ouput without data xfer is only supported
0, 0}; * with 2232H, 4242H & 232H
int xfer_len = clk_len; */
while (xfer_len > 0) {
int xfer = (xfer_len > 8) ? 8 : xfer_len; if (_ftdi->type == TYPE_2232H || _ftdi->type == TYPE_4232H ||
buf[1] = xfer -1; _ftdi->type == TYPE_232H) {
mpsse_store(buf, 2); uint8_t buf[] = {static_cast<uint8_t>(0x8f), 0, 0};
mpsse_write(); if (clk_len > 8) {
xfer_len -= xfer; buf[1] = ((len / 8) ) & 0xff;
buf[2] = ((len / 8) >> 8) & 0xff;
mpsse_store(buf, 3);
ret = mpsse_write();
if (ret < 0)
return ret;
len %= 8;
}
if (len > 0) {
buf[0] = 0x8E;
buf[1] = len - 1;
mpsse_store(buf, 2);
mpsse_write();
if (ret < 0)
return ret;
}
ret = clk_len;
} else {
printf("ftdi type : %d\n", _ftdi->type);
int byteLen = (len+7)/8;
uint8_t buf_tms[byteLen];
memset(buf_tms, (tms) ? 0xff : 0x00, byteLen);
ret = writeTMS(buf_tms, len, true);
} }
return 0;
return ret;
} }
int FtdiJtagMPSSE::flush() int FtdiJtagMPSSE::flush()