1# Common (non-chip-specific) SPIRAM options
2#
3# sourced into the "SPIRAM config" submenu for a specific chip.
4
5config SPIRAM_BOOT_INIT
6    bool "Initialize SPI RAM during startup"
7    default "y"
8    help
9        If this is enabled, the SPI RAM will be enabled during initial boot. Unless you
10        have specific requirements, you'll want to leave this enabled so memory allocated
11        during boot-up can also be placed in SPI RAM.
12
13config SPIRAM_IGNORE_NOTFOUND
14    bool "Ignore PSRAM when not found"
15    default "n"
16    depends on SPIRAM_BOOT_INIT && !SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY
17    help
18        Normally, if psram initialization is enabled during compile time but not found at runtime, it
19        is seen as an error making the CPU panic. If this is enabled, booting will complete
20        but no PSRAM will be available.
21
22choice SPIRAM_USE
23    prompt "SPI RAM access method"
24    default SPIRAM_USE_MALLOC
25    help
26        The SPI RAM can be accessed in multiple methods: by just having it available as an unmanaged
27        memory region in the CPU's memory map, by integrating it in the heap as 'special' memory
28        needing heap_caps_malloc to allocate, or by fully integrating it making malloc() also able to
29        return SPI RAM pointers.
30
31    config SPIRAM_USE_MEMMAP
32        bool "Integrate RAM into memory map"
33    config SPIRAM_USE_CAPS_ALLOC
34        bool "Make RAM allocatable using heap_caps_malloc(..., MALLOC_CAP_SPIRAM)"
35    config SPIRAM_USE_MALLOC
36        bool "Make RAM allocatable using malloc() as well"
37        select FREERTOS_SUPPORT_STATIC_ALLOCATION
38endchoice
39
40config SPIRAM_MEMTEST
41    bool "Run memory test on SPI RAM initialization"
42    default "y"
43    depends on SPIRAM_BOOT_INIT
44    help
45        Runs a rudimentary memory test on initialization. Aborts when memory test fails. Disable this for
46        slightly faster startup.
47
48config SPIRAM_MALLOC_ALWAYSINTERNAL
49    int "Maximum malloc() size, in bytes, to always put in internal memory"
50    depends on SPIRAM_USE_MALLOC
51    default 16384
52    range 0 131072
53    help
54        If malloc() is capable of also allocating SPI-connected ram, its allocation strategy will prefer to
55        allocate chunks less than this size in internal memory, while allocations larger than this will be
56        done from external RAM. If allocation from the preferred region fails, an attempt is made to allocate
57        from the non-preferred region instead, so malloc() will not suddenly fail when either internal or
58        external memory is full.
59
60config SPIRAM_TRY_ALLOCATE_WIFI_LWIP
61    bool "Try to allocate memories of WiFi and LWIP in SPIRAM firstly. If failed, allocate internal memory"
62    depends on SPIRAM_USE_CAPS_ALLOC || SPIRAM_USE_MALLOC
63    default "n"
64    help
65        Try to allocate memories of WiFi and LWIP in SPIRAM firstly. If failed, try to allocate internal
66        memory then.
67
68config SPIRAM_MALLOC_RESERVE_INTERNAL
69    int "Reserve this amount of bytes for data that specifically needs to be in DMA or internal memory"
70    depends on SPIRAM_USE_MALLOC
71    default 32768
72    range 0 262144
73    help
74        Because the external/internal RAM allocation strategy is not always perfect, it sometimes may happen
75        that the internal memory is entirely filled up. This causes allocations that are specifically done in
76        internal memory, for example the stack for new tasks or memory to service DMA or have memory that's
77        also available when SPI cache is down, to fail. This option reserves a pool specifically for requests
78        like that; the memory in this pool is not given out when a normal malloc() is called.
79
80        Set this to 0 to disable this feature.
81
82        Note that because FreeRTOS stacks are forced to internal memory, they will also use this memory pool;
83        be sure to keep this in mind when adjusting this value.
84
85        Note also that the DMA reserved pool may not be one single contiguous memory region, depending on the
86        configured size and the static memory usage of the app.
87
88config SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY
89    bool "Allow .bss segment placed in external memory"
90    default n
91    depends on SPIRAM
92    select ESP_ALLOW_BSS_SEG_EXTERNAL_MEMORY
93    help
94        If enabled, variables with EXT_RAM_BSS_ATTR attribute will be placed in SPIRAM instead of internal DRAM.
95        BSS section of `lwip`, `net80211`, `pp`, `bt` libraries will be automatically placed
96        in SPIRAM. BSS sections from other object files and libraries can also be placed in SPIRAM through
97        linker fragment scheme `extram_bss`.
98
99        Note that the variables placed in SPIRAM using EXT_RAM_BSS_ATTR will be zero initialized.
100
101config SPIRAM_ALLOW_NOINIT_SEG_EXTERNAL_MEMORY
102    bool "Allow .noinit segment placed in external memory"
103    default n
104    depends on SPIRAM && IDF_TARGET_ESP32
105    help
106        If enabled, noinit variables can be placed in PSRAM using EXT_RAM_NOINIT_ATTR.
107
108        Note the values placed into this section will not be initialized at startup and should keep its value
109        after software restart.
110
111config SPIRAM_ECC_ENABLE
112    bool "Enable SPI RAM ECC"
113    default n
114    depends on SPIRAM_MODE_OCT && IDF_TARGET_ESP32S3
115    help
116        Enable MSPI Error-Correcting Code function when accessing SPIRAM.
117
118        If enabled, 1/16 of the SPI RAM total size will be reserved for error-correcting code.
119