The following setup was used for Basys2 board with an external FTDI-based JTAG adapter. Read the previous posts to get familiar with setup.
Specifying USERCODE
User code register provides bit stream identification and a type of version control. To write a user code into a bit stream in Xilinx ISE, go to "Implementation" -> "Design" and right-click on "Generate Programming File". In the popped up window specify your 32-bit user code in hexadecimal format:
For example, I set it to 0xADEAFBEE. Now generate the *.bit file in Xilinx ISE and analyze its header using bitparse utility, which is a part of xc3sprog:
|
1
2
3
4
5
6
|
[johndoe@ArchLinux]% bitparse Sliding_LED.bit
Created from NCD file: Sliding_LED.ncd;UserID=0xADEAFBEE
Target device: 3s100ecp132
Created: 2017/01/26 17:53:30
Bitstream length: 581344 bits 72668 bytes(0x011bdc)
64-bit sum: 18460515
|
UserID field tells that its value is embedded into the bit stream and will be written to the USERCODE during configuration.
Now program the FPGA using xc3sprog:
|
1
2
3
4
5
6
7
8
9
|
[johndoe@ArchLinux]% xc3sprog -c ft232h Sliding_LED.bit
XC3SPROG (c) 2004-2011 xc3sprog project $Rev: 785 $ OS: Linux
Free software: If you contribute nothing, expect nothing!
Feedback on success/failure/enhancement requests:
http://sourceforge.net/mail/?group_id=170565
Check Sourceforge for updates:
http://sourceforge.net/projects/xc3sprog/develop
Using Libftdi,
|
Reading USERCODE in UrJTAG
While your program is running on the FPGA, run UrJTAG:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
[johndoe@ArchLinux]% jtag
UrJTAG 0.10 #2052
Copyright (C) 2002, 2003 ETC s.r.o.
Copyright (C) 2007, 2008, 2009 Kolja Waschk and the respective authors
UrJTAG is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
There is absolutely no warranty for UrJTAG.
warning: UrJTAG may damage your hardware!
Type "quit" to exit, "help" for help.
jtag> cable ft2232 vid=0x0403 pid=0x6014
Connected to libftd2xx driver.
jtag> bsdl path Basys2_BSDL
jtag> detect
IR length: 14
Chain length: 2
Device Id: 11110101000001000101000010010011 (0xF5045093)
Filename: Basys2_BSDL/xcf02s.bsd
Device Id: 00010001110000010000000010010011 (0x11C10093)
Filename: Basys2_BSDL/xc3s100e_cp132.bsd
jtag> print chain
No. Manufacturer Part Stepping Instruction Register
-------------------------------------------------------------------------------------------------------------------
0 XCF02S BYPASS BYPASS
* 1 XC3S100E_CP132 BYPASS BYPASS
jtag> instruction USERCODE
jtag> shift ir
jtag> shift dr
jtag> dr
10101101111010101111101111101110 (0xADEAFBEE)
jtag>
|
The USERCODE instruction selects USERCODE register as data register. Shifting 32 bits into the data register will yield our user code.
Reading USERCODE in OpenOCD
While your program is running on the FPGA, start OpenOCD server:
|
1
2
3
4
5
6
7
8
9
10
11
|
[johndoe@ArchLinux]% openocd -f OpenOCD/FT232H.cfg -f OpenOCD/Basys2.cfg
Open On-Chip Debugger 0.10.0
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
adapter speed: 6000 kHz
xc3s_get_dna
Info : clock speed 6000 kHz
Info : JTAG tap: prom.tap tap/device found: 0xf5045093 (mfg: 0x049 (Xilinx), part: 0x5045, ver: 0xf)
Info : JTAG tap: spartan3e.tap tap/device found: 0x11c10093 (mfg: 0x049 (Xilinx), part: 0x1c10, ver: 0x1)
Warn : gdb services need one or more targets defined
|
In other terminal, connect as a client:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
[johndoe@ArchLinux]% telnet localhost 4444
Trying ::1...
Connection failed: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Open On-Chip Debugger
> scan_chain
TapName Enabled IdCode Expected IrLen IrCap IrMask
-- ------------------- -------- ---------- ---------- ----- ----- ------
0 prom.tap Y 0xf5045093 0xf5045093 8 0x01 0x03
1 spartan3e.tap Y 0x11c10093 0x11c10093 6 0x01 0x03
> irscan spartan3e.tap 0x08 # USERCODE instruction opcode
> drscan spartan3e.tap 0x20 0 # 32 in hexadecimal, state 0
ADEAFBEE
>
|
The user code is successfully retrieved.
