JTAG programming [solved]

pavel_skirko
Posts: 6
Joined: Wed Dec 05, 2018 3:31 pm

JTAG programming [solved]

Postby pavel_skirko » Wed Dec 05, 2018 3:49 pm

Hi. I'm trying to load program to my ESP32 WROOM using JTAG connection (JetLink9).
Now I get in OpenOCD such messages:

Code: Select all

Open On-Chip Debugger 0.10.0-dev (2018-11-05-04:10)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
adapter speed: 100 kHz
esp32 interrupt mask on
jaylink: Failed to open device: LIBUSB_ERROR_NOT_SUPPORTED.
Info : No device selected, using first device.
Info : J-Link V9 compiled Aug 23 2018 09:45:44
Info : Hardware version: 9.10
Info : VTarget = 3.301 V
Info : clock speed 100 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=0x400873E9 (active)    APP_CPU: PC=0x40080ED7
Info : accepting 'gdb' connection on tcp/3333
Info : Target halted. PRO_CPU: PC=0x4009171A (active)    APP_CPU: PC=0x40080ED7
Warn : Empty flash mapping!
Info : Target halted. PRO_CPU: PC=0x4009171A (active)    APP_CPU: PC=0x40080ED7
Info : Target halted. PRO_CPU: PC=0x4009171A (active)    APP_CPU: PC=0x40080ED7
Info : Auto-detected flash size 4096 KB
Info : Using flash size 4096 KB
Info : Target halted. PRO_CPU: PC=0x4009171A (active)    APP_CPU: PC=0x40080ED7
Warn : Empty flash mapping!
Info : Target halted. PRO_CPU: PC=0x4009171A (active)    APP_CPU: PC=0x40080ED7
Info : Using flash size 0 KB
Info : Target halted. PRO_CPU: PC=0x4009171A (active)    APP_CPU: PC=0x40080ED7
Warn : Empty flash mapping!
Info : Target halted. PRO_CPU: PC=0x4009171A (active)    APP_CPU: PC=0x40080ED7
Info : Using flash size 0 KB
Info : dropped 'gdb' connection
Obviously, loading isn't successful.
I'm using Eclipse with recommended by official tutorials settings.
Last edited by pavel_skirko on Sat Dec 08, 2018 3:55 pm, edited 1 time in total.

pavel_skirko
Posts: 6
Joined: Wed Dec 05, 2018 3:31 pm

Re: JTAG programming.

Postby pavel_skirko » Thu Dec 06, 2018 8:56 pm

I've tried to manually connect to esp32 WROOM. Here what I got:

Code: Select all

xtensa-esp32-elf-gdb H:/Dropbox/Projects/Frog/blink/build/blink.elf
GNU gdb (crosstool-NG crosstool-ng-1.22.0-80-g6c4433a5) 7.10
Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=i686-host_pc-mingw32 --target=xtensa-esp32-elf".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...[/Codebox]

Reading symbols from H:/Dropbox/Projects/Frog/blink/build/blink.elf...done.
(gdb) set remotetimeout 15000
(gdb)
(gdb) target remote :3333
Remote debugging using :3333
0x40000400 in ?? ()
(gdb) load
Loading section .flash.rodata, size 0x6b44 lma 0x3f400020
Load failed
(gdb) mon reset halt
JTAG tap: esp32.cpu0 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
JTAG tap: esp32.cpu1 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
esp32: Debug controller 0 was reset (pwrstat=0x5F, after clear 0x0F).
esp32: Core 0 was reset (pwrstat=0x5F, after clear 0x0F).
Target halted. PRO_CPU: PC=0x5000004B (active)    APP_CPU: PC=0x00000000
esp32: Core 0 was reset (pwrstat=0x1F, after clear 0x0F).
esp32: Debug controller 1 was reset (pwrstat=0x5F, after clear 0x0F).
esp32: Core 1 was reset (pwrstat=0x5F, after clear 0x0F).
Target halted. PRO_CPU: PC=0x40000400 (active)    APP_CPU: PC=0x40000400
(gdb) flushregs
Register cache flushed.
(gdb) load
Loading section .flash.rodata, size 0x6b44 lma 0x3f400020
Load failed
I dont really understand what means string after successful connecting

