@@ -462,7 +462,9 @@ int esp_usb_jtag::writeTMS(const uint8_t *tms, uint32_t len, bool flush_buffer,
462462 if (buffer_idx >= OUT_BUF_SZ /* buf full*/ || i == len - 1 /* last*/ ) {
463463 int ret = xfer (buf, NULL , buffer_idx);
464464 if (ret < 0 ) {
465- cerr << " writeTMS: usb bulk write failed " << ret << endl;
465+ char mess[128 ];
466+ snprintf (mess, 256 , " ESP USB Jtag: writeTMS failed with error %d" , ret);
467+ printError (mess);
466468 return -EXIT_FAILURE;
467469 }
468470 cerr << " tms" << endl;
@@ -479,6 +481,9 @@ int esp_usb_jtag::toggleClk(uint8_t tms, uint8_t tdi, uint32_t len)
479481 if (len == 0 )
480482 return 0 ;
481483
484+ _tms = tms;
485+ _tdi = tdi;
486+
482487 uint8_t prev_high_nibble = CMD_FLUSH << 4 ; // for odd length 1st command is flush = nop
483488 uint32_t buffer_idx = 0 ; // reset
484489 uint8_t is_high_nibble = 1 & ~len;
@@ -488,7 +493,7 @@ int esp_usb_jtag::toggleClk(uint8_t tms, uint8_t tdi, uint32_t len)
488493 // 2nd (low nibble) is data
489494 // last byte in buf will have data in both nibbles, no flush
490495 // exec order: high-nibble-first, low-nibble-second
491- const uint8_t cmd = CMD_CLK (0 , tdi, tms );
496+ const uint8_t cmd = CMD_CLK (0 , _tdi, _tms );
492497 for (uint32_t i = 0 ; i < len; i++) {
493498 // TODO: repeat clocking with CMD_REP
494499 if (is_high_nibble) { // 1st (high nibble) = cmd
@@ -500,7 +505,7 @@ int esp_usb_jtag::toggleClk(uint8_t tms, uint8_t tdi, uint32_t len)
500505 }
501506 is_high_nibble ^= 1 ;
502507
503- if (buffer_idx >= sizeof (buf) /* buf full*/ || i == len - 1 /* last*/ ) {
508+ if (buffer_idx >= OUT_BUF_SZ /* buf full*/ || i == len - 1 /* last*/ ) {
504509 int ret = xfer (buf, NULL , buffer_idx);
505510 if (ret < 0 ) {
506511 char mess[128 ];
0 commit comments