tmedicci opened a new pull request, #15890: URL: https://github.com/apache/nuttx/pull/15890
## Summary * xtensa/esp32[|s3]: re-enable cache during exception handler This PR implements re-enabling the cache before the exception handler for ESP32-S3 and removes unnecessary checks (cache should always be re-enabled during an exception handler and disabled again after processed, except for ESP32-S3 that implements no recoverable exceptions). ## Impact Allows calling `xtensa_user_panic` and stack/backtrace dumps on unrecoverable exceptions to successfully print on the terminal on ESP32 and ESP32-S3 if the exception occurred when the cache was disabled. Impact on user: YES. Indirectly, it provides useful crash information when cache is disabled. Impact on build: NO. Impact on hardware: NO. Impact on documentation: NO. Impact on security: NO Impact on compatibility: NO ## Testing Internal CI testing + ESP32 + ESP32-S3. ### Building and Flashing Simulate a situation where cache is disabled and an unrecoverable exception happens (apply the following patch locally): ``` diff --git a/arch/xtensa/src/esp32s3/esp32s3_spiflash.c b/arch/xtensa/src/esp32s3/esp32s3_spiflash.c index bf86049c8b..2613f691e4 100644 --- a/arch/xtensa/src/esp32s3/esp32s3_spiflash.c +++ b/arch/xtensa/src/esp32s3/esp32s3_spiflash.c @@ -267,6 +267,7 @@ void spiflash_start(void) #ifdef CONFIG_SMP int other_cpu; #endif + int *p = NULL; nxrmutex_lock(&g_flash_op_mutex); @@ -311,6 +312,8 @@ void spiflash_start(void) esp32s3_irq_noniram_disable(); spiflash_suspend_cache(); + + *p = 0; } ``` Build a `defconfig` with SMP enabled + SPI flash support + scheduler backtrace. The following configuration is expected to fail during initialization: ``` make -j distclean && ./tools/configure.sh esp32s3-devkit:sta_softap && kconfig-tweak -e SCHED_BACKTRACE && make flash ESPTOOL_PORT=/dev/ttyUSB0 && minicom ``` #### Expected Results Without this PR, the resulting output is: ``` ESP-ROM:esp32s3-20210327 Build:Mar 27 2021 rst:0x1 (POWERON),boot:0x18 (SPI_FAST_FLASH_BOOT) SPIWP:0xee Octal Flash Mode Enabled For OPI Flash, Use Default Flash Boot Mode mode:SLOW_RD, clock div:2 load:0x3fcab0f0,len:0x2fa0 load:0x40374000,len:0xbac4 SHA-256 comparison failed: Calculated: c7cfc782850f28a3c7ad2b4c9deaf6fb9d9fd4a1de5b054f4f53e55d8265ecdf Expected: 0000000060150000000000000000000000000000000000000000000000000000 Attempting to boot anyway... entry 0x40374f68 *** Booting NuttX *** dram: lma 0x00000020 vma 0x3fcab0f0 len 0x2fa0 (12192) iram: lma 0x00002fc8 vma 0x40374000 len 0xbac4 (47812) padd: lma 0x0000ea98 vma 0x00000000 len 0x1560 (5472) imap: lma 0x00010000 vma 0x42040000 len 0x8434c (541516) padd: lma 0x00094354 vma 0x00000000 len 0xbca4 (48292) dmap: lma 0x000a0000 vma 0x3c010000 len 0x1f95c (129372) total segments stored 6 ``` **No error printed!** With this PR: ``` ESP-ROM:esp32s3-20210327 Build:Mar 27 2021 rst:0x1 (POWERON),boot:0x19 (SPI_FAST_FLASH_BOOT) SPIWP:0xee Octal Flash Mode Enabled For OPI Flash, Use Default Flash Boot Mode mode:SLOW_RD, clock div:2 load:0x3fcab0f0,len:0x2fa0 load:0x40374000,len:0xbae8 SHA-256 comparison failed: Calculated: 9b302648b85a21a757350da279be7b67129fd9580773836f53452510b60fdd8c Expected: 0000000030150000000000000000000000000000000000000000000000000000 Attempting to boot anyway... entry 0x40374f6c *** Booting NuttX *** dram: lma 0x00000020 vma 0x3fcab0f0 len 0x2fa0 (12192) iram: lma 0x00002fc8 vma 0x40374000 len 0xbae8 (47848) padd: lma 0x0000eac8 vma 0x00000000 len 0x1530 (5424) imap: lma 0x00010000 vma 0x42040000 len 0x84338 (541496) padd: lma 0x00094340 vma 0x00000000 len 0xbcb8 (48312) dmap: lma 0x000a0000 vma 0x3c010000 len 0x1f95c (129372) total segments stored 6 [CPU1] xtensa_user_panic: User Exception: EXCCAUSE=001d task: nsh_main [CPU1] dump_assert_info: Current Version: NuttX 10.4.0 14062e8e38-dirty Feb 7 2025 16:05:13 xtensa [CPU1] dump_assert_info: Assertion failed user panic: at file: common/xtensa_assert.c:190 task(CPU1): nsh_main process: nsh_main 0x4204adb8 [CPU1] up_dump_register: PC: 40378c86 PS: 00060830 [CPU1] up_dump_register: A0: 8004cbf5 A1: 3fcb2200 A2: 00000000 A3: 00000064 [CPU1] up_dump_register: A4: 00000001 A5: 00000001 A6: 00000010 A7: 40404040 [CPU1] up_dump_register: A8: 80378c78 A9: 3fcb21e0 A10: 00000002 A11: 3fc975a4 [CPU1] up_dump_register: A12: 00060820 A13: 00000004 A14: 00000000 A15: 20000001 [CPU1] up_dump_register: SAR: 0000001f CAUSE: 0000001d VADDR: 00000000 [CPU1] up_dump_register: LBEG: 400570e8 LEND: 400570f3 LCNT: 00000000 [CPU1] dump_stackinfo: User Stack: [CPU1] dump_stackinfo: base: 0x3fcb0558 [CPU1] dump_stackinfo: size: 00008136 [CPU1] dump_stackinfo: sp: 0x3fcb2200 [CPU1] stack_dump: 0x3fcb21e0: b927082c d2499529 8899d1a4 4d3da6e8 8004d0f0 3fcb2220 00000003 00000001 [CPU1] stack_dump: 0x3fcb2200: 00000002 3fcb00b8 3fc8fd38 00060b20 82076be0 3fcb2240 00000000 3fcb2370 [CPU1] stack_dump: 0x3fcb2220: 3fcab8a8 00000001 00000000 ff000000 820609e4 3fcb22a0 00000000 00180000 [CPU1] stack_dump: 0x3fcb2240: 00000063 00000000 00000000 400556d5 400556e5 fffffffd 40374e7e ab49b303 [CPU1] stack_dump: 0x3fcb2260: 001800fe 00000000 00000000 00180100 00000000 00000000 00000000 00000000 [CPU1] stack_dump: 0x3fcb2280: 00000002 02000000 3fcef710 00000000 8205d7e0 3fcb22c0 00000000 42076bc4 [CPU1] stack_dump: 0x3fcb22a0: 001800fe 00000000 00000002 3fcb2370 8205c569 3fcb22f0 3fcb3060 3fcb2370 [CPU1] stack_dump: 0x3fcb22c0: 3c01c268 3fcb0420 00000002 3fc90b30 000000fe 00000000 00000002 3fcb2370 [CPU1] stack_dump: 0x3fcb22e0: 82059e04 3fcb2330 3fcb3060 00000001 3fcb2370 3fcb2330 000000fe 3fcb2bc8 [CPU1] stack_dump: 0x3fcb2300: 00000000 40378c8c 3fcade74 000000d0 42060960 00000000 00000002 3fcb2370 [CPU1] stack_dump: 0x3fcb2320: 82058d74 3fcb2360 3fcb3060 ffffffff 00000001 00000000 00000000 3fcaef48 [CPU1] stack_dump: 0x3fcb2340: 00000000 3fcb3110 000000fe 00000000 82057292 3fcb23a0 00000100 3fcb3060 [CPU1] stack_dump: 0x3fcb2360: 00000002 3fcb2370 ffffffff 1fffffff 3fcb3124 3fcb0000 3fcb2fa8 00000000 [CPU1] stack_dump: 0x3fcb2380: 3fcb2370 00000000 3fcb3124 00000000 82073cbd 3fcb23c0 42058cd0 3c01c0b5 [CPU1] stack_dump: 0x3fcb23a0: 3fcb23dc 00000000 00000010 40404040 82073c07 3fcb2410 3c01c080 3fcb2710 [CPU1] stack_dump: 0x3fcb23c0: 3c01c0b6 00000000 00000000 3fcaee60 00000000 00000000 3c01c000 00000000 [CPU1] stack_dump: 0x3fcb23e0: 00000000 3fcb3028 00000000 3fcb2710 3c012718 00000000 00000000 ff000000 [CPU1] stack_dump: 0x3fcb2400: 82073bb2 3fcb2430 3fcab30e 3c01073e 3c012028 00000000 00000003 00000000 [CPU1] stack_dump: 0x3fcb2420: 82061d6b 3fcb2450 00000000 3c010748 00000000 3fc90c08 00000008 3fc8fbd0 [CPU1] stack_dump: 0x3fcb2440: 8204ae27 3fcb2470 0000ff01 00000000 000000ff 0000ff00 00ff0000 ff000000 [CPU1] stack_dump: 0x3fcb2460: 8204add8 3fcb2490 00000000 3fcb24b0 00000000 00060b20 00000000 00000000 [CPU1] stack_dump: 0x3fcb2480: 82047500 3fcb24b0 00000001 3fcb0538 3fc8fd38 00060920 00060d20 0000abab [CPU1] stack_dump: 0x3fcb24a0: 8204436b 3fcb24e0 4204adb8 00000001 00000064 3fcb2500 00000000 3fcb00b8 [CPU1] stack_dump: 0x3fcb24c0: 00000000 3fcb26f0 3fcb0188 00000000 00000000 3fcb2500 00000000 4204adb8 [CPU1] stack_dump: 0x3fcb24e0: 3fcb0538 00000000 3fc98945 00000000 00000000 3fcb2520 00000000 00000000 [CPU1] stack_dump: 0x3fcb2500: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [CPU1] stack_dump: 0x3fcb2520: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [CPU1] sched_dumpstack: backtrace| 3: 0x42062900 0x403792fa 0x40379587 0x40378f41 0x40378bd1 0x40374e3b 0x40378c86 0x4004cbf5 [CPU1] sched_dumpstack: backtrace| 3: 0x4004d0f0 0x42076be0 0x420609e4 0x4205d7e0 0x4205c569 0x42059e04 0x42058d74 0x42057292 [CPU1] sched_dumpstack: backtrace| 3: 0x4004cbf5 [CPU1] dump_fatal_info: Dump CPU0: RUNNING [CPU1] dump_tasks: PID GROUP CPU PRI POLICY TYPE NPX STATE EVENT SIGMASK STACKBASE STACKSIZE COMMAND [CPU1] dump_tasks: ---- --- 0 --- -------- ------- --- ------- ---------- ---------------- 0x3fc9766c 2048 irq [CPU1] dump_tasks: ---- --- 1 --- -------- ------- --- ------- ---------- ---------------- 0x3fc97e6c 2048 irq [CPU1] dump_task: 0 0 0 0 FIFO Kthread - Assigned 0000000000000000 0x3fcaa500 3056 CPU0 IDLE [CPU1] dump_task: 1 0 1 0 FIFO Kthread - Assigned 0000000000000000 0x3fcae268 3048 CPU1 IDLE [CPU1] dump_task: 2 0 0 100 RR Kthread - Waiting Semaphore 0000000000000000 0x3fcaf0f0 4032 lpwork 0x3fcab0f0 0x3fcab120 [CPU1] dump_task: 3 3 1 100 RR Task - Running 0000000000000000 0x3fcb0558 8136 nsh_main [CPU1] dump_task: 4 0 0 255 RR Kthread - Running 0000000000000000 0x3fcb2900 704 spiflash_op 0x3fcb23ec [CPU1] dump_task: 5 0 1 255 RR Kthread - Waiting Semaphore 0000000000000000 0x3fcb2ce0 704 spiflash_op 0x3fcb23ec [CPU1] sched_dumpstack: backtrace| 0: 0x42043004 0x40374f68 0x4037501e 0x40045c04 0x40043ab9 0x40034c48 0x40000000 [CPU1] sched_dumpstack: backtrace| 1: 0x4037994d 0x42043064 0x40000000 0x40000000 [CPU1] sched_dumpstack: backtrace| 2: 0x42043cf3 0x420436ee 0x4204435c 0x40000000 0x40000000 [CPU1] sched_dumpstack: backtrace| 3: 0x42062900 0x40379124 0x4205fb4d 0x4037964b 0x40378f41 0x40378bd1 0x40374e3b 0x40378c86 [CPU1] sched_dumpstack: backtrace| 3: 0x4004cbf5 0x4004d0f0 0x42076be0 0x420609e4 0x4205d7e0 0x4205c569 0x42059e04 0x42058d74 [CPU1] sched_dumpstack: backtrace| 3: 0x4004cbf5 [CPU1] xtensa_user_panic: User Exception: EXCCAUSE=001c task: nsh_main ``` **Stack and backtrace dump printed!** -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org