Code: Select all

Remote debugging using :3333
0x40000400 in ?? ()
Maybe it is something about stock program, I'm using brand new ESP32.
The problem is, that I cannot load a binary.
In OpenOCD window I get the same messages about empty flash mapping

Code: Select all

Info : accepting 'gdb' connection on tcp/3333
Info : Target halted. PRO_CPU: PC=0x4009171A (active)    APP_CPU: PC=0x40080EF0
Warn : Empty flash mapping!
Info : Target halted. PRO_CPU: PC=0x4009171A (active)    APP_CPU: PC=0x40080EF0
Info : Target halted. PRO_CPU: PC=0x4009171A (active)    APP_CPU: PC=0x40080EF0
Info : Auto-detected flash size 4096 KB
Info : Using flash size 4096 KB
Info : Target halted. PRO_CPU: PC=0x4009171A (active)    APP_CPU: PC=0x40080EF0
Warn : Empty flash mapping!
Info : Target halted. PRO_CPU: PC=0x4009171A (active)    APP_CPU: PC=0x40080EF0
Info : Using flash size 0 KB
Info : Target halted. PRO_CPU: PC=0x4009171A (active)    APP_CPU: PC=0x40080EF0
Warn : Empty flash mapping!
Info : Target halted. PRO_CPU: PC=0x4009171A (active)    APP_CPU: PC=0x40080EF0
Info : Using flash size 0 KB
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 0 was reset (pwrstat=0x5F, after clear 0x0F).
Info : esp32: Core 0 was reset (pwrstat=0x5F, after clear 0x0F).
Info : Target halted. PRO_CPU: PC=0x5000004B (active)    APP_CPU: PC=0x00000000
Info : esp32: Core 0 was reset (pwrstat=0x1F, after clear 0x0F).
Info : esp32: Debug controller 1 was reset (pwrstat=0x5F, after clear 0x0F).
Info : esp32: Core 1 was reset (pwrstat=0x5F, after clear 0x0F).
Info : Target halted. PRO_CPU: PC=0x40000400 (active)    APP_CPU: PC=0x40000400
Info : dropped 'gdb' connection

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

Re: JTAG programming.

Postby ESP_igrr » Fri Dec 07, 2018 3:43 am

Hi pavel_skirko,
Have you tried using "mon program_esp32 <file.bin> <address>" command instead of "load"?
https://docs.espressif.com/projects/esp ... -debugging

"load" is a bit hard to support, because GDB only passes virtual address of loaded sections, which is not sufficient to program some of the sections into the flash memory. Neither GDB nor OpenOCD are aware of the ESP32 binary image layout, so they can not correctly convert ELF sections into a binary file in flash. "load" may work for programs which are loaded directly into RAM, but not for programs which contain cached code and rodata.

If you meet issues with "mon program_esp32" as well, could you please open an issue at https://github.com/espressif/openocd-esp32/issues and provide debug info as described here? https://docs.espressif.com/projects/esp ... ing-issues

pavel_skirko
Posts: 6
Joined: Wed Dec 05, 2018 3:31 pm

Re: JTAG programming.

Postby pavel_skirko » Fri Dec 07, 2018 8:25 pm

Hi. I've tried what you just proposed and here what I got (I collected all information in one post).
I'm using JTAG connection (JetLink9 and JetLink5, It is the same as JLink), the stable ESP-EDF v3.1.1, the latest OpenOCD, Win10 running natively.
I'm using a simple example code for LED Blinking:

Code: Select all

#define BLINK_GPIO 27

void blink_task(void *pvParameter)
{
    while(1) {
       /* Blink off (output low) */
    	gpio_set_level(BLINK_GPIO, 0);
        vTaskDelay(100 / portTICK_PERIOD_MS);
        /* Blink on (output high) */
        gpio_set_level(BLINK_GPIO, 1);
        vTaskDelay(110 / portTICK_PERIOD_MS);
    }
}

