Chapter 2. API Reference
following lines after the idf_component_register, in the CMakeLists.txt file of the custom_chip_driver compo-
nent:
idf_component_get_property(spi_flash_lib
set_property(TARGET
FACE_LINK_LIBRARIES $<LINK_ONLY:${COMPONENT_LIB}>)
5. The linker.lf is used to put every chip driver that you are going to use whilst cache is disabled into internal
RAM. See
Linker Script Generation
6. Build your project, and you will see the new flash driver is used.
Example
See also storage/custom_flash_driver.
Initializing a flash device
To use esp_flash_* APIs, you need to have a chip initialized on a certain SPI bus.
1. Call
spi_bus_initialize()
(I/O, DMA, interrupts) shared among devices attached to this bus.
2. Call
spi_bus_add_flash_device()
and fill the members for the esp_flash_t structure. The CS I/O is also initialized here.
3. Call
esp_flash_init()
influence the following operations.
Note: Multiple flash chips can be attached to the same bus now. However, using esp_flash_* devices and
spi_device_* devices on the same SPI bus is not supported yet.
SPI flash access API
This is the set of API functions for working with data in flash:
•
esp_flash_read()
•
esp_flash_write()
•
esp_flash_erase_region()
•
esp_flash_erase_chip()
• esp_flash_get_chip_size() returns flash chip size, in bytes, as configured in menuconfig
Generally, try to avoid using the raw SPI flash functions to the "main"SPI flash chip in favour of
functions.
SPI Flash Size
The SPI flash size is configured by writing a field in the software bootloader image header, flashed at offset 0x1000.
By default, the SPI flash size is detected by esptool.py when this bootloader is written to flash, and the header
is updated with the correct size. Alternatively, it is possible to generate a fixed flash size by setting CON-
FIG_ESPTOOLPY_FLASHSIZE in project configuration.
If it is necessary to override the configured flash size at runtime, it is possible to set the chip_size member of
the g_rom_flashchip structure. This size is used by esp_flash_* functions (in both software & ROM) to
check the bounds.
Concurrency Constraints for flash on SPI1
Concurrency Constraints for flash on SPI1
(for firmware execution) and the SPI1 peripheral (controlled by the drivers including this SPI Flash driver). Hence,
operations to SPI1 will cause significant influence to the whole system. This kind of operations include calling SPI
Espressif Systems
${spi_flash_lib}
for more details. Make sure this file covers all the source files that you add.
to properly initialize an SPI bus. This functions initialize the resources
to attach the flash device onto the bus. This allocates memory,
to actually communicate with the chip. This will also detect the chip type, and
reads data from flash to RAM
writes data from RAM to flash
erases specific region of flash
erases the whole flash
The SPI0/1 bus is shared between the instruction & data cache
742
Submit Document Feedback
spi_flash
COMPONENT_LIB)
APPEND
PROPERTY
INTER-
partition-specific
Release v4.4
Need help?
Do you have a question about the ESP32-S2 and is the answer not in the manual?