esp-idf icon indicating copy to clipboard operation
esp-idf copied to clipboard

FREERTOS_WATCHPOINT_END_OF_STACK severely slow down the ISR response on C3 and C6 with debugger attached. (IDFGH-12539)

Open andylinpersonal opened this issue 1 year ago • 3 comments

Answers checklist.

  • [X] I have read the documentation ESP-IDF Programming Guide and the issue is not addressed there.
  • [X] I have updated my IDF branch (master or release) to the latest version and checked that the issue is present there.
  • [X] I have searched the issue tracker for a similar issue and not found a similar issue.

IDF version.

release/v5.1 and release/v5.2

Espressif SoC revision.

ESP32-C3 (QFN32) (revision v0.3) and ESP32-C6 revision 0.0

Operating System used.

Linux

How did you build your project?

VS Code IDE

If you are using Windows, please specify command line type.

None

Development Kit.

C3: Custom board, C6: ESP32-C6-DevkitC-N8

Power Supply used.

USB

What is the expected behavior?

System should not be clogged even with the debug probe attached and enabled on it.

What is the actual behavior?

When the system is busy (simulated by two busy printing tasks) and compiled with FREERTOS_WATCHPOINT_END_OF_STACK=y, system will become very slow and the serving of ISRs are severely deferred (use systick as demo). BTW, this issue also affect the interrupt-intensive tasks. I have been successfully reproduced on the I2C and I2S over GDMA.

Steps to reproduce.

  1. Enable FREERTOS_WATCHPOINT_END_OF_STACK=y in the sdkconfig.defaults.
  2. Apply the snippets to the systick handler.
  3. Build and flash
  4. Run openocd -f 'board/$CHIP-builtin.cfg' and open the console of openocd by telnet localhost 4444.
  5. Run idf.py monitor -p $PORT --no-reset.
  6. Reset the target in the openocd console reset.
  7. See the console output with and without FREERTOS_WATCHPOINT_END_OF_STACK.
    1. Systick has been severely delayed for about 407x. It's an incredible ratio.

Debug Logs.

C6 with debugger attached