void app_main()
{
    gpio_pad_select_gpio(BLINK_GPIO);
    gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT);
    xTaskCreate(&blink_task, "blink_task", configMINIMAL_STACK_SIZE, NULL, 10, NULL);
}
Here is successful connecting

Code: Select all

Open On-Chip Debugger 0.10.0-dev (2018-11-05-04:10)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
adapter speed: 3000 kHz
esp32 interrupt mask on
Info : No device selected, using first device.
Info : J-Link compiled Jun 14 2007 14:36:33 ARM Rev.5
Info : Hardware version: 5.30
Info : VTarget = 3.313 V
Info : clock speed 3000 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=0x4008740D (active)    APP_CPU: PC=0x40080EE9
After launching gdb and connecting it to openocd by command

Code: Select all

target remote :3333
I got such messages in OpenOCD window:

Code: Select all

Info : accepting 'gdb' connection on tcp/3333
Info : Target halted. PRO_CPU: PC=0x4009171A (active)    APP_CPU: PC=0x40080EE9
Warn : Empty flash mapping!
Info : Target halted. PRO_CPU: PC=0x4009171A (active)    APP_CPU: PC=0x40080EE9
Info : Target halted. PRO_CPU: PC=0x4009171A (active)    APP_CPU: PC=0x40080EE9
Info : Auto-detected flash size 4096 KB
Info : Using flash size 4096 KB
Info : Target halted. PRO_CPU: PC=0x4009171A (active)    APP_CPU: PC=0x40080EE9
Warn : Empty flash mapping!
Info : Target halted. PRO_CPU: PC=0x4009171A (active)    APP_CPU: PC=0x40080EE9
Info : Using flash size 0 KB
Info : Target halted. PRO_CPU: PC=0x4009171A (active)    APP_CPU: PC=0x40080EE9
Warn : Empty flash mapping!
Info : Target halted. PRO_CPU: PC=0x4009171A (active)    APP_CPU: PC=0x40080EE9
Info : Using flash size 0 KB
Why does it say "empty flash mapping"and "Using flash size 0 KB"?
Then I try load the program:

Code: Select all

(gdb) mon reset halt
JTAG tap: esp32.cpu0 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
JTAG tap: esp32.cpu1 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
esp32: Debug controller 0 was reset (pwrstat=0x5F, after clear 0x0F).
esp32: Core 0 was reset (pwrstat=0x5F, after clear 0x0F).
Target halted. PRO_CPU: PC=0x5000004B (active)    APP_CPU: PC=0x00000000
esp32: Core 0 was reset (pwrstat=0x1F, after clear 0x0F).
esp32: Debug controller 1 was reset (pwrstat=0x5F, after clear 0x0F).
esp32: Core 1 was reset (pwrstat=0x5F, after clear 0x0F).
Target halted. PRO_CPU: PC=0x40000400 (active)    APP_CPU: PC=0x40000400

Code: Select all

(gdb) mon program_esp32 H:/Dropbox/Projects/Frog/blink/build/blink.bin 0x10000 verify
JTAG tap: esp32.cpu0 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
JTAG tap: esp32.cpu1 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
esp32: Debug controller 0 was reset (pwrstat=0x5F, after clear 0x0F).
esp32: Core 0 was reset (pwrstat=0x5F, after clear 0x0F).
Target halted. PRO_CPU: PC=0x5000004B (active)    APP_CPU: PC=0x00000000
esp32: Core 0 was reset (pwrstat=0x1F, after clear 0x0F).
esp32: Debug controller 1 was reset (pwrstat=0x5F, after clear 0x0F).
esp32: Core 1 was reset (pwrstat=0x5F, after clear 0x0F).
Target halted. PRO_CPU: PC=0x40000400 (active)    APP_CPU: PC=0x40000400
** Programming Started **
auto erase enabled
Target halted. PRO_CPU: PC=0x4009171A (active)    APP_CPU: PC=0x40000400
Target halted. PRO_CPU: PC=0x4009171A (active)    APP_CPU: PC=0x40000400
wrote 147456 bytes from file H:/Dropbox/Projects/Frog/blink/build/blink.bin in 5.038046s (28.583 KiB/s)
** Programming Finished **
** Verify Started **
Target halted. PRO_CPU: PC=0x4009171A (active)    APP_CPU: PC=0x40000400
read 146128 bytes from file H:/Dropbox/Projects/Frog/blink/build/blink.bin and flash bank 0 at offset 0x00010000 in 2.594721s (54.997 KiB/s)
contents match
** Verified OK **

