1menu "SPI Flash driver"
2
3    config SPI_FLASH_VERIFY_WRITE
4        bool "Verify SPI flash writes"
5        default n
6        help
7            If this option is enabled, any time SPI flash is written then the data will be read
8            back and verified. This can catch hardware problems with SPI flash, or flash which
9            was not erased before verification.
10
11    config SPI_FLASH_LOG_FAILED_WRITE
12        bool "Log errors if verification fails"
13        depends on SPI_FLASH_VERIFY_WRITE
14        default n
15        help
16            If this option is enabled, if SPI flash write verification fails then a log error line
17            will be written with the address, expected & actual values. This can be useful when
18            debugging hardware SPI flash problems.
19
20    config SPI_FLASH_WARN_SETTING_ZERO_TO_ONE
21        bool "Log warning if writing zero bits to ones"
22        depends on SPI_FLASH_VERIFY_WRITE
23        default n
24        help
25            If this option is enabled, any SPI flash write which tries to set zero bits in the flash to
26            ones will log a warning. Such writes will not result in the requested data appearing identically
27            in flash once written, as SPI NOR flash can only set bits to one when an entire sector is erased.
28            After erasing, individual bits can only be written from one to zero.
29
30            Note that some software (such as SPIFFS) which is aware of SPI NOR flash may write one bits as an
31            optimisation, relying on the data in flash becoming a bitwise AND of the new data and any existing data.
32            Such software will log spurious warnings if this option is enabled.
33
34    config SPI_FLASH_ENABLE_COUNTERS
35        bool "Enable operation counters"
36        default 0
37        help
38            This option enables the following APIs:
39
40            - spi_flash_reset_counters
41            - spi_flash_dump_counters
42            - spi_flash_get_counters
43
44            These APIs may be used to collect performance data for spi_flash APIs
45            and to help understand behaviour of libraries which use SPI flash.
46
47    config SPI_FLASH_ROM_DRIVER_PATCH
48        bool "Enable SPI flash ROM driver patched functions"
49        default y
50        help
51            Enable this flag to use patched versions of SPI flash ROM driver functions.
52            This option should be enabled, if any one of the following is true: (1) need to write
53            to flash on ESP32-D2WD; (2) main SPI flash is connected to non-default pins; (3) main
54            SPI flash chip is manufactured by ISSI.
55
56    config SPI_FLASH_ROM_IMPL
57        bool "Use esp_flash implementation in ROM"
58        depends on IDF_TARGET_ESP32S3 || IDF_TARGET_ESP32C3
59        default n
60        help
61            Enable this flag to use new SPI flash driver functions from ROM instead of ESP-IDF.
62
63            If keeping this as "n" in your project, you will have less free IRAM.
64            But you can use all of our flash features.
65
66            If making this as "y" in your project, you will increase free IRAM.
67            But you may miss out on some flash features and support for new flash chips.
68
69            Currently the ROM cannot support the following features:
70
71            - SPI_FLASH_AUTO_SUSPEND (C3, S3)
72
73    choice SPI_FLASH_DANGEROUS_WRITE
74        bool  "Writing to dangerous flash regions"
75        default SPI_FLASH_DANGEROUS_WRITE_ABORTS
76        help
77            SPI flash APIs can optionally abort or return a failure code
78            if erasing or writing addresses that fall at the beginning
79            of flash (covering the bootloader and partition table) or that
80            overlap the app partition that contains the running app.
81
82            It is not recommended to ever write to these regions from an IDF app,
83            and this check prevents logic errors or corrupted firmware memory from
84            damaging these regions.
85
86            Note that this feature *does not* check calls to the esp_rom_xxx SPI flash
87            ROM functions. These functions should not be called directly from IDF
88            applications.
89
90        config SPI_FLASH_DANGEROUS_WRITE_ABORTS
91            bool "Aborts"
92        config SPI_FLASH_DANGEROUS_WRITE_FAILS
93            bool "Fails"
94        config SPI_FLASH_DANGEROUS_WRITE_ALLOWED
95            bool "Allowed"
96    endchoice
97
98    config SPI_FLASH_USE_LEGACY_IMPL
99        bool "Use the legacy implementation before IDF v4.0"
100        default n
101        help
102            The implementation of SPI flash has been greatly changed in IDF v4.0.
103            Enable this option to use the legacy implementation.
104
105    config SPI_FLASH_SHARE_SPI1_BUS
106        bool  "Support other devices attached to SPI1 bus"
107        default n
108        # The bus lock on SPI1 is meaningless when the legacy implementation is used, or the SPI
109        # driver does not support SPI1.
110        depends on !SPI_FLASH_USE_LEGACY_IMPL && !IDF_TARGET_ESP32S2
111        help
112            Each SPI bus needs a lock for arbitration among devices. This allows multiple
113            devices on a same bus, but may reduce the speed of esp_flash driver access to the
114            main flash chip.
115
116            If you only need to use esp_flash driver to access the main flash chip, disable
117            this option, and the lock will be bypassed on SPI1 bus. Otherwise if extra devices
118            are needed to attach to SPI1 bus, enable this option.
119
120    config SPI_FLASH_BYPASS_BLOCK_ERASE
121        bool "Bypass a block erase and always do sector erase"
122        default n
123        help
124            Some flash chips can have very high "max" erase times, especially for block erase (32KB or 64KB).
125            This option allows to bypass "block erase" and always do sector erase commands.
126            This will be much slower overall in most cases, but improves latency for other code to run.
127
128    config SPI_FLASH_YIELD_DURING_ERASE
129        bool "Enables yield operation during flash erase"
130        default y
131        help
132            This allows to yield the CPUs between erase commands.
133            Prevents starvation of other tasks.
134
135    config SPI_FLASH_ERASE_YIELD_DURATION_MS
136        int "Duration of erasing to yield CPUs (ms)"
137        depends on SPI_FLASH_YIELD_DURING_ERASE
138        default 20
139        help
140            If a duration of one erase command is large
141            then it will yield CPUs after finishing a current command.
142
143    config SPI_FLASH_ERASE_YIELD_TICKS
144        int "CPU release time (tick) for an erase operation"
145        depends on SPI_FLASH_YIELD_DURING_ERASE
146        default 1
147        help
148            Defines how many ticks will be before returning to continue a erasing.
149
150    config SPI_FLASH_AUTO_SUSPEND
151        bool "Auto suspend long erase/write operations (READ DOCS FIRST)"
152        default n
153        depends on IDF_TARGET_ESP32C3 && !SPI_FLASH_USE_LEGACY_IMPL && !SPI_FLASH_ROM_IMPL
154        help
155            This option is default n before ESP32-C3, because it needs bootloader support.
156
157            CAUTION: If you want to OTA to an app with this feature turned on, please make
158            sure the bootloader has the support for it. (later than IDF v4.3)
159
160            Auto-suspend feature only supported by XMC chip.
161            If you are using an official module, please contact Espressif Business support.
162            Also reading auto suspend part in `SPI Flash API` document before you enable this function.
163
164    config SPI_FLASH_WRITE_CHUNK_SIZE
165        int "Flash write chunk size"
166        default 8192
167        range 256 8192
168        help
169            Flash write is broken down in terms of multiple (smaller) write operations.
170            This configuration options helps to set individual write chunk size, smaller
171            value here ensures that cache (and non-IRAM resident interrupts) remains
172            disabled for shorter duration.
173
174    config SPI_FLASH_SIZE_OVERRIDE
175        bool "Override flash size in bootloader header by ESPTOOLPY_FLASHSIZE"
176        default n
177        help
178            SPI Flash driver uses the flash size configured in bootloader header by default.
179            Enable this option to override flash size with latest ESPTOOLPY_FLASHSIZE value from
180            the app header if the size in the bootloader header is incorrect.
181
182    config SPI_FLASH_CHECK_ERASE_TIMEOUT_DISABLED
183        bool "Flash timeout checkout disabled"
184        depends on !SPI_FLASH_USE_LEGACY_IMPL
185        default n
186        help
187            This option is helpful if you are using a flash chip whose timeout is quite large or unpredictable.
188
189    config SPI_FLASH_OVERRIDE_CHIP_DRIVER_LIST
190        bool "Override default chip driver list"
191        depends on !SPI_FLASH_USE_LEGACY_IMPL
192        default n
193        help
194            This option allows the chip driver list to be customized, instead of using the default list provided by
195            ESP-IDF.
196
197            When this option is enabled, the default list is no longer compiled or linked. Instead, the
198            `default_registered_chips` structure must be provided by the user.
199
200            See example: custom_chip_driver under examples/storage for more details.
201
202    menu "Auto-detect flash chips"
203        visible if !SPI_FLASH_OVERRIDE_CHIP_DRIVER_LIST
204
205        config SPI_FLASH_SUPPORT_ISSI_CHIP
206            bool "ISSI"
207            default y
208            help
209                Enable this to support auto detection of ISSI chips if chip vendor not directly
210                given by ``chip_drv`` member of the chip struct. This adds support for variant
211                chips, however will extend detecting time.
212
213        config SPI_FLASH_SUPPORT_MXIC_CHIP
214            bool "MXIC"
215            default y
216            help
217                Enable this to support auto detection of MXIC chips if chip vendor not directly
218                given by ``chip_drv`` member of the chip struct. This adds support for variant
219                chips, however will extend detecting time.
220
221        config SPI_FLASH_SUPPORT_GD_CHIP
222            bool "GigaDevice"
223            default y
224            help
225                Enable this to support auto detection of GD (GigaDevice) chips if chip vendor not
226                directly given by ``chip_drv`` member of the chip struct. If you are using Wrover
227                modules, please don't disable this, otherwise your flash may not work in 4-bit
228                mode.
229
230                This adds support for variant chips, however will extend detecting time and image
231                size. Note that the default chip driver supports the GD chips with product ID
232                60H.
233
234        config SPI_FLASH_SUPPORT_WINBOND_CHIP
235            bool "Winbond"
236            default y
237            help
238                Enable this to support auto detection of Winbond chips if chip vendor not directly
239                given by ``chip_drv`` member of the chip struct. This adds support for variant
240                chips, however will extend detecting time.
241
242        config SPI_FLASH_SUPPORT_BOYA_CHIP
243            bool "BOYA"
244            # ESP32 doens't usually use this chip, default n to save iram.
245            default n if IDF_TARGET_ESP32
246            default y
247            help
248                Enable this to support auto detection of BOYA chips if chip vendor not directly
249                given by ``chip_drv`` member of the chip struct. This adds support for variant
250                chips, however will extend detecting time.
251
252        config SPI_FLASH_SUPPORT_TH_CHIP
253            bool "TH"
254            # ESP32 doens't usually use this chip, default n to save iram.
255            default n if IDF_TARGET_ESP32
256            default y
257            help
258                Enable this to support auto detection of TH chips if chip vendor not directly
259                given by ``chip_drv`` member of the chip struct. This adds support for variant
260                chips, however will extend detecting time.
261
262        config SPI_FLASH_SUPPORT_MXIC_OPI_CHIP
263            bool "mxic (opi)"
264            depends on IDF_TARGET_ESP32S3
265            default y
266            help
267                Enable this to support auto detection of Octal MXIC chips if chip vendor not directly
268                given by ``chip_drv`` member of the chip struct. This adds support for variant
269                chips, however will extend detecting time.
270
271    endmenu #auto detect flash chips
272
273    config SPI_FLASH_ENABLE_ENCRYPTED_READ_WRITE
274        bool "Enable encrypted partition read/write operations"
275        default y
276        help
277            This option enables flash read/write operations to encrypted partition/s. This option
278            is kept enabled irrespective of state of flash encryption feature. However, in case
279            application is not using flash encryption feature and is in need of some additional
280            memory from IRAM region (~1KB) then this config can be disabled.
281
282endmenu
283