Hi Martin, > Hello! This is my first post here.
Welcome to the Apache NuttX mailing list! > The esp32 flash driver suggests "Consider using spi_flash_mmap()" [1] The "spi_flash_mmap()" and the referenced "spi_flash_read()" are ROM functions from the ESP32-C3 chip and their usage should be restricted to the chip implementation, so they should not be called from the userspace. > BTW my requirement for memory mapping is to implement XiP. By default, the NuttX application firmware images for every supported chip of the ESP32 family runs from the External Flash, so XIP is already supported. In fact, there is an option for running the entire firmware image from the Internal SRAM, which is disabled by default: https://github.com/apache/incubator-nuttx/blob/f49a5797213f2ec3fd348e1826db6e080e7be4d9/arch/xtensa/src/esp32/Kconfig#L257-L262 If by supporting XIP you mean dynamically load executable code from External Flash, then ROMFS support may be what you are looking for. https://cwiki.apache.org/confluence/display/NUTTX/RAM+Disks+and+ROM+Disks It seems you are working with an ESP32-C3-based platform, so you may take a look at these defconfigs that rely on the ROMFS support for achieving different purposes: https://github.com/apache/incubator-nuttx/tree/master/boards/risc-v/esp32c3/esp32c3-devkit/configs/elf https://github.com/apache/incubator-nuttx/tree/master/boards/risc-v/esp32c3/esp32c3-devkit/configs/module https://github.com/apache/incubator-nuttx/tree/master/boards/risc-v/esp32c3/esp32c3-devkit/configs/romfs Best regards, Gustavo. On Tue, Sep 20, 2022 at 6:30 AM Martin Klang <m...@pingdynasty.com> wrote: > Hello! This is my first post here. > > I have a question about memory mapping SPI flash on the ESP32. > > The esp32 flash driver suggests "Consider using spi_flash_mmap()" [1] > Does anyone have an example or suggestion for how to do that? > > When I try to use spi_flash_mmap() and spi_flash_munmap() as per the > docs [2] I run into difficulties: the esp32-idf files that define these > functions are not part of a standard NuttX build. In short, after > including the relevant headers I end up with undefined symbol > `spi_flash_munmap` (but spi_flash_mmap is found, surprisingly). So I > guess I need to compile the spi-flash part of esp32-idf as a library and > include in my NuttX build - right? > > Meanwhile the NuttX codebase has its own implementation of esp32 memory > mapping (used for reading encrypted partitions), in the functions > esp32_mmap() and esp32_ummap() [3]. Unfortunately they are static in > esp32_spiflash.c. > > Is the NuttX memory mapping implementation compatible with > spi_flash_mmap()? Would it not make sense to make available, in NuttX, > an public interface to these functions? > > Okay, that was more than one question! Any and all feedback or advice is > welcome. > BTW my requirement for memory mapping is to implement XiP. > > best regards, > > > Martin Klang > > > [1] > > https://github.com/apache/incubator-nuttx/blob/f49a5797213f2ec3fd348e1826db6e080e7be4d9/arch/risc-v/src/esp32c3/rom/esp32c3_spiflash.h#L934 > > [2] > > https://docs.espressif.com/projects/esp-idf/en/release-v3.2/api-reference/storage/spi_flash.html#memory-mapping-apis > > [3] > > https://github.com/apache/incubator-nuttx/blob/master/arch/xtensa/src/esp32/esp32_spiflash.c#L1315 > > -- Gustavo Henrique Nihei