tmedicci opened a new pull request, #16756: URL: https://github.com/apache/nuttx/pull/16756
## Summary * esp32s3: Fix bug related to the PSRAM-allocated task stack If both SPI Flash support (`CONFIG_ESP32S3_SPIFLASH`) and PSRAM (`CONFIG_ESP32S3_SPIRAM`) are enabled, the PSRAM can only be assigned to the user's heap (`CONFIG_ESP32S3_SPIRAM_USER_HEAP`). Additionaly, `CONFIG_ESP32S3_SPI_FLASH_SUPPORT_PSRAM_STACK` must be set because the system will end up allocating tasks' stacks from the external PSRAM. This has an impact when dealing with SPI flash operations because the cache must be disabled and the running task should not rely on any data from the PSRAM. To accomplish that, It offloads the SPI flash operation to a work queue (which, by definition, allocates its heap from the kernel heap). The same (assigning the PSRAM to the user's heap) is valid when the Wi-Fi is enabled because the lower-half driver requires data being allocated from the internal memory (which can only be achieved by allocating from the kernel heap when both the kernel and user heaps exists). ## Impact Impact on user: Yes. It fixes a bug. Impact on build: No. Impact on hardware: Yes. It impacts ESP32-S3. Impact on documentation: No. Impact on security: No. Impact on compatibility: No. ## Testing Testing can be performed by building the firmware and flashing it to a ESP32-S3 board with a PSRAM module (this example uses a ESP32-S3-DevKitC-1 v1.1 board with a ESP32-S3-WROOM-2 module). Before applying this patch, the device fails to boot. ### Building The firmware can be built and flashed with the following command: ``` make -j distclean && ./tools/configure.sh esp32s3-devkit:sta_softap && kconfig-tweak -e ESP32S3_FLASH_MODE_OCT && kconfig-tweak -e ESP32S3_SPIRAM && kconfig-tweak -e ESP32S3_SPIRAM_MODE_OCT && kconfig-tweak -e ESP32S3_SPIRAM_USER_HEAP && make olddefconfig && make EXTRAFLAGS="-Wno-cpp -Werror" bootloader && make flash EXTRAFLAGS="-Wno-cpp -Werror" ESPTOOL_PORT=/dev/ttyUSB0 ESPTOOL_BINDIR=./ -s -j$(nproc) && xtensa-esp32s3-elf-objdump -D nuttx > objdump.flat ``` ### Running Check boot on UART0: ``` picocom -b 115200 /dev/ttyUSB0 ``` ### Results #### Before ``` 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:0x3fcabc50,len:0x3250 load:0x40374000,len:0xd5fc SHA-256 comparison failed: Calculated: bab955807470cc44dd6b715f2a557b2a0aec28520a7bf2a0d5b3bf819db15e9e Expected: 0000000070f70000000000000000000000000000000000000000000000000000 Attempting to boot anyway... entry 0x403750ac *** Booting NuttX *** dram: lma 0x00000020 vma 0x3fcabc50 len 0x3250 (12880) iram: lma 0x00003278 vma 0x40374000 len 0xd5fc (54780) padd: lma 0x00010888 vma 0x00000000 len 0xf770 (63344) imap: lma 0x00020000 vma 0x42010000 len 0x7b66c (505452) padd: lma 0x0009b674 vma 0x00000000 len 0x4984 (18820) dmap: lma 0x000a0000 vma 0x3c0a0000 len 0x19928 (104744) total segments stored 6 ``` Boot failed... #### After ``` 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:0x3fcabd60,len:0x3260 load:0x40374000,len:0xd74c SHA-256 comparison failed: Calculated: 2b6bcf83299757a8ddfc669a9afaa75c94ac31431dbaa96ec8ff2d05d23c59bc Expected: 0000000010f60000000000000000000000000000000000000000000000000000 Attempting to boot anyway... entry 0x403750c0 *** Booting NuttX *** dram: lma 0x00000020 vma 0x3fcabd60 len 0x3260 (12896) iram: lma 0x00003288 vma 0x40374000 len 0xd74c (55116) padd: lma 0x000109e8 vma 0x00000000 len 0xf610 (62992) imap: lma 0x00020000 vma 0x42010000 len 0x7b804 (505860) padd: lma 0x0009b80c vma 0x00000000 len 0x47ec (18412) dmap: lma 0x000a0000 vma 0x3c0a0000 len 0x19928 (104744) total segments stored 6 NuttShell (NSH) NuttX-10.4.0 nsh> free total used free maxused maxfree nused nfree name 261744 62616 199128 62976 199056 116 3 Kmem 8388608 10400 8378208 11384 8378208 8 1 Umem ``` -- 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