idf-eclipse-plugin icon indicating copy to clipboard operation
idf-eclipse-plugin copied to clipboard

bleprph example program will not run in the debugger (IEP-651)

Open davidlehrian opened this issue 3 years ago • 2 comments

Environment

  • Development Kit: ESP32-DevKitC
  • Kit version v1
  • Module or chip used: ESP32
  • IDF version (run git describe --tags to find it): v4.4
  • Build System: CMake
  • Compiler version (run xtensa-esp32-elf-gcc --version to find it): xtensa-esp32-elf-gcc (crosstool-NG esp-2021r2-patch2) 8.4.0
  • Operating System: Windows
  • (Windows only) environment type: ESP Command Prompt
  • Using an IDE?: Yes Eclipse and idf-eclipse-plugin
  • Power Supply: ESP-Prog via USB

Problem Description

I'm trying to run bluetooth->nimble->bleprph example code in the debugger in eclipse. The code compiles and flashes onto the uP just fine and I can see the device in my smart phone app. But if I try and run the code in the debugger the system hangs. I get the following output in the Console but the debug process times out and terminates.

Open On-Chip Debugger v0.11.0-esp32-20211220 (2021-12-20-15:43) Licensed under GNU GPL v2 For bug reports, read http://openocd.org/doc/doxygen/bugs.html adapter speed: 20000 kHz

Flashing C:/Users/lehrian/Documents/SmartRecirculationControl/ESP-IDF_Firmware/bleprph/build/partition_table/partition-table.bin at 0x8000 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 : esp32.cpu0: Target halted, PC=0x401282B6, debug_reason=00000000 Info : esp32.cpu1: Target halted, PC=0x401282B6, debug_reason=00000000 Info : starting gdb server for esp32.cpu0 on 3333 Info : Listening on port 3333 for gdb connections 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.cpu0: Debug controller was reset. Info : esp32.cpu0: Core was reset. Info : esp32.cpu0: Target halted, PC=0x500000CF, debug_reason=00000000 Info : Set GDB target to 'esp32.cpu0' Info : esp32.cpu0: Core was reset. Info : esp32.cpu0: Target halted, PC=0x40000400, debug_reason=00000000 Info : esp32.cpu1: Debug controller was reset. Info : esp32.cpu1: Core was reset. Info : esp32.cpu1: Target halted, PC=0x40000400, debug_reason=00000000 Info : esp32.cpu0: Target halted, PC=0x40092AEE, debug_reason=00000001 Info : Flash mapping 0: 0x10020 -> 0x3f400020, 59 KB Info : Flash mapping 1: 0x20020 -> 0x400d0020, 362 KB Info : esp32.cpu0: Target halted, PC=0x40092AEE, debug_reason=00000001 Info : Auto-detected flash bank 'esp32.cpu0.flash' size 4096 KB Info : Using flash bank 'esp32.cpu0.flash' size 4096 KB Info : esp32.cpu0: Target halted, PC=0x40092AEE, debug_reason=00000001 Info : Flash mapping 0: 0x10020 -> 0x3f400020, 59 KB Info : Flash mapping 1: 0x20020 -> 0x400d0020, 362 KB Info : esp32.cpu0: Target halted, PC=0x40092AEE, debug_reason=00000001 Info : Auto-detected flash bank 'esp32.cpu1.flash' size 4096 KB Info : Using flash bank 'esp32.cpu1.flash' size 4096 KB ** Programming Started ** Info : esp32.cpu0: Target halted, PC=0x40092AEE, debug_reason=00000001 Info : esp32.cpu0: Target halted, PC=0x40092AEE, debug_reason=00000001 Info : esp32.cpu0: Target halted, PC=0x40092AEE, debug_reason=00000001 Info : PROF: Data transferred in 69.999 ms @ 57.1437 KB/s ** Programming Finished ** ** Verify Started ** Info : esp32.cpu0: Target halted, PC=0x40092AEE, debug_reason=00000001 ** Verified OK ** ** Flashing done for partition_table/partition-table.bin ** Flashing C:/Users/lehrian/Documents/SmartRecirculationControl/ESP-IDF_Firmware/bleprph/build/bootloader/bootloader.bin at 0x1000 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.cpu0: Debug controller was reset. Info : esp32.cpu0: Core was reset. Info : esp32.cpu0: Target halted, PC=0x500000CF, debug_reason=00000000 Info : esp32.cpu0: Core was reset. Info : esp32.cpu0: Target halted, PC=0x40000400, debug_reason=00000000 Info : esp32.cpu1: Debug controller was reset. Info : esp32.cpu1: Core was reset. Info : esp32.cpu1: Target halted, PC=0x40000400, debug_reason=00000000 ** Programming Started ** Info : esp32.cpu0: Target halted, PC=0x40092AEE, debug_reason=00000001 Info : esp32.cpu0: Target halted, PC=0x40092AEE, debug_reason=00000001 Info : PROF: Data transferred in 275.996 ms @ 101.451 KB/s Info : esp32.cpu0: Target halted, PC=0x40092AEE, debug_reason=00000001 ** Programming Finished ** ** Verify Started ** Info : esp32.cpu0: Target halted, PC=0x40092AEE, debug_reason=00000001 ** Verified OK ** ** Flashing done for bootloader/bootloader.bin ** Flashing C:/Users/lehrian/Documents/SmartRecirculationControl/ESP-IDF_Firmware/bleprph/build/bleprph.bin at 0x10000 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.cpu0: Debug controller was reset. Info : esp32.cpu0: Core was reset. Info : esp32.cpu0: Target halted, PC=0x500000CF, debug_reason=00000000 Info : esp32.cpu0: Core was reset. Info : esp32.cpu0: Target halted, PC=0x40000400, debug_reason=00000000 Info : esp32.cpu1: Debug controller was reset. Info : esp32.cpu1: Core was reset. Info : esp32.cpu1: Target halted, PC=0x40000400, debug_reason=00000000 ** Programming Started ** Info : esp32.cpu0: Target halted, PC=0x40092AEE, debug_reason=00000001 Info : esp32.cpu0: Target halted, PC=0x40092AEE, debug_reason=00000001 Info : PROF: Data transferred in 2039.6 ms @ 266.718 KB/s Info : esp32.cpu0: Target halted, PC=0x40092AEE, debug_reason=00000001 ** Programming Finished ** ** Verify Started ** Info : esp32.cpu0: Target halted, PC=0x40092AEE, debug_reason=00000001 ** Verified OK ** ** Flashing done for bleprph.bin ** ** Resetting Target ** 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.cpu0: Debug controller was reset. Info : esp32.cpu0: Core was reset. Info : esp32.cpu0: Target halted, PC=0x500000CF, debug_reason=00000000 Info : esp32.cpu0: Core was reset. Info : esp32.cpu1: Debug controller was reset. Info : esp32.cpu1: Core was reset. 0 Started by GNU MCU Eclipse Info : Listening on port 6666 for tcl connections Info : Listening on port 4444 for telnet connections Info : accepting 'gdb' connection on tcp/3333 Info : esp32.cpu0: Target halted, PC=0x401292DA, debug_reason=00000000 Info : esp32.cpu1: Target halted, PC=0x401292DA, debug_reason=00000000 Warn : No symbols for FreeRTOS! Info : esp32.cpu0: Target halted, PC=0x40092AEE, debug_reason=00000001 Info : Flash mapping 0: 0x10020 -> 0x3f400020, 60 KB Info : Flash mapping 1: 0x20020 -> 0x400d0020, 366 KB Info : Using flash bank 'esp32.cpu0.irom' size 368 KB

