mrjimenez / JTAG

JTAG library for Arduino
BSD 2-Clause "Simplified" License
123 stars 22 forks source link

Error in programming process #10

Open lcesarfs opened 11 months ago

lcesarfs commented 11 months ago

Hi, I have trying to use this code/library to program a Lattice CPLD. But unfortunately, I'm not have success on that. I also tried to program the Xilinx CoolRunner II, and I'm having the same problem. This screenshot is the result of a erase.svf file.

Im not sure if I can use this code for Lattice CPLD or another Xilinx CPLD, as I'm trying to use.

image

mrjimenez commented 11 months ago

Hi Luiz,

It seems like you are sending a SVF file instead of a XSVF file. The python script only understands the XSVF format.

Regards, Marcelo.

lcesarfs commented 10 months ago

image

Hi Marcelo, thanks for your answer. I tried with an XSVF format, and I have not success as the same before. Adding more information, I'm using a ESP32 board to act an Arduino, I don't think that this is the problem.

I'm trying to have this working on my CoolRunner II devboard, but my final goal is having this working for lattice CPLDs, do you think that I can get something in this way?

mrjimenez commented 10 months ago

Hi Luiz,

Using an ESP32 should be just fine.

I still claim that what is printed (prog.xsvf?) is not XSVF, since XSVF is a binary format, and from the dump in your message, I can see that text is beeing sent.

In this project, there are some SVF and XSVF examples. Please look at extras/xsvf and subfolders. Also, there is a disassembler for XSVF written in python 2.something.

If possible, try to use another tool to generate XSVF. If you input a real XSVF file, things should work. I have used it with a coolrunner CPLD and with a Spartan3e FPGA. Bigger stuff like bigger FPGAs may require bigger buffers in the software.

Regards, Marcelo.

lcesarfs commented 10 months ago

First, thank you Marcelo for your time. Could you show me how do you know that I'm not using a correct XSVF file, based on my printed screen. I did not got it. To create my XSVF file Im using the tool ISE iMPACT. I did the disassembler process on the example \extras\xsvf\XC2C64A\blank_check.xsvf and also in one blanck check generated by my tool/process and they are pretty similar. Probably I'm missing something that I cannot see it.

mrjimenez commented 10 months ago

Hi Luiz,

This is strange, because I have also used the ISE Impact tool.