Code: Select all

(gdb) flushregs
Register cache flushed.

Code: Select all

(gdb) thb app_main
Note: breakpoint 1 also set at pc 0x400d204f.
Hardware assisted breakpoint 2 at 0x400d204f: file H:/Dropbox/Projects/Frog/blink/main/blink.c, line 40.

Code: Select all

(gdb) c
Continuing.
Target halted. PRO_CPU: PC=0x40087481 (active)    APP_CPU: PC=0x40080EED

Program received signal SIGTRAP, Trace/breakpoint trap.
invoke_abort ()
    at C:/msys32/home/Pavel/esp/esp-idf/components/esp32/panic.c:138
138                 __asm__ ("break 0,0");
And get the panic in the program. Why is it happened? Code is as simple as it can be. Can it be somehow connected with flash memory issues, that I encountered while connecting?
Technically, flashing now is successful, but the program doesn't work. Please, help.

pavel_skirko
Posts: 6
Joined: Wed Dec 05, 2018 3:31 pm

Re: JTAG programming.

Postby pavel_skirko » Sat Dec 08, 2018 4:06 pm

For some reason, when I'm trying to do the same using Eclipse, It stuck with this error

Code: Select all

Failed to execute MI command:
-break-insert -t -f

Error message from debugger back end:
-break-insert: Missing <location>

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

Re: JTAG programming.

Postby ESP_igrr » Sun Dec 09, 2018 2:37 am

Can you please run "bt" command (backtrace) when GDB halts because of panic? The backtrace will indicate where the abort was called from.

Also, if you open serial monitor before launching GDB, and then follow this process of programming and running the application, do you see anything unusual reported on the serial console?

pavel_skirko
Posts: 6
Joined: Wed Dec 05, 2018 3:31 pm

Re: JTAG programming.

Postby pavel_skirko » Thu Jan 03, 2019 11:30 pm

Here what I get after abort. Still don't understand what caused the problem.

Code: Select all

(gdb) bt
#0  invoke_abort ()
    at C:/msys32/home/Pavel/esp/esp-idf/components/esp32/panic.c:138
#1  0x4008765e in abort ()
    at C:/msys32/home/Pavel/esp/esp-idf/components/esp32/panic.c:149
#2  0x400d209e in __assert_func (
    file=0x3f402ee8 "C:/msys32/home/Pavel/esp/esp-idf/components/esp32/clk.c", line=69, func=<optimized out>,
    failedexpr=0x3f402eb8 "rtc_clk_xtal_freq_get() != RTC_XTAL_FREQ_AUTO")
    at ../../../.././newlib/libc/stdlib/assert.c:63
#3  0x400d19e9 in esp_clk_init ()
    at C:/msys32/home/Pavel/esp/esp-idf/components/esp32/clk.c:69
#4  0x40080e05 in start_cpu0_default ()
    at C:/msys32/home/Pavel/esp/esp-idf/components/esp32/cpu_start.c:300
#5  0x400810d6 in call_start_cpu0 ()
    at C:/msys32/home/Pavel/esp/esp-idf/components/esp32/cpu_start.c:219

pavel_skirko
Posts: 6
Joined: Wed Dec 05, 2018 3:31 pm

Re: JTAG programming.

Postby pavel_skirko » Sun Jan 27, 2019 9:55 pm

[SOLVED] My problem was caused by inappropriate bootloader and/or partitions table. I've flashed bootloader.bin to 0x1000 and partition table binary to 0x8000 and it helped.

Who is online

Users browsing this forum: No registered users and 117 guests