@@ -421,9 +421,8 @@ int esp_usb_jtag::setClkFreq(uint32_t clkHZ)
421421 return clkHZ;
422422}
423423
424- int esp_usb_jtag::writeTMS (const uint8_t *tms, uint32_t len,
425- __attribute__ ((unused)) bool flush_buffer,
426- __attribute__((unused)) const uint8_t tdi)
424+ int esp_usb_jtag::writeTMS (const uint8_t *tms, uint32_t len, bool flush_buffer,
425+ const uint8_t tdi)
427426{
428427 uint8_t buf[OUT_BUF_SZ];
429428
@@ -437,6 +436,8 @@ int esp_usb_jtag::writeTMS(const uint8_t *tms, uint32_t len,
437436 cerr << " " << std::hex << (int )tms[i];
438437 cerr << endl;
439438
439+ _tdi = tdi & 0x01 ;
440+
440441 uint8_t prev_high_nibble = CMD_FLUSH << 4 ; // for odd length 1st command is flush = nop
441442 uint32_t buffer_idx = 0 ; // reset
442443 uint8_t is_high_nibble = 1 & ~len;
@@ -447,8 +448,8 @@ int esp_usb_jtag::writeTMS(const uint8_t *tms, uint32_t len,
447448 // last byte in buf will have data in both nibbles, no flush
448449 // exec order: high-nibble-first, low-nibble-second
449450 for (uint32_t i = 0 ; i < len; i++) {
450- uint8_t tms_bit = (tms[i >> 3 ] >> (i & 7 )) & 1 ; // get i'th bit from tms
451- uint8_t cmd = CMD_CLK (0 , 0 , tms_bit );
451+ _tms = (tms[i >> 3 ] >> (i & 7 )) & 1 ; // get i'th bit from tms
452+ uint8_t cmd = CMD_CLK (0 , _tdi, _tms );
452453 if (is_high_nibble) { // 1st (high nibble) = data
453454 buf[buffer_idx] = prev_high_nibble = cmd << 4 ;
454455 } else { // low nibble
@@ -458,7 +459,7 @@ int esp_usb_jtag::writeTMS(const uint8_t *tms, uint32_t len,
458459 }
459460 is_high_nibble ^= 1 ;
460461
461- if (buffer_idx >= sizeof (buf) /* buf full*/ || i == len - 1 /* last*/ ) {
462+ if (buffer_idx >= OUT_BUF_SZ /* buf full*/ || i == len - 1 /* last*/ ) {
462463 int ret = xfer (buf, NULL , buffer_idx);
463464 if (ret < 0 ) {
464465 cerr << " writeTMS: usb bulk write failed " << ret << endl;
0 commit comments