📜 ⬆️ ⬇️

MIPSfpga and in-circuit debugging

Supplied as part of the MIPSfpga package, the documentation, software, and configuration files assume the use of Bus Bluster as a hardware debugger. The article contains instructions for using for this purpose virtually any USB-UART adapter built on an FTDI chip with support for MPSSE (FT232H, FT2232H, FT4232H, FT2232D). Briefly describes the integration of the Visual Studio Code development environment and the GNU GDB debugger.


All configuration files described in the article, as well as part of the documentation are available on github .


System elements


image


MIPSfpga is the industrial processor core of the MIPS microAptiv, the source codes of which are available under academic licenses [ L1 ]. MIPSfpga-plus is a system-on-a-chip design based on the MIPSfpga [ L2 ] core. In my case, the system is deployed on a Terasic DE10-Lite board with an Altera MAX10 FPGA on board [ L3 ].


The adapter (programmer, debugger) between the MIPSfpga-plus and PC is the Pinboard II [ L4 ] board with the FT22I [ D1 ] chip from FTDI [ L5 ]. Physically, the boards are interconnected by the UART and JTAG [ L6 ] interfaces. The first is used for console access to the system being debugged. The second is the basic debugging interface using EJTAG [ D7 ]. The difference between JTAG and EJTAG is very well shown in [ L7 ].


The key technology that greatly simplifies the construction of programmers and debuggers based on FTDI chips is the Multi-Protocol Synchronous Serial Engine (MPSSE) [ D2 , D3 , D4 ]. MPSSE support is a crucial point for the configuration described in the article. You can get similar results only on USB adapters based on the following FTDI chips: FT232H, FT2232H, FT4232H, FT2232D.


On the PC side, the interaction with the USB board is carried out: for the UART channel — using the usual FTDI drivers and any terminal program; for the MPSSE channel, the WinUSB driver is used (the work was done on a Windows-based system).


For compilation, the Codescape GNU Tools [ D9 ] is used, for debugging, the traditional bundle of OpenOCD [ L8 , D8 ] and GNU GDB [ D5 ]. These software packages are included with the Codescape MIPS SDK [ L12 ]. Their interaction with each other is carried out using the gdbserver [ L9 ] protocol.


Visual Studio Code (VSCode) [ L10 ] with the vscode-cpptools extension [ L11 ] installed is used as a GUI for debugging. Due to the fact that this extension is focused on high-level development (C / C ++), the interface lacks such views as viewing assembler instructions, viewing memory, direct access to registers.


Briefly about MPSSE and FTDI


MPSSE is a hardware-implemented set of primitive functions that greatly simplify the implementation of serial interfaces (SPI, I2C, JTAG). For example: send N bits on the clock edge, read M bits on the decay, set the X output to zero, etc.


Until 2014, Chinese on a substantial scale riveted counterfeit FTDI chips, for this reason USB-UART converters based on them were one of the most common on sites like ebay or aliexpress. And the developers were happy to build their solutions on them, to take at least the same support from OpenOCD. The list of USB adapter adapters manufactured by FTDI is shown below, with support for MPSSE - marked in color.


In 2014, FTDI releases updated drivers that refuse to work with counterfeit devices [ L13 , L14 ]. The number of offers for these USB-UART adapters has since declined somewhat, but they still remain one of the most common developers on hand.


Even FTDI, despite the excellent chips, sometimes blamed for the quality of software for them. Maybe it's my hands crooked, but Having suffered a lot from working with libMPSSE from under .NET, I wrote my analogue of this library in C # [ L15 ].


If any reader knows an adequate alternative for FTDI chips, an inexpensive and yet correctly supported OpenOCD, I will be grateful for the information.


image


USB module diagram


Below is a fragment of the Pinboard II debug board circuit, in your case the module circuit may be different. The main determining parameter for us is the ability to directly access the ports of the chip: one free MPSSE channel (for TCK, TDI, TDO, TMS) + 1 GPIO output for the reset signal (SRSTn) is enough for operation. For the second channel of the chip, the MPSSE functionality is not mandatory, and it is convenient to use it for UART interaction with the system being debugged.


The outputs of the FTDI chip are directly connected to the FPGA ports. Strictly speaking, this is a violation of [ D7 , D6 ], since it is assumed that there should be installed pull-up, pull-down or series-connected resistors. Everything works without them for me: carefully check the setting of the ports for input-output, check the maximum current limit on the FPGA ports involved for EJTAG.


