Skip to content

Commit

Permalink
Merge pull request #410 from pu-cc/gatemate-chain-fix
Browse files Browse the repository at this point in the history
gatemate: fix configuration byte alignment in jtag chains
  • Loading branch information
trabucayre authored Dec 27, 2023
2 parents a3745bc + 001f20c commit c51dbcb
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
30 changes: 27 additions & 3 deletions src/colognechip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "colognechip.hpp"

#include <memory>
#include <string.h>

#define JTAG_CONFIGURE 0x06
#define JTAG_SPI_BYPASS 0x05
Expand Down Expand Up @@ -279,19 +280,42 @@ void CologneChip::programJTAG_sram(const uint8_t *data, int length)

ProgressBar progress("Load SRAM via JTAG", length, 50, _quiet);

/* make sure to only send multiples of 8 bits */
int bits_before = _jtag->get_devices_list().size() - _jtag->get_device_index() - 1;
if (bits_before > 0) {
int n = 8 - (bits_before % 8);
uint8_t tx[n];
memset(tx, 0x00, n);
_jtag->shiftDR(tx, NULL, n, Jtag::SHIFT_DR);
}

/* the bypass register defaults to '0'.
* in order to generate a proper 'nop' command (0x00, 0xFF), send a
* sequence of zeros instead of ones.
*/
int bits_after = _jtag->get_device_index();
if (bits_after > 0) {
int n = (bits_after + 7) / 8;
uint8_t tx[n];
memset(tx, 0x00, n);
_jtag->shiftDR(tx, NULL, 8-bits_after, Jtag::SHIFT_DR);
}

Jtag::tapState_t next_state = Jtag::SHIFT_DR;
for (int i = 0; i < length; i += size) {
if (length < i + size)
if (length < i + size) {
size = length-i;
next_state = Jtag::RUN_TEST_IDLE;
}

for (int ii = 0; ii < size; ii++)
tmp[ii] = data[i+ii];

_jtag->shiftDR(tmp, NULL, size*8, Jtag::SHIFT_DR);
_jtag->shiftDR(tmp, NULL, size*8, next_state);
progress.display(i);
}

progress.done();
_jtag->set_state(Jtag::RUN_TEST_IDLE);

if (_ftdi_jtag) {
waitCfgDone();
Expand Down
6 changes: 6 additions & 0 deletions src/jtag.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ class Jtag {
*/
std::vector<int> get_devices_list() {return _devices_list;}

/*!
* \brief return device index in list
* \return device index
*/
int get_device_index() {return device_index;}

/*!
* \brief return current selected device idcode
* \return device idcode
Expand Down

0 comments on commit c51dbcb

Please sign in to comment.