Expected Behavior

Would expect the program to be able to run in the debugger.

Actual Behavior

Steps to reproduce

  1. Create new ESP Project using example code bluetooth->nimble->bleprph.
  2. Compile and flash to uP and confirm that it is running via second ble device
  3. Create a debug launch configuration in Eclipse and set the Board to ESP32 chip (via ESP-PROG) and leave everything else as defaults.
  4. Launch the debugger and see that the program never breaks at main();

// If possible, attach a picture of your setup/wiring here.

The board is wired properly because I can run other example code in the debugger and they work just fine. For example the Blink program runs just fine in the debugger.

What I have discovered is that it seems to be related to lines 123 & 124 in the example code.

    rc = ble_gap_adv_start(own_addr_type, NULL, BLE_HS_FOREVER,
                           &adv_params, bleprph_gap_event, NULL);

If I comment the above line out the code runs just fine in the debugger however I can't find the device when scanning for peripherals in my smart phone app.

davidlehrian avatar Feb 20 '22 05:02 davidlehrian

The problem has to do with sdkconfig Compiler options->Optimization Level. By default it is set to "Debug (-Og)" which causes the debugger to hang when starting gap advertising. If this is changed to "Debug without optimization (-O0)" then the program will run in the debugger and gap [advertising starts just fine] CORRECTION: gap advertising DOES NOT start.

davidlehrian avatar Feb 21 '22 18:02 davidlehrian

CORRECTION: There still seems to be something funny going on.

By changing the Compiler options->Optimization Level from Debug to Debug without optimization I was able to get the debugger to launch and connect to the ESP32. However, ble_gap_adv_start DOES NOT start the device advertising whether I run it in the debugger or not. This compiler option does allow me to connect via the debugger to the process but the program does not advertise itself.

If I change the Compiler options->Optimization Level back to Debug I can not run the program in the debugger because it hangs and never inserts the initial breakpoint in main but if I flash the processor with the program and reboot it I can see the device advertising itself as nimble-bleprph and connect to it with a smart phone app.

davidlehrian avatar Feb 21 '22 23:02 davidlehrian