The voltage at the terminals of the adapter is set to 3.3V. In the case of Pinboard II, a separate jumper (VCCIO_PWR_SEL) is provided for selecting this voltage. For other boards, be guided by their schemes and FPGA settings, in some cases it may be necessary to refine the adapter (which is simpler) and / or the level conversion circuit [ L16 ] (which is more difficult and can lead to interference or reduced speed).
image


Typical EJTAG connection


A typical wiring diagram for the EJTAG interface is obtained from [ D6 ]. The optional DINT and TRSTn inputs are not used in this configuration. Compliance of the rest is given in the table.
image


Table of connecting the USB module to the FPGA


image


Configuration files ( on github )


mipsfpga_ftdi.cfg
# # OpenOCD config for using FT2232D that is directly connected # to FPGA as MIPSfpga EJTAG debugger # Any FTDI USB IC with MPSSE support (required) can be used # # 2017, Stanislav Zhelnio # # ########################################################## # interface part # ########################################################## # interface, transport and channel setup # (use zadig to install WinUSB driver instead of FTDI one) interface ftdi transport select jtag ftdi_channel 0 ftdi_vid_pid 0x0403 0x6010 # ftdi MPSSE initial value and direction # for detailed description of Magic Numbers look at # connection table and FTDI AppNote AN_108: # chapter 2.1 Data bit Definition ftdi_layout_init 0x0018 0x081b # special signals # described in OpenOCD User's Guide: # chapter 8.2 Interface Drivers (ftdi) # chapter 9 Reset Configuration # nTRST is not used ftdi_layout_signal nSRST -data 0x0010 -oe 0x0020 ftdi_layout_signal LED -ndata 0x0800 -oe 0x0800 # speed setup # decrease when errors adapter_khz 10000 # ########################################################## # target part # ########################################################## # reset delays # described in OpenOCD User's Guide: # chapter 9 Reset Configuration adapter_nsrst_delay 100 jtag_ntrst_delay 100 # reset sygnal config # nSRST is directly connected to MIPSfpga (~SI_ColdReset) wire reset_config srst_only separate srst_nogate srst_push_pull # To check connection and scan EJTAG chain uncomment this # and comment all that is bellow then 'shutdown' command. # Use IDCODE value to detect connection errors: # IDCODE that was set in RTL config should be identical # to -expected-id result in 'shutdown' output. # The IDCODE structure is described in EJTAG Specification: # chapter 6.5.1 Device Identification (ID) Register #shutdown # tap connector and target creation # change -expected-id to your IDCODE value # for other arguments see at OpenOCD User's Guide jtag newtap auto0 tap -expected-id 0x000f1005 -irlen 5 -ircapture 0x1 -irmask 0x1f target create auto0.tap mips_mAptiv -endian little -chain-position auto0.tap # tap configuration # change params acording to compile and memory settings # for details see at OpenOCD User's Guide auto0.tap configure -work-area-phys 0xa0003ff00 -work-area-size 256 -work-area-backup 0 # EJTAG scan perion mips32 scan_delay 20000 # run the debugger process and wait for gdb connection init 


c_cpp_properties.json
 { "configurations": [ { "name": "Mac", "includePath": [ "/usr/include", "/usr/local/include" ], "browse": { "limitSymbolsToIncludedHeaders": true, "databaseFilename": "" } }, { "name": "Linux", "includePath": [ "/usr/include", "/usr/local/include" ], "browse": { "limitSymbolsToIncludedHeaders": true, "databaseFilename": "" } }, { "name": "Win32", "includePath": [ "C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/include/*" ], "browse": { "limitSymbolsToIncludedHeaders": true, "databaseFilename": "" } }, { "name": "mips-mti-elf", "includePath": [ "D:/Codescape/Toolchains/mips-mti-elf/2016.05-03/lib/gcc/mips-mti-elf/4.9.2/include/*" ], "browse": { "limitSymbolsToIncludedHeaders": true, "databaseFilename": "" } } ] } 


launch.json
 { "version": "0.2.0", "configurations": [ { "name": "MIPS Load", "type": "cppdbg", "request": "launch", "program": "${fileDirname}/program.elf", "cwd": "${fileDirname}", "miDebuggerPath": "d:/CODESC~1/TOOLCH~1/mips-mti-elf/2016.05-03/bin/mips-mti-elf-gdb.exe", "setupCommands": [ {"text": "file 'D:/mipsfpga-plus/programs/00_counter/program.elf'"}, {"text": "target remote localhost:3333"}, {"text": "set endian little"}, {"text": "monitor reset halt"}, {"text": "load"}, {"text": "br main"}, {"text": "monitor continue"} ], "customLaunchSetupCommands": [], "launchCompleteCommand": "None", "targetArchitecture": "mips" //Uncomment this to debug //,"logging": { "engineLogging": true } //or this for verbose debug //,"logging": { "engineLogging": true, "trace": true, "traceResponse": true } }, { "name": "MIPS Attach", "type": "cppdbg", "request": "launch", "program": "${fileDirname}/program.elf", "cwd": "${fileDirname}", "miDebuggerPath": "d:/CODESC~1/TOOLCH~1/mips-mti-elf/2015.06-05/bin/mips-mti-elf-gdb.exe", "setupCommands": [ {"text": "file 'D:/mipsfpga-plus/programs/00_counter/program.elf'"}, {"text": "target remote localhost:3333"}, {"text": "set endian little"} ], "customLaunchSetupCommands": [], "launchCompleteCommand": "None", "targetArchitecture": "mips" //Uncomment this to debug //,"logging": { "engineLogging": true } //or this for verbose debug //,"logging": { "engineLogging": true, "trace": true, "traceResponse": true } } ] } 


Primary setup



Settings on the MIPSFpga side



 assign EJ_DINT = 1'b0; assign EJ_TRST_N = 1'b1; 

Compilation settings



Connection test



Debug in console mode



VSCode Setup



Debugging in vscode



image


Thanks


The author is grateful to the team of translators from David Harris and Sarah Harris, Digital Circuit Design and Computer Architecture , by Imagination Technologies for the academic license for a modern processor core, personally Yuri Panchul YuriPanchul for his work on promoting MIPSfpga, and DIHALT for a debugging fee, which is which year does not leave the surface of my table.


Links


[L1] - How to start working with MIPSfpga ;
[L2] - MIPSfpga-plus project on github ;
[L3] - Terasic DE10-Lite FPGA board ;
[L4] - Pinboard II debug board ;
[L5] - FTDI website ;
[L6] - JTAG interface? - It's very easy!
[L7] - EJTAG: an attraction for hackers ;
[L8] - OpenOCD: user manual (translation) ;
[L9] - Wikipedia. gdbserver ;
[L10] - VSCode Documentation: Debugging ;
[L11] - VSCode Documentation: C / C ++ for VS Code ;
[L12] - Codescape MIPS SDK ;
[L13] - FTDI strikes back ;
[L14] - Resurrect FTDI in pictures ;
[L15] - MPSSELight. Lightweight .net MPSSE library ;
[L16] - Coordination of logical levels of 5V and 3.3V devices
[L17] - Visual Studio Code ;


Documentation


[D1] - FTDI FT2232D Datasheet ;
[D2] - FTDI Application Note AN 135. FTDI MPSSE Basics ;
[D3] - FTDI Application Note AN 108. Command Processor for MPSSE and MCU Host Bus Emulation Modes ;
[D4] - FTDI Software Application Development. D2XX Programmer's Guide ;
[D5] - Debugging with gdb. Codescape GNU Tools 2016.05-03 for MIPS MTI Bare Meta ;
[D6] - MIPS32 microAptiv UP Processor Core Family Integrator's Guide ;
[D7] - EJTAG Specification. Document Number: MD00047 ;
[D8] - OpenOCD User's Guide for release 0.8.0 ;
[D9] - Using the GNU Compiler Collection. Codescape GNU Tools 2016.05-03 for MIPS MTI Bare Metal ;
[D10] - MIPSfpga Getting Started Guide ;


Images


[P1] The main elements of the system ;
[P2] FTDI USB Adapter Chip Specs (source: L5 );
[P3] Fragment of the Pinboard II debugging circuit (source: L4 );
[P4] Typical connection scheme via EJTAG interface (source: D6 );
[P5] Table of connecting the USB module to the FPGA ;
[P6] IDCODE register (source: D7 );
[P7] Visual Studio Code in debug mode (screenshot) .


')

Source: https://habr.com/ru/post/322442/


All Articles