Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
trabucayre committed Oct 27, 2023
1 parent 7a034cd commit 6ef5e13
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 9 deletions.
7 changes: 4 additions & 3 deletions src/ftdiJtagMPSSE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

using namespace std;

#define DEBUG 0
#define DEBUG 1

#ifdef DEBUG
#define display(...) \
Expand All @@ -40,6 +40,7 @@ FtdiJtagMPSSE::FtdiJtagMPSSE(const cable_t &cable,
_tdo_pos(0)
{
init_internal(cable.config);
_verbose = true;
}

FtdiJtagMPSSE::~FtdiJtagMPSSE()
Expand Down Expand Up @@ -235,8 +236,8 @@ int FtdiJtagMPSSE::writeTDI(const uint8_t *tdi, uint8_t *tdo, uint32_t len, bool
static_cast<unsigned char>((xfer - 1) & 0xff), // low
static_cast<unsigned char>((((xfer - 1) >> 8) & 0xff))}; // high

display("%s len : %d %d %d %d\n", __func__, len, real_len, nb_byte,
nb_bit);
display("%s len : %d %d %d %d last: %d\n", __func__, len, real_len, nb_byte,
nb_bit, last);

if ((nb_byte + _num + 3) > _buffer_size)
mpsse_write();
Expand Down
13 changes: 12 additions & 1 deletion src/ftdipp_mpsse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

using namespace std;

//#define DEBUG 1
#define DEBUG 1
#define display(...) \
do { if (_verbose) fprintf(stdout, __VA_ARGS__);}while(0)

Expand Down Expand Up @@ -488,6 +488,17 @@ int FTDIpp_MPSSE::mpsse_write()

#ifdef DEBUG
display("%s %d\n", __func__, _num);
printf("\t");
int col = 0;
for (size_t i = 0; i < _num; i++) {
col++;
if (col == 10) {
col = 0;
printf("\n\t");
}
printf("%02x ", _buffer[i]);
}
printf("\n");
#endif

if ((ret = ftdi_write_data(_ftdi, _buffer, _num)) != _num) {
Expand Down
34 changes: 29 additions & 5 deletions src/gowin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ void Gowin::program(unsigned int offset, bool unprotect_flash)
programFlash();
} else { /* write bitstream into external flash */
_jtag->setClkFreq(10000000);
_jtag->setClkFreq(1000000);

if (!EnableCfg())
throw std::runtime_error("Error: fail to enable configuration");
Expand All @@ -286,6 +287,7 @@ void Gowin::program(unsigned int offset, bool unprotect_flash)
wr_rd(NOOP, NULL, 0, NULL, 0);
wr_rd(0x16, NULL, 0, NULL, 0);
wr_rd(0x00, NULL, 0, NULL, 0);
_jtag->set_state(Jtag::TEST_LOGIC_RESET);
/* save current read/write edge cfg before switching to SPI mode0
* (rising edge: read / falling edge: write)
*/
Expand Down Expand Up @@ -870,34 +872,56 @@ int Gowin::spi_put_gw5a(const uint8_t *tx, uint8_t *rx, uint32_t len)
{
uint8_t jtx[len];
uint8_t jrx[len];
if (rx)
len++;
uint8_t cmd = 0;
int ret = 0;
len--; // extract first byte + sent rest
for (ret = 0; ret < 5; ret++)
printf("\n");
//if (rx)
// len++;
if (tx != NULL) {
cmd = FsParser::reverseByte(tx[0]); // extract first byte.

/* SPI: MSB, JTAG: LSB -> reverse Bytes */
printf("cmd: %02x(%02x)\n", cmd, tx[0]);
for (uint32_t i = 0; i < len; i++)
printf("write %d 0x%02x\n", i, tx[i]);
for (uint32_t i = 0; i < len; i++)
jtx[i] = FsParser::reverseByte(tx[i]);
jtx[i] = FsParser::reverseByte(tx[i + 1]);
}
if (tx[0] == 0x9F) {
printf("wait\n");
_jtag->setClkFreq(500e3);
getchar();
}
/* set TMS/CS low by moving to a state where loop is
* with TMS == 0
*/
_jtag->set_state(Jtag::RUN_TEST_IDLE);
_jtag->set_state(Jtag::RUN_TEST_IDLE, cmd & 0x01);
//_jtag->flushTMS(true);
cmd >>= 1;
/* write/read the sequence. Force set to 0 to manage state here */
int ret = _jtag->read_write(jtx, (rx) ? jrx : NULL, 8 * len, 0);
ret = _jtag->read_write(&cmd, NULL, 7, 0);
ret = _jtag->read_write(jtx, (rx) ? jrx : NULL, 8 * len, 0);
if (ret != 0)
return -1;
/* set TMS/CS high by moving to a state where loop is
* with TMS == 1
*/
_jtag->set_state(Jtag::TEST_LOGIC_RESET);
_jtag->flushTMS(true);
if (rx) {
/* again data must be reversed due to JTAG LSB */
for (uint32_t i = 0; i < len; i++)
printf("read %d 0x%02x -> 0x%02x\n", i, jrx[i], FsParser::reverseByte(jrx[i]));
for (uint32_t i=0; i < len; i++)
rx[i] = FsParser::reverseByte(jrx[i]);
}
for (ret = 0; ret < 5; ret++)
printf("\n");
if (tx[0] == 0x9f)
sleep(1);
//throw std::runtime_error("nothing");
return 0;
}

Expand Down

0 comments on commit 6ef5e13

Please sign in to comment.