For example, the line ('Unrecognized line:', 'ets Jun 8 2016 00:22:57' is showing text. Take a look inside the file prog.xsvf to see if this line is there. Or attach the file in this post so that I can have a look at it.

lcesarfs commented 10 months ago

Sure thing, please take a look at the file. I desassembled the prog.xsvf in order to try to find any text, I just found ", ".

prog.zip

lcesarfs commented 10 months ago

Hi Marcelo, I notice that you update something related python version. I was previously using python2, because I got something that lead me to do that in our previous issues.

Now I tried to use the python3 and I'm getting new errors. (I got the last version of your code today) C:\Users\luizcsil>python3 C:\CPLDProgram\JTAG-master\JTAG-master\extras\python\xsvf -p COM3 C:\CPLDProgram\JTAG-master\JTAG-master\extras\xsvf\all\idcode_simpler.xsvf Traceback (most recent call last): File "C:\CPLDProgram\JTAG-master\JTAG-master\extras\python\xsvf", line 57, in main() File "C:\CPLDProgram\JTAG-master\JTAG-master\extras\python\xsvf", line 46, in main u.upload_all_files(args.fileName) File "C:\CPLDProgram\JTAG-master\JTAG-master\extras\python\Uploader.py", line 149, in upload_all_files ok = self.upload_one_file(fd) ^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\CPLDProgram\JTAG-master\JTAG-master\extras\python\Uploader.py", line 143, in upload_one_file line.translate(Uploader._translate_str)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TypeError: a bytes-like object is required, not 'str'

mrjimenez commented 10 months ago

Hi Luiz,

No, stick to the other version. I will do an update to work with python3, but it is still not ok. I'll send another message to you with my results, I am in another computer right now.

mrjimenez commented 10 months ago

Hi Luiz,

I will have to port things to python3 to test, I am having some difficulties to find stuff in my distro. Sorry for the mess up in the repo, I'll soon fix it.

Ok, the file prog.xsvf is definitely binary. I did

./xsvf -c disasm prog.xsvf > prog.xsvf.s

And the result is here prog.xsvf.s.zip

Looks ok to me.

What I still don't understand is the sequence of ('Unrecognized line: ...'s that shows in your output. Did you upload the JTAGTest.ino script to your ESP32? Or maybe it could be related to the reboot of the system. You can try to comment Uploader.py:64 (reset_arduino()) to see if it goes on.

mrjimenez commented 10 months ago

Without the hardware connected to the Arduino, I am getting this:

$ ./xsvf -p /dev/ttyACM0 prog.xsvf
File: /home/mroberto/sketchbook/arduino/libraries/JTAG/extras/python/prog.xsvf
Ready to send 90065 bytes.
Sent:       63 bytes,    90002 remainingIMPORTANT: DR check failed!
IMPORTANT: *****************************
IMPORTANT: Failure at instruction #   10
IMPORTANT: *****************************
IMPORTANT: Last TDO: FF FF FF FF/32 bits
IMPORTANT: Processed 10 instructions.
IMPORTANT: Checksum:  0x83/37.
IMPORTANT: Sum: 0x0000067D/37.
Quit: DR check failed (-101).
  Expected checksum:  0x05/90065.
  Expected sum: 0x00000CFB/90065.
Elapsed time: 0.03 seconds.

The disassembled prog.xsvf code gives me this:

07 00                       XREPEAT 0
13 00                       XENDIR RUN_TEST_IDLE
14 00                       XENDDR RUN_TEST_IDLE
12 00                       XSTATE TEST_LOGIC_RESET
12 01                       XSTATE RUN_TEST_IDLE
02 08 01                    XSIR 8 01
08 00 00 00 20              XSDRSIZE 32
01 0F FF 8F FF              XTDOMASK
                                0F FF 8F FF
04 00 00 00 00              XRUNTEST 0
09 00 00 00 00 F6 D4 F0     XSDRTDO
93                              00 00 00 00,
                                F6 D4 F0 93
02 08 FF                    XSIR 8 FF
02 08 01                    XSIR 8 01
09 00 00 00 00 F6 D4 F0     XSDRTDO
93                              00 00 00 00,
                                F6 D4 F0 93
02 08 FF                    XSIR 8 FF
02 08 E8                    XSIR 8 E8
17 01 01 00 00 00 C8        XWAIT RUN_TEST_IDLE RUN_TEST_IDLE 200
...

Instruction number 10 is XSDRTDO 00 00 00 00, F6 D4 F0 93. The error is expected, since I have nothing connected, so the last TDO read is FF FF FF FF, usual when there is nothing connected, not the expected value and the test fails.

mrjimenez commented 10 months ago

Hum, I have a theory. The first unrecognized messages are the boot messages of the ESP32. Then the program works and processes 10 instructions, but reads an invalid (not expected) TDO and fails. Maybe check the electrical connections, it has read an all zeroes TDO in your case. Or try to run the extras/xsvf/all/idcode_simpler.xsvf file to see if it works.

lcesarfs commented 10 months ago

I see Marcelo, I got your new updates and now I'm getting error running in python 2.7 but not using 3.11 (it fails the first try always, but after start to work.).

error python2.7:

C:\Users\luizcsil>python C:\CPLDProgram\JTAG-master\JTAG-master\extras\python\xsvf -p COM3 C:\CPLDProgram\JTAG-master\JTAG-master\extras\xsvf\all\idcode_simpler.xsvf Traceback (most recent call last): File "C:\CPLDProgram\JTAG-master\JTAG-master\extras\python\xsvf", line 8, in import Uploader File "C:\CPLDProgram\JTAG-master\JTAG-master\extras\python\Uploader.py", line 114 end="", ^ SyntaxError: invalid syntax

python 3.11:

C:\Users\luizcsil>python3 C:\CPLDProgram\JTAG-master\JTAG-master\extras\python\xsvf -p COM3 C:\CPLDProgram\JTAG-master\JTAG-master\extras\xsvf\all\idcode_simpler.xsvf Unrecognized line: b'ets Jun 8 2016 00:22:57' Unrecognized line: b'rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)' Unrecognized line: b'configsip: 0, SPIWP:0xee' Unrecognized line: b'clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00' Unrecognized line: b'mode:DIO, clock div:1' Unrecognized line: b'load:0x3fff0030,len:1184' Unrecognized line: b'load:0x40078000,len:13220' Unrecognized line: b'ho 0 tail 12 room 4' Unrecognized line: b'load:0x40080400,len:3028' Unrecognized line: b'entry 0x400805e4' File: C:\CPLDProgram\JTAG-master\JTAG-master\extras\xsvf\all\idcode_simpler.xsvf Ready to send 18 bytes. Sent: 18 bytes, 0 remainingIMPORTANT: **** IMPORTANT: Success! IMPORTANT: **** IMPORTANT: Last TDO: 00 00 00 00/32 bits IMPORTANT: Processed 5 instructions. IMPORTANT: Checksum: 0xC2/18. IMPORTANT: Sum: 0x0000003E/18. Quit: No error (0). Expected checksum: 0xC2/18. Expected sum: 0x0000003E/18. Elapsed time: 0.02 seconds.

Therefore when I try to use my program file I got the error:

C:\Users\luizcsil>python3 C:\CPLDProgram\JTAG-master\JTAG-master\extras\python\xsvf -p COM3 C:\CPLDProgram\prog.xsvf Unrecognized line: b'ets Jun 8 2016 00:22:57' Unrecognized line: b'rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)' Unrecognized line: b'configsip: 0, SPIWP:0xee' Unrecognized line: b'clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00' Unrecognized line: b'mode:DIO, clock div:1' Unrecognized line: b'load:0x3fff0030,len:1184' Unrecognized line: b'load:0x40078000,len:13220' Unrecognized line: b'ho 0 tail 12 room 4' Unrecognized line: b'load:0x40080400,len:3028' Unrecognized line: b'entry 0x400805e4' File: C:\CPLDProgram\prog.xsvf Ready to send 90065 bytes. Sent: 63 bytes, 90002 remainingIMPORTANT: DR check failed! IMPORTANT: IMPORTANT: Failure at instruction # 10 IMPORTANT: IMPORTANT: Last TDO: 00 00 00 00/32 bits IMPORTANT: Processed 10 instructions. IMPORTANT: Checksum: 0x83/37. IMPORTANT: Sum: 0x0000067D/37. Quit: DR check failed (-101). Expected checksum: 0x05/90065. Expected sum: 0x00000CFB/90065. Elapsed time: 0.03 seconds.

Bellow I put an image that shows the lines, as you can see the TDI and TDO are always in 0. That also happens when I try use the xsvf\all\idcode_simpler.xsvf. When I use the xsvf\all\idcode_simpler.xsvf does not matter if the wires are connected to CPLD board or not, the results its always the same, success.

Note: I created a project to validate my ESP pins, they are working well.

this is the change that I did on the Arduino side. PlayXSVFJTAGArduino p(Serial, SERIAL_RX_BUFFER_SIZE, 21, 19, 18, 5, 32);

image

mrjimenez commented 10 months ago

Hi Luiz,

If you use the latest git files, it will only work with python 3. I guess it was about time we do an update, right?

So, my theory seems to be right. The first messages the python module receives are ESP32 boot messages. As soon as it recognizes the command to start the upload, it sends idcode_simpler.xsvf. This file has a very simple logic and does not test the TDO against a mask, so whatever is output is shown in the Last TDO, and this should be the ID of the part (chip).

It is strange that the output is always zero. The ID should have been output. If you are sure that the part is working, i.e., if the part is functioning with another programmer, then you have to check the electrical connections.

But it is even more strange that the TDI is zero. Most likely you may need to change in the file JTAGTest.ino, the line PlayXSVFJTAGArduino p(Serial, SERIAL_RX_BUFFER_SIZE, 8, 9, 10, 11, 12);, the numbers 8, 9, 10, 11, 12 to correspond to the right pins in the ESP32. The sequence is TMS, TDI, TDO, TCK, VREF. This is most likely the cause of the problem.

Best regards, Marcelo.

lcesarfs commented 10 months ago

Hi Marcelo, Yes, I'm sure that my target its working properly, I have a JTAG from Xilinx that works, and I can upload the .jed file.

As I told you, I already change that line to work in my ESP32:PlayXSVFJTAGArduino p(Serial, SERIAL_RX_BUFFER_SIZE, 21, 19, 18, 5, 32); . In order to validate my chosen pins (21, 19, 18, 5, 32) I used your project (JTAGTest.ino) did some changes and made them blink and that work.

So far, I don't have a clue how to get this working.

Kind Regards, Luiz Cesar

mrjimenez commented 10 months ago

Hi Luiz,

this is the change that I did on the Arduino side. PlayXSVFJTAGArduino p(Serial, SERIAL_RX_BUFFER_SIZE, 21, 19, 18, 5, 32);

Sorry, I missed that in your message, I had concentrated on the image. The thing is, we can see some activity in TMS, TDI and TCK, but none in TDO, which remains flat at a high level. Which is also odd because the program says: Last TDO: 00 00 00 00/32 bits which is a sequence of all zeroes, which is not in accordance with what we see in the image. Maybe try to zoom at the places that TCK is switching to see if you see some movement in TDO.

The project has mostly been tested with an arduino, have you tried to test it with one, instead of the ESP32?

Regards, Marcelo.