Flashing over JTAG with TIAO multi function adapter

User avatar
bdelarre
Posts: 11
Joined: Sun Oct 22, 2017 2:15 am

Flashing over JTAG with TIAO multi function adapter

Postby bdelarre » Sun Oct 22, 2017 2:22 am

I'm attempting to get flashing over JTAG with OpenOCD working.

Starting openocd as below seems to work:

Code: Select all

$ bin/openocd.exe -s share/openocd/scripts -f interface/ftdi/tumpa.cfg -f board/esp-wroom-32.cfg
Open On-Chip Debugger 0.10.0-dev-ga859564 (2017-07-24-16:18)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
none separate
adapter speed: 20000 kHz
force hard breakpoints
Error: libusb_open() failed with LIBUSB_ERROR_NOT_SUPPORTED
Info : ftdi: if you experience problems at higher adapter clocks, try the command "ftdi_tdo_sample_edge falling"
Info : clock speed 20000 kHz
Info : JTAG tap: esp32.cpu0 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : JTAG tap: esp32.cpu1 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : Target halted. PRO_CPU: PC=0x4009113D (active)    APP_CPU: PC=0x400076E0
Not exactly sure why I get the LIBUSB_ERROR_NOT_SUPPORTED message, but probably due to having two other libusb serial ports attached. I have confirmed gdb working with this and managed to hit a breakpoint and step.

But trying to do the flashing fails:

Code: Select all

$ bin/openocd.exe -s share/openocd/scripts -f interface/ftdi/tumpa.cfg -f board/esp-wroom-32.cfg -c "program_esp32 firmware.bin 0x10000 verify exit"    Open On-Chip Debugger 0.10.0-dev-ga859564 (2017-07-24-16:18)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
none separate
adapter speed: 20000 kHz
force hard breakpoints
Error: libusb_open() failed with LIBUSB_ERROR_NOT_SUPPORTED
Info : ftdi: if you experience problems at higher adapter clocks, try the command "ftdi_tdo_sample_edge falling"
Info : clock speed 20000 kHz
Info : JTAG tap: esp32.cpu0 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : JTAG tap: esp32.cpu1 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : Target halted. PRO_CPU: PC=0x4009113D (active)    APP_CPU: PC=0x400076E0
Info : JTAG tap: esp32.cpu0 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : JTAG tap: esp32.cpu1 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : esp32: Debug controller was reset (pwrstat=0x5F, after clear 0x0F).
Info : esp32: Core was reset (pwrstat=0x5F, after clear 0x0F).
Info : Target halted. PRO_CPU: PC=0x5000004B (active)    APP_CPU: PC=0x00000000
esp32: target state: halted
Info : esp32: Core was reset (pwrstat=0x1F, after clear 0x0F).
Info : Target halted. PRO_CPU: PC=0x40000400 (active)    APP_CPU: PC=0x40000400
esp32: target state: halted
** Programming Started **
auto erase enabled
Info : Use core0 of target 'esp32'
Info : Target halted. PRO_CPU: PC=0x40091D07 (active)    APP_CPU: PC=0x400076E0
Info : Auto-detected flash size 4096 KB
Info : Using flash size 4096 KB
Info : Use core0 of target 'esp32'
Error: timed out while waiting for target halted / 4 - 2
Info : Target halted. PRO_CPU: PC=0x4009113D (active)    APP_CPU: PC=0x400076E0
Error: xtensa_wait_algorithm: not halted 0, pc 0x4009113d, ps 0x60021
Error: Faied to wait algorithm (0)!
Error: Algorithm run faied (-302)!
Error: failed erasing sectors 16 to 200
** Programming Failed **
shutdown command invoked
Full log with debug level 3 output is here https://gist.github.com/benjamind/b91c0 ... 276e2eeff3

User avatar
bdelarre
Posts: 11
Joined: Sun Oct 22, 2017 2:15 am

Re: Flashing over JTAG with TIAO multi function adapter

Postby bdelarre » Sun Oct 22, 2017 8:07 pm

Forgot to include some relevant bits of info.

