@@ -137,9 +137,11 @@ using namespace std;
137137#define READ_ECDSA_PUBKEY2 0x62 /* This command is used to read the third 128 bits of the ECDSA Public Key. */
138138#define PROG_ECDSA_PUBKEY3 0x63 /* This command is used to program the fourth 128 bits of the ECDSA Public Key. */
139139#define READ_ECDSA_PUBKEY3 0x64 /* This command is used to read the fourth 128 bits of the ECDSA Public Key. */
140+ #define ISC_ENABLE_X 0x74
140141#define ISC_NOOP 0xff /* This command is no operation command (NOOP) or null operation. */
141142#define LSC_DEVICE_CONTROL 0x7D /* Multiple commands. Bit 3: configuration reset */
142143#define PRELOAD_SAMPLE 0x1C /* PRELOAD/SAMPLE jtag opcode. Nexus family has Bscan register 362 bits-long => 45.25 => 46 bytes */
144+ #define BYPASS 0xFF
143145
144146#define PUBKEY_LENGTH_BYTES 64 /* length of the public key (MachXO3D) in bytes */
145147
@@ -817,7 +819,8 @@ bool Lattice::post_flash_access()
817819}
818820void Lattice::reset ()
819821{
820- if (_fpga_family == ECP5_FAMILY || _fpga_family == ECP3_FAMILY)
822+ if (_fpga_family == ECP5_FAMILY || _fpga_family == ECP3_FAMILY
823+ || _fpga_family == NEXUS_FAMILY)
821824 post_flash_access ();
822825 else
823826 printError (" Lattice Reset only tested on ECP5 Family." );
@@ -834,14 +837,24 @@ bool Lattice::clearSRAM()
834837 uint8_t tx_buf[46 ];
835838 memset (tx_buf, 0xff , 46 );
836839 int tx_len;
840+ int tx_bit_len;
837841 if (_fpga_family == NEXUS_FAMILY){
838842 tx_len = 46 ;
843+ tx_bit_len = 362 ;
844+ uint8_t cmd = PRELOAD_SAMPLE;
845+ _jtag->shiftIR (&cmd, NULL , 8 , Jtag::RUN_TEST_IDLE);
846+ _jtag->shiftDR (tx_buf, NULL , tx_bit_len,
847+ Jtag::RUN_TEST_IDLE);
848+ wr_rd (REFRESH, NULL , 0 , NULL , 0 );
849+ _jtag->set_state (Jtag::RUN_TEST_IDLE);
850+ _jtag->toggleClk (2 );
839851 } else {
840852 tx_len = 26 ;
841- }
842- wr_rd (PRELOAD_SAMPLE, tx_buf, tx_len, NULL , 0 );
853+ tx_bit_len = 26 * 8 ;
854+ wr_rd (PRELOAD_SAMPLE, tx_buf, tx_len, NULL , 0 );
843855
844- wr_rd (0xFF , NULL , 0 , NULL , 0 );
856+ wr_rd (BYPASS, NULL , 0 , NULL , 0 );
857+ }
845858
846859 /* ISC Enable 0xC6 */
847860 printInfo (" Enable configuration: " , false );
@@ -1015,15 +1028,20 @@ void Lattice::program(unsigned int offset, bool unprotect_flash)
10151028 */
10161029bool Lattice::EnableISC (uint8_t flash_mode)
10171030{
1031+ uint8_t cmd = ISC_ENABLE;
1032+
10181033 if (_fpga_family == ECP3_FAMILY) {
10191034 wr_rd (ECP3_ISC_ENABLE, NULL , 0 , NULL , 0 );
10201035 _jtag->set_state (Jtag::RUN_TEST_IDLE);
10211036 _jtag->toggleClk (5 , 1 );
10221037 usleep_ecp3 (20000 ); // 0.20s
10231038 return true ;
1039+ } else if (_fpga_family == NEXUS_FAMILY) {
1040+ cmd = (_mode == FLASH_MODE) ? ISC_ENABLE: ISC_ENABLE_X;
1041+ flash_mode = 0 ;
10241042 }
10251043
1026- wr_rd (ISC_ENABLE , &flash_mode, 1 , NULL , 0 );
1044+ wr_rd (cmd , &flash_mode, 1 , NULL , 0 );
10271045
10281046 _jtag->set_state (Jtag::RUN_TEST_IDLE);
10291047 _jtag->toggleClk (1000 );
@@ -1045,7 +1063,14 @@ bool Lattice::DisableISC()
10451063 }
10461064 wr_rd (ISC_DISABLE, NULL , 0 , NULL , 0 );
10471065 _jtag->set_state (Jtag::RUN_TEST_IDLE);
1048- _jtag->toggleClk (1000 );
1066+ if (_fpga_family == NEXUS_FAMILY) {
1067+ _jtag->toggleClk (2 );
1068+ wr_rd (BYPASS, NULL , 0 , NULL , 0 );
1069+ _jtag->set_state (Jtag::RUN_TEST_IDLE);
1070+ _jtag->toggleClk (100 );
1071+ } else {
1072+ _jtag->toggleClk (1000 );
1073+ }
10491074 if (!pollBusyFlag ())
10501075 return false ;
10511076 if (!checkStatus (0 , REG_STATUS_ISC_EN))
0 commit comments