ESP-ROM:esp32c6-20220919
ESP-ROM:esp32c6-20220919
Build:Sep 19 2022
rst:0x18 (JTAG_CPU),boot:0xc (SPI_FAST_FLASH_BOOT)
Saved PC:0x20000830
SPIWP:0xee
mode:DIO, clock div:2
load:0x40875720,len:0x19b0
load:0x4086c410,len:0xd54
load:0x4086e610,len:0x2e38
entry 0x4086c41a
[0;32m22       boot            I: ESP-IDF v5.2-dev-5051-g9010d945e1-dirty 2nd stage bootloader[0m
[0;32m23       boot            I: compile time Apr  5 2024 01:55:30[0m
[0;32m26       boot            I: chip revision: v0.0[0m
[0;32m31       boot.esp32c6    I: SPI Speed      : 80MHz[0m
[0;32m37       boot.esp32c6    I: SPI Mode       : DIO[0m
[0;32m42       boot.esp32c6    I: SPI Flash Size : 2MB[0m
[0;32m47       boot            I: Enabling RNG early entropy source...[0m
[0;32m54       boot            I: Partition Table:[0m
[0;32m59       boot            I: ## Label            Usage          Type ST Offset   Length[0m
[0;32m67       boot            I:  0 nvs              WiFi data        01 02 00009000 00006000[0m
[0;32m76       boot            I:  1 phy_init         RF data          01 01 0000f000 00001000[0m
[0;32m85       boot            I:  2 factory          factory app      00 00 00010000 00100000[0m
[0;32m94       boot            I: End of partition table[0m
[0;32m99       esp_image       I: segment 0: paddr=00010020 vaddr=42010020 size=08660h ( 34400) map[0m
[0;32m116      esp_image       I: segment 1: paddr=00018688 vaddr=40800000 size=07990h ( 31120) load[0m
[0;32m125      esp_image       I: segment 2: paddr=00020020 vaddr=42000020 size=0c5f0h ( 50672) map[0m
[0;32m138      esp_image       I: segment 3: paddr=0002c618 vaddr=40807990 size=0215ch (  8540) load[0m
[0;32m141      esp_image       I: segment 4: paddr=0002e77c vaddr=40809af0 size=011d4h (  4564) load[0m
[0;32m149      boot            I: Loaded app from partition at offset 0x10000[0m
[0;32m153      boot            I: Disabling RNG early entropy source...[0m
[0;32m360   ř˙˙˙˙Ÿƒ€ŒÁŐ}ÍхÉс€€€€€€$é€TšĽ˝É•„ÁÁmlÁ´5([0;33m369      clk             W: esp_perip_clk_init() has not been implemented yet[0m
[0;32m369      cpu_start       I: Pro cpu start user code[0m
[0;32m371      cpu_start       I: cpu freq: 160000000 Hz[0m
[0;32m376      cpu_start       I: Application information:[0m
[0;32m382      cpu_start       I: Project name:     tester[0m
[0;32m388      cpu_start       I: App version:      1[0m
[0;32m393      cpu_start       I: Compile time:     Apr  5 2024 01:55:15[0m
[0;32m400      cpu_start       I: ELF file SHA256:  a693f6e35...[0m
[0;32m406      cpu_start       I: ESP-IDF:          v5.2-dev-5051-g9010d945e1-dirty[0m
[0;32m414      cpu_start       I: Min chip rev:     v0.0[0m
[0;32m419      cpu_start       I: Max chip rev:     v0.99 [0m
[0;32m425      cpu_start       I: Chip rev:         v0.0[0m
[0;32m430      heap_init       I: Initializing. RAM available for dynamic allocation:[0m
[0;32m438      heap_init       I: At 4080EE90 len 0006D780 (437 KiB): RAM[0m
[0;32m445      heap_init       I: At 4087C610 len 00002F54 (11 KiB): RAM[0m
[0;32m452      heap_init       I: At 50000000 len 00003FE8 (15 KiB): RTCRAM[0m
[0;32m460      spi_flash       I: detected chip: generic[0m
[0;32m465      spi_flash       I: flash io: dio[0m
[0;33m469      spi_flash       W: Detected size(8192k) larger than the size in the binary image header(2048k). Using the size in the binary image header.[0m
[0;32m483      sleep           I: Configure to isolate all GPIO pins in sleep state[0m
[0;32m491      sleep           I: Enable automatic switching of GPIO sleep configuration[0m
[0;32m499      coexist         I: coex firmware version: d96c1e51f[0m
[0;32m500      coexist         I: coexist rom version 5b8dcfa[0m
[0;32m724      main_task       I: Started on CPU0[0m
[0;32m724      main_task       I: Calling app_main()[0m
[0;32m724      main            I: 0 interrupts recorded[0m
[0;32m724      main            I: print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things [0m
[0;32m725      main            I: 1 interrupts recorded[0m
[0;32m725      main_task       I: Returned from app_main()[0m
[0;32m726      main            I: print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things [0m
[0;32m726      main            I: 2 interrupts recorded[0m
[0;32m727      main            I: print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things [0m
[0;32m727      main            I: 3 interrupts recorded[0m
[0;32m728      main            I: print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things [0m
[0;32m728      main            I: 4 interrupts recorded[0m
[0;32m729      main            I: print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things [0m
[0;32m729      main            I: 5 interrupts recorded[0m
[0;32m730      main            I: print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things [0m
[0;32m730      main            I: 6 interrupts recorded[0m
[0;32m731      main            I: print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things [0m
[0;32m731      main            I: 7 interrupts recorded[0m
[0;32m732      main            I: print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things [0m
[0;32m732      main            I: 8 interrupts recorded[0m
[0;32m733      main            I: print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things [0m
[0;32m733      main            I: 9 interrupts recorded[0m
[0;32m734      main            I: print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things [0m
[0;32m734      main            I: 10 interrupts recorded[0m
[0;32m735      main            I: print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things [0m
[0;32m735      main            I: 11 interrupts recorded[0m
[0;32m736      main            I: print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things [0m
[0;32m736      main            I: 12 interrupts recorded[0m
[0;32m737      main            I: print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things [0m
[0;32m737      main            I: 13 interrupts recorded[0m
[0;32m738      main            I: print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things [0m
[0;32m738      main            I: 14 interrupts recorded[0m
[0;32m739      main            I: print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things [0m
[0;32m739      main            I: 15 interrupts recorded[0m
[0;32m740      main            I: print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things [0m
[0;32m740      main            I: 16 interrupts recorded[0m
[0;32m741      main            I: print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things [0m
[0;32m741      main            I: 17 interrupts recorded[0m
[0;32m742      main            I: print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things [0m
[0;32m742      main            I: 18 interrupts recorded[0m
[0;32m743      main            I: print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things [0m
[0;32m743      main            I: 19 interrupts recorded[0m
[0;32m744      main            I: print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things [0m
[0;32m744      main            I: 20 interrupts recorded[0m
[0;32m745      main            I: print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things [0m
[0;32m745      main            I: 21 interrupts recorded[0m
[0;32m746      main            I: print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things [0m
[0;32m746      main            I: 22 interrupts recorded[0m
[0;32m747      main            I: print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things [0m
[0;32m747      main            I: 23 interrupts recorded[0m
[0;32m748      main            I: print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things [0m
[0;32m748      main            I: 24 interrupts recorded[0m
[0;32m749      main            I: print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things [0m
[0;32m749      main            I: 25 interrupts recorded[0m
[0;32m750      main            I: print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things [0m
[0;32m750      main            I: 26 interrupts recorded[0m
[0;32m751      main            I: print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things [0m
[0;32m751      main            I: 27 interrupts recorded[0m
[0;32m752      main            I: print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things [0m
[0;32m752      main            I: 28 interrupts recorded[0m
[0;32m753      main            I: print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things [0m
[0;32m753      main            I: 29 interrupts recorded[0m
[0;32m754      main            I: print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things [0m
[0;32m754      main            I: 30 interrupts recorded[0m
[0;32m755      main            I: print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things [0m
[0;32m755      main            I: 31 interrupts recorded[0m
[0;32m756      main            I: print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things [0m
[0;32m756      main            I: 32 interrupts in 0xFFFFFFFFFEFFDA07 ticks (16000000 MHz)[0m
[0;32m757      main            I: print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things [0m
[0;32m757      main            I: 32 interrupts in 0x00000000095B2A0B ticks (16000000 MHz)[0m
[0;32m758      main            I: print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things [0m
[0;32m758      main            I: 32 interrupts in 0x00000000095B2A0B ticks (16000000 MHz)[0m
[0;32m759      main            I: print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things [0m
[0;32m759      main            I: 32 interrupts in 0x00000000095B2A0B ticks (16000000 MHz)[0m
[0;32m760      main            I: print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things [0m
[0;32m760      main            I: 32 interrupts in 0x00000000095B2A0B ticks (16000000 MHz)[0m

C6 without debugger

[0;32m1365     main            I: print lots of things print loESP-ROM:esp32c6-20220919
Build:Sep 19 2022
rst:0x15 (USB_UART_HPSYS),boot:0xc (SPI_FAST_FLASH_BOOT)
Saved PC:0x40020890
SPIWP:0xee
mode:DIO, clock div:2
load:0x40875720,len:0x19b0
load:0x4086c410,len:0xd54
load:0x4086e610,len:0x2e38
entry 0x4086c41a
[0;32m23       boot            I: ESP-IDF v5.2-dev-5051-g9010d945e1-dirty 2nd stage bootloader[0m
[0;32m23       boot            I: compile time Apr  5 2024 01:55:30[0m
[0;32m27       boot            I: chip revision: v0.0[0m
[0;32m32       boot.esp32c6    I: SPI Speed      : 80MHz[0m
[0;32m37       boot.esp32c6    I: SPI Mode       : DIO[0m
[0;32m42       boot.esp32c6    I: SPI Flash Size : 2MB[0m
[0;32m48       boot            I: Enabling RNG early entropy source...[0m
[0;32m55       boot            I: Partition Table:[0m
[0;32m59       boot            I: ## Label            Usage          Type ST Offset   Length[0m
[0;32m68       boot            I:  0 nvs              WiFi data        01 02 00009000 00006000[0m
[0;32m77       boot            I:  1 phy_init         RF data          01 01 0000f000 00001000[0m
[0;32m85       boot            I:  2 factory          factory app      00 00 00010000 00100000[0m
[0;32m94       boot            I: End of partition table[0m
[0;32m100      esp_image       I: segment 0: paddr=00010020 vaddr=42010020 size=08660h ( 34400) map[0m
[0;32m116      esp_image       I: segment 1: paddr=00018688 vaddr=40800000 size=07990h ( 31120) load[0m
[0;32m126      esp_image       I: segment 2: paddr=00020020 vaddr=42000020 size=0c5f0h ( 50672) map[0m
[0;32m138      esp_image       I: segment 3: paddr=0002c618 vaddr=40807990 size=0215ch (  8540) load[0m
[0;32m141      esp_image       I: segment 4: paddr=0002e77c vaddr=40809af0 size=011d4h (  4564) load[0m
[0;32m149      boot            I: Loaded app from partition at offset 0x10000[0m
[0;32m153      boot            I: Disabling RNG early entropy source...[0m
[0;32m160      cpu_start       I: Unicore app[0m
[0;33m173      clk             W: esp_perip_clk_init() has not been implemented yet[0m
[0;32m174      cpu_start       I: Pro cpu start user code[0m
[0;32m178      cpu_start       I: cpu freq: 160000000 Hz[0m
[0;32m183      cpu_start       I: Application information:[0m
[0;32m189      cpu_start       I: Project name:     tester[0m
[0;32m195      cpu_start       I: App version:      1[0m
[0;32m200      cpu_start       I: Compile time:     Apr  5 2024 01:55:15[0m
[0;32m207      cpu_start       I: ELF file SHA256:  a693f6e35...[0m
[0;32m213      cpu_start       I: ESP-IDF:          v5.2-dev-5051-g9010d945e1-dirty[0m
[0;32m221      cpu_start       I: Min chip rev:     v0.0[0m
[0;32m226      cpu_start       I: Max chip rev:     v0.99 [0m
[0;32m232      cpu_start       I: Chip rev:         v0.0[0m
[0;32m237      heap_init       I: Initializing. RAM available for dynamic allocation:[0m
[0;32m245      heap_init       I: At 4080EE90 len 0006D780 (437 KiB): RAM[0m
[0;32m252      heap_init       I: At 4087C610 len 00002F54 (11 KiB): RAM[0m
[0;32m259      heap_init       I: At 50000000 len 00003FE8 (15 KiB): RTCRAM[0m
[0;32m267      spi_flash       I: detected chip: generic[0m
[0;32m272      spi_flash       I: flash io: dio[0m
[0;33m276      spi_flash       W: Detected size(8192k) larger than the size in the binary image header(2048k). Using the size in the binary image header.[0m
[0;32m290      sleep           I: Configure to isolate all GPIO pins in sleep state[0m
[0;32m298      sleep           I: Enable automatic switching of GPIO sleep configuration[0m
[0;32m306      coexist         I: coex firmware version: d96c1e51f[0m
[0;32m307      coexist         I: coexist rom version 5b8dcfa[0m
[0;32m307      main_task       I: Started on CPU0[0m
[0;32m307      main_task       I: Calling app_main()[0m
[0;32m307      main            I: 0 interrupts recorded[0m
[0;32m307      main            I: print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things [0m
[0;32m308      main            I: 1 interrupts recorded[0m
[0;32m308      main_task       I: Returned from app_main()[0m
[0;32m309      main            I: print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things [0m
[0;32m309      main            I: 2 interrupts recorded[0m
[0;32m310      main            I: print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things [0m
[0;32m310      main            I: 3 interrupts recorded[0m
[0;32m311      main            I: print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things [0m
[0;32m311      main            I: 4 interrupts recorded[0m
[0;32m312      main            I: print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things [0m
[0;32m312      main            I: 5 interrupts recorded[0m
[0;32m313      main            I: print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things [0m
[0;32m313      main            I: 6 interrupts recorded[0m
[0;32m314      main            I: print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things [0m
[0;32m314      main            I: 7 interrupts recorded[0m
[0;32m315      main            I: print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things [0m
[0;32m315      main            I: 8 interrupts recorded[0m
[0;32m316      main            I: print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things [0m
[0;32m316      main            I: 9 interrupts recorded[0m
[0;32m317      main            I: print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things [0m
[0;32m317      main            I: 10 interrupts recorded[0m
[0;32m318      main            I: print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things [0m
[0;32m318      main            I: 11 interrupts recorded[0m
[0;32m319      main            I: print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things [0m
[0;32m319      main            I: 12 interrupts recorded[0m
[0;32m320      main            I: print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things [0m
[0;32m320      main            I: 13 interrupts recorded[0m
[0;32m321      main            I: print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things [0m
[0;32m321      main            I: 14 interrupts recorded[0m
[0;32m322      main            I: print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things [0m
[0;32m322      main            I: 15 interrupts recorded[0m
[0;32m323      main            I: print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things [0m
[0;32m323      main            I: 16 interrupts recorded[0m
[0;32m324      main            I: print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things [0m
[0;32m324      main            I: 17 interrupts recorded[0m
[0;32m325      main            I: print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things [0m
[0;32m325      main            I: 18 interrupts recorded[0m
[0;32m326      main            I: print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things [0m
[0;32m326      main            I: 19 interrupts recorded[0m
[0;32m327      main            I: print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things [0m
[0;32m327      main            I: 20 interrupts recorded[0m
[0;32m328      main            I: print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things [0m
[0;32m328      main            I: 21 interrupts recorded[0m
[0;32m329      main            I: print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things [0m
[0;32m329      main            I: 22 interrupts recorded[0m
[0;32m330      main            I: print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things [0m
[0;32m330      main            I: 23 interrupts recorded[0m
[0;32m331      main            I: print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things [0m
[0;32m331      main            I: 24 interrupts recorded[0m
[0;32m332      main            I: print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things [0m
[0;32m332      main            I: 25 interrupts recorded[0m
[0;32m333      main            I: print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things [0m
[0;32m333      main            I: 26 interrupts recorded[0m
[0;32m334      main            I: print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things [0m
[0;32m334      main            I: 27 interrupts recorded[0m
[0;32m335      main            I: print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things [0m
[0;32m335      main            I: 28 interrupts recorded[0m
[0;32m336      main            I: print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things [0m
[0;32m336      main            I: 29 interrupts recorded[0m
[0;32m337      main            I: print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things [0m
[0;32m337      main            I: 30 interrupts recorded[0m
[0;32m338      main            I: print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things [0m
[0;32m338      main            I: 31 interrupts recorded[0m
[0;32m339      main            I: print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things [0m
[0;32m339      main            I: 32 interrupts in 0xFFFFFFFFFFB493F8 ticks (16000000 MHz)[0m
[0;32m340      main            I: print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things [0m
[0;32m340      main            I: 32 interrupts in 0x000000000007D000 ticks (16000000 MHz)[0m
[0;32m341      main            I: print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things [0m
[0;32m341      main            I: 32 interrupts in 0x000000000007D000 ticks (16000000 MHz)[0m
[0;32m342      main            I: print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things print lots of things [0m

More Information.

main.c

#include <freertos/FreeRTOS.h>
#include <esp_log.h>

volatile bool start_measure = false;
#if CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK == 1
const uint32_t max_intr_counter = 32;
#else
const uint32_t max_intr_counter = 16384;
#endif
volatile uint64_t systick_start = 0;
volatile uint64_t systick_end = 0;
volatile uint32_t intr_counter = 0;

static const char TAG[] = "main";
static StackType_t s_main_stack[4096];
static StaticTask_t s_main_tcb;
static StackType_t s_test_stack[4096];
static StaticTask_t s_test_tcb;

static void main_task(void *) {
  start_measure = true;
  while (1) {
    if (intr_counter == max_intr_counter) {
      uint64_t delta = systick_end - systick_start;
      ESP_LOGI(TAG, "%u interrupts in 0x%08X%08X ticks (%u MHz)",
               (unsigned)intr_counter, (unsigned)(delta >> 32), (unsigned)delta,
               16000000);
    } else {
      ESP_LOGI(TAG, "%u interrupts recorded", (unsigned)intr_counter);
    }
    vTaskDelay(1);
  }
}

static void test_task(void *arg) {
  while (true) {
    ESP_LOGI(TAG, "print lots of things "
                  "print lots of things "
                  "print lots of things "
                  "print lots of things "
                  "print lots of things "
                  "print lots of things "
                  "print lots of things ");
    vTaskDelay(1);
  }
}

void app_main(void) {
  xTaskCreateStaticPinnedToCore(&main_task, "main", sizeof(s_main_stack), NULL,
                                5, &s_main_stack[0], &s_main_tcb, 0);
  xTaskCreateStaticPinnedToCore(&test_task, "0", sizeof(s_test_stack), NULL,
                                5, &s_test_stack[0], &s_test_tcb, 0);
}

Snippets to be added to the systick handler or global interrupt handler: (Choose one of the two and see the console output)

components/freertos/port_systick.c

extern volatile bool start_measurement;
extern const uint32_t max_intr_counter;
extern volatile uint64_t systick_start;
extern volatile uint64_t systick_end;
extern volatile uint32_t intr_counter;

void SysTickIsrHandler(void *arg) {
    if (start_measurement) {
        systimer_hal_context_t tmrhal = {.dev = &SYSTIMER};
        if (intr_counter == 0) {
            if (systimer_ll_is_counter_value_valid(&SYSTIMER, SYSTIMER_COUNTER_ESPTIMER)) {
                systick_start = systimer_hal_get_counter_value(&tmrhal, SYSTIMER_COUNTER_ESPTIMER);
                intr_counter++;
            }
        } else if (intr_counter < max_intr_counter) {
            intr_counter++;
        } else {
            start_measurement = false;
            systick_end = systimer_hal_get_counter_value(&tmrhal, SYSTIMER_COUNTER_ESPTIMER);
        }
    }
    // omit
}

components/riscv/interrupt.c

extern volatile bool start_measurement;
extern const uint32_t max_intr_counter;
extern volatile uint64_t systick_start;
extern volatile uint64_t systick_end;
extern volatile uint32_t intr_counter;

void _global_interrupt_handler(intptr_t sp, int mcause) {
    if (start_measurement) {
        systimer_hal_context_t tmrhal = {.dev = &SYSTIMER};
        if (intr_counter == 0) {
            if (systimer_ll_is_counter_value_valid(&SYSTIMER, SYSTIMER_COUNTER_ESPTIMER)) {
                systick_start = systimer_hal_get_counter_value(&tmrhal, SYSTIMER_COUNTER_ESPTIMER);
                intr_counter++;
            }
        } else if (intr_counter < max_intr_counter) {
            intr_counter++;
        } else {
            start_measurement = false;
            systick_end = systimer_hal_get_counter_value(&tmrhal, SYSTIMER_COUNTER_ESPTIMER);
        }
    }
    // omit
}

sdkconfig.defaults

CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG=y
CONFIG_FREERTOS_HZ=1000
CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK=y # Toggle this one

andylinpersonal avatar Apr 04 '24 21:04 andylinpersonal

Hi @andylinpersonal! I have tried to reproduce it but still no luck. I am getting 1ms for both w and w/o FREERTOS_WATCHPOINT_END_OF_STACK + w and w/o the debug probe attached. I used the C6 chip with your example. Does it happen on the master as well?

Your result: 0x7D000 = 512000 ticks,
512000 / 32 (max_intr_counter = 32) / 16 (systimer division) = 1000us. Which is equal to the used CONFIG_FREERTOS_HZ=1000.

(It seems this is without FREERTOS_WATCHPOINT_END_OF_STACK) 0x00000000095B2A0B = 156969483 ticks 156969483 / 16384 (max_intr_counter = 16384) / 16 (systimer division) = 598us. Which is even less than 1ms. Could you explain this case? Is it for 16384 or not?

KonstantinKondrashov avatar Apr 09 '24 13:04 KonstantinKondrashov

@andylinpersonal It seems I have reproduced this case. I slightly changed your example. This example works well when CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK=n or debug is not attached. The issue occurs when CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK=y and the debug is attached. I am getting the 32 Systick interrupts not within 32ms as expected (1 tick is 1ms, CONFIG_FREERTOS_HZ=1000) but within 10sec. Which is 312 times longer. I will check why it works like that.

KonstantinKondrashov avatar Apr 09 '24 16:04 KonstantinKondrashov

BTW, attaching the OpenOCD to running ESP32-C3s and ESP32-C6s will trigger infinite unhandled debug exceptions occasionally, which cannot be eliminated without a full power cycle. It's strange. 😅

andylinpersonal avatar Apr 09 '24 17:04 andylinpersonal