I'm running Windows 10 Home Edition, and attempting to flash a Sparkfun ESP32 Thing.

I also tried compiling the latest version of the modified OpenOCD version from source, with exactly the same results.

User avatar
bdelarre
Posts: 11
Joined: Sun Oct 22, 2017 2:15 am

Re: Flashing over JTAG with TIAO multi function adapter

Postby bdelarre » Thu Oct 26, 2017 2:55 am

Nobody?

Could really do with this working, and by all accounts it should work. Its a real pain to flash over serial and then have to plug the jtag back in to debug.

Any suggestions?

ESP_Alexey
Posts: 24
Joined: Fri Dec 02, 2016 8:55 pm

Re: Flashing over JTAG with TIAO multi function adapter

Postby ESP_Alexey » Fri Oct 27, 2017 8:46 pm

bdelarre wrote:Nobody?

Could really do with this working, and by all accounts it should work. Its a real pain to flash over serial and then have to plug the jtag back in to debug.

Any suggestions?
Hi,

Could you tell the size of app image? According to the log you try to erase 0xB9000 (757760) bytes. Erase operation takes some time. Maybe the problem is with pre-configured timeout values.
Could you retry it with blink example from $IDF_PATH/examples/get-started/blink?

User avatar
bdelarre
Posts: 11
Joined: Sun Oct 22, 2017 2:15 am

Re: Flashing over JTAG with TIAO multi function adapter

Postby bdelarre » Sat Oct 28, 2017 6:58 pm

Hi Alexey,

Thanks for pitching in!

I ran the same process on the hello_world example (I had it precompiled so it was handy), same result:

Code: Select all

$ bin/openocd.exe -s share/openocd/scripts -f interface/ftdi/tumpa.cfg -f board/esp-wroom-32.cfg -c "program_esp32 hello-world.bin 0x10000 verify exit" Open On-Chip Debugger 0.10.0-dev-ga859564 (2017-07-24-16:18)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
none separate
adapter speed: 20000 kHz
force hard breakpoints
Error: libusb_open() failed with LIBUSB_ERROR_NOT_SUPPORTED
Info : ftdi: if you experience problems at higher adapter clocks, try the command "ftdi_tdo_sample_edge falling"
Info : clock speed 20000 kHz
Info : JTAG tap: esp32.cpu0 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : JTAG tap: esp32.cpu1 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : Target halted. PRO_CPU: PC=0x40091138 (active)    APP_CPU: PC=0x400076E2
Info : JTAG tap: esp32.cpu0 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : JTAG tap: esp32.cpu1 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : esp32: Debug controller was reset (pwrstat=0x5F, after clear 0x0F).
Info : esp32: Core was reset (pwrstat=0x5F, after clear 0x0F).
Info : Target halted. PRO_CPU: PC=0x5000004B (active)    APP_CPU: PC=0x00000000
esp32: target state: halted
Info : esp32: Core was reset (pwrstat=0x1F, after clear 0x0F).
Info : Target halted. PRO_CPU: PC=0x40000400 (active)    APP_CPU: PC=0x40000400
esp32: target state: halted
** Programming Started **
auto erase enabled
Info : Use core0 of target 'esp32'
Info : Target halted. PRO_CPU: PC=0x40091D07 (active)    APP_CPU: PC=0x400076E2
Info : Auto-detected flash size 4096 KB
Info : Using flash size 4096 KB
Info : Use core0 of target 'esp32'
Error: timed out while waiting for target halted / 4 - 2
Info : Target halted. PRO_CPU: PC=0x4009113B (active)    APP_CPU: PC=0x400076E2
Error: xtensa_wait_algorithm: not halted 0, pc 0x4009113b, ps 0x60021
Error: Faied to wait algorithm (0)!
Error: Algorithm run faied (-302)!
Error: failed erasing sectors 16 to 47
** Programming Failed **
shutdown command invoked
Full log here - https://gist.github.com/benjamind/d7381 ... 62b7e88ce7

The hello-world.bin is 126kb and the firmware I was trying to flash before was 739kb.

