|
| 1 | +# Short readme for how to use the PyJTAG |
| 2 | + |
| 3 | +## Setup |
| 4 | +Generally follow these rules to setup JTAG debugging on your OS: https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/jtag-debugging/index.html |
| 5 | + |
| 6 | +Download link for OpenOCD for ESP32 from Espressif: https://github.com/espressif/openocd-esp32/releases |
| 7 | + |
| 8 | + |
| 9 | +## Build the firmware |
| 10 | +Create the firmware with `BTYPE=debug` flag. |
| 11 | + |
| 12 | +Note: Do not use the default pins assigned to UART, SPI, CAN because they are used by the JTAG. Pins not to be used: P4, P9, P10, P23. |
| 13 | + |
| 14 | +## Setup the PyJTAG board |
| 15 | + |
| 16 | +PyJTAG's switches: |
| 17 | + * ESP32 JTAG: all turned ON |
| 18 | + * ESP32 B.LOADER: all turned ON except SAFE_BOOT_SW which is OFF |
| 19 | + * TO LTE UART 1/2: does not matter |
| 20 | + * CURRENT SHUNTS: connected |
| 21 | + |
| 22 | +Place the Pycom board with the reset button towards the Current Shunts. Now connect the PyJTAG via usb. You will see four new USB devices. On Linux this will look like this: |
| 23 | +``` |
| 24 | +$ lsusb -d 0403: |
| 25 | +Bus 001 Device 010: ID 0403:6011 Future Technology Devices International, Ltd FT4232H Quad HS USB-UART/FIFO IC |
| 26 | +$ ls /dev/ttyUSB? |
| 27 | +/dev/ttyUSB0 /dev/ttyUSB1 /dev/ttyUSB2 /dev/ttyUSB3 |
| 28 | +``` |
| 29 | + |
| 30 | +## Start OCD |
| 31 | + |
| 32 | +Go to `esp32` folder in Firmware-Development repository and run: |
| 33 | +``` |
| 34 | +PATH_TO_OPENOCD/bin/openocd -s PATH_TO_OPENOCD/share/openocd/scripts -s PyJTAG -f PyJTAG/interface/ftdi/esp32-pycom.cfg -f PyJTAG/board/esp32-pycom.cfg |
| 35 | +``` |
| 36 | + |
| 37 | +Output should be like: |
| 38 | +``` |
| 39 | +Open On-Chip Debugger v0.10.0-esp32-20191114 (2019-11-14-14:15) |
| 40 | +Licensed under GNU GPL v2 |
| 41 | +For bug reports, read |
| 42 | + http://openocd.org/doc/doxygen/bugs.html |
| 43 | +none separate |
| 44 | +adapter speed: 20000 kHz |
| 45 | +Info : Configured 2 cores |
| 46 | +Info : Listening on port 6666 for tcl connections |
| 47 | +Info : Listening on port 4444 for telnet connections |
| 48 | +Error: type 'esp32' is missing virt2phys |
| 49 | +Info : ftdi: if you experience problems at higher adapter clocks, try the command "ftdi_tdo_sample_edge falling" |
| 50 | +Info : clock speed 20000 kHz |
| 51 | +Info : JTAG tap: esp32.cpu0 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1) |
| 52 | +Info : JTAG tap: esp32.cpu1 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1) |
| 53 | +Info : Listening on port 3333 for gdb connections |
| 54 | +``` |
| 55 | + |
| 56 | +## Start GDB |
| 57 | + |
| 58 | +When OpenOCD is running, start GDB from `esp32` folder. Assuming you have a FIPY: |
| 59 | +``` |
| 60 | +xtensa-esp32-elf-gdb -x PyJTAG/gdbinit build/FIPY/debug/application.elf |
| 61 | +``` |
| 62 | + |
| 63 | +In `PyJTAG/gdbinit` a breakpoint is configured at `TASK_Micropython`, so execution should stop there first: |
| 64 | + |
| 65 | +``` |
| 66 | +Thread 1 hit Temporary breakpoint 1, TASK_Micropython (pvParameters=0x0) at mptask.c:136 |
| 67 | +``` |
| 68 | + |
| 69 | + |
| 70 | +## REPL |
| 71 | + |
| 72 | +Connect to `/dev/ttyUSB2` to reach the REPL terminal over usb serial. E.g. using pymakr in Atom. |
| 73 | + |
| 74 | +## Troubleshooting |
| 75 | +If openocd says "Error: Connect failed", try to close gdb and openocd and start over. |
| 76 | + |
| 77 | +If `/dev/ttyUSB0` doesn't show up or disappears, disconnect the PyJTAG board, reconnect and start over. |
| 78 | + |
| 79 | +It can be advisable to use the `gdb` from the latest xtensa toolchain, even if an earlier version is used to build the firmware. |
| 80 | + |
| 81 | +If `gdb` does not reach the `Thread 1 hit Temporary breakpoint ...` line, close and reopen `gdb`. |
| 82 | + |
| 83 | + |
| 84 | +## Versions |
| 85 | +There are two generations of PyJTAG boards: |
| 86 | + |
| 87 | +1) First generation with green PCB has three blocks of switches. (Make sure SAFE_BOOT_SW is off.) |
| 88 | +2) Second generation with black PCB and two blocks of switches. |
| 89 | + |
| 90 | +Both generation boards can be equipped with pogo pins that connect to the bottom of the development board and allow LTE debugging. There can either be pins that connect to a GPy or pins that conenct to a FiPy. |
| 91 | + |
| 92 | +To reach the modem UART connect to `/dev/ttyUSB1`. |
| 93 | + |
| 94 | +## Extra |
| 95 | +A few more details are here: https://pycomiot.atlassian.net/wiki/spaces/FIR/pages/966295564/Usage+of+PyJTAG |
| 96 | + |
0 commit comments