Just to sanity check here's my wiring:

Code: Select all

        Thing   ESP32   JTAG    JTAG20  Color
+3.3V   +3.3V           +3.3V   1       Red
Reset   RST     9       SRST    3       Orange
GND     GND             GND     4       Gray
MTDI    12      18      TDI     5       Yellow
MTMS    14      17      TMS     7       Green
MTCK    13      20      TCK     9       Blue
MTDO    15      21      TDO     13      Purple
Here's some photos of my wiring:
https://photos.app.goo.gl/KLX3zeGu8R643hRU2
https://photos.app.goo.gl/Z7uiyP9ROuv40gSW2
https://photos.app.goo.gl/N6QcuMjdDUNS42Rm1

And the schematic for the ESP32 Thing: https://cdn.sparkfun.com/assets/learn_t ... ematic.pdf
And here's there ESP32 Thing wiring diagram: https://cdn.sparkfun.com/assets/learn_t ... et-v02.png

ESP_igrr
Posts: 2071
Joined: Tue Dec 01, 2015 8:37 am

Re: Flashing over JTAG with TIAO multi function adapter

Postby ESP_igrr » Sun Oct 29, 2017 6:24 am

Perhaps you could try lowering the JTAG clock frequency? 20MHz is okay for dev boards with integrated JTAG adapter, but may not work if you have long wiring. Not sure that is the case here, just something to try.

User avatar
bdelarre
Posts: 11
Joined: Sun Oct 22, 2017 2:15 am

Re: Flashing over JTAG with TIAO multi function adapter

Postby bdelarre » Tue Oct 31, 2017 2:50 am

Well, I am thoroughly confused.

I haven't changed anything, and its started working!

I did remove a usb hub that I had plugged in (that wasn't in any way connected to any of my devices). I wonder if it was interfering somehow?

User avatar
bdelarre
Posts: 11
Joined: Sun Oct 22, 2017 2:15 am

Re: Flashing over JTAG with TIAO multi function adapter

Postby bdelarre » Fri Nov 03, 2017 2:44 am

What the hell? Started failing again. No changes, worked last night, doesn't work this morning.

I lowered the speed to 10mhz with no improvement.

User avatar
bdelarre
Posts: 11
Joined: Sun Oct 22, 2017 2:15 am

Re: Flashing over JTAG with TIAO multi function adapter

Postby bdelarre » Fri Nov 03, 2017 5:28 am

Finally some progress figuring this thing out!

Tried a few other speeds, reducing way down to 3khz. No joy. Then decided to revert my code change and try flashing again with usb. Worked fine. Flashed the same code with jtag, worked fine.

After some binary chopping it appears that if my code has this line:

Code: Select all

wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
Then it will not flash over jtag failing with:

Code: Select all

Error: timed out while waiting for target halted / 4 - 2
Info : Target halted. PRO_CPU: PC=0x40091138 (active)    APP_CPU: PC=0x400076E2
Error: xtensa_wait_algorithm: not halted 0, pc 0x40091138, ps 0x60021
Error: Faied to wait algorithm (0)!
Error: Algorithm run faied (-302)!
Error: failed erasing sectors 16 to 127
** Programming Failed **
If I remove the line, even just the esp_wifi_init call flashing over jtag works again. Don't need to reset the board or anything.

This had me scratching my head for a while before I checked the file sizes. The .bin size is 447kb with the wifi init call, and 211kb without it. So evidently its a timing issue relating to the time it takes to clear the flash area for programming, pulling in the wifi libs puts me over this limit and the flashing fails due to not returning to the halt state in time.

Any idea where I can tweak this timeout?

User avatar
bdelarre
Posts: 11
Joined: Sun Oct 22, 2017 2:15 am

Re: Flashing over JTAG with TIAO multi function adapter

Postby bdelarre » Fri Nov 03, 2017 11:40 pm

Filed this PR against the openocd-esp32 project to increase the timeout to 10s. Seems to do the job.

https://github.com/espressif/openocd-esp32/pull/24

Who is online

Users browsing this forum: No registered users and 92 guests