Chapter 2. API Reference
• ESP_ERR_NOT_SUPPORTED if the chip doesn’t support read id.
esp_err_t esp_flash_erase_chip(esp_flash_t *chip)
Erase flash chip contents.
Return
• ESP_OK on success,
• ESP_ERR_NOT_SUPPORTED if the chip is not able to perform the operation. This is indicated
by WREN = 1 after the command is sent.
• Other flash error code if operation failed.
Parameters
• chip: Pointer to identify flash chip. Must have been successfully initialised via esp_flash_init()
esp_err_t esp_flash_erase_region(esp_flash_t *chip, uint32_t start, uint32_t len)
Erase a region of the flash chip.
Sector size is specifyed in chip->drv->sector_size field (typically 4096 bytes.) ESP_ERR_INVALID_ARG
will be returned if the start & length are not a multiple of this size.
Parameters
• chip: Pointer to identify flash chip. Must have been successfully initialised via esp_flash_init()
• start: Address to start erasing flash. Must be sector aligned.
• len: Length of region to erase. Must also be sector aligned.
Erase is performed using block (multi-sector) erases where possible (block size is specified in chip->drv-
>block_erase_size field, typically 65536 bytes). Remaining sectors are erased using individual sector erase
commands.
Return
• ESP_OK on success,
• ESP_ERR_NOT_SUPPORTED if the chip is not able to perform the operation. This is indicated
by WREN = 1 after the command is sent.
• Other flash error code if operation failed.
esp_err_t esp_flash_get_chip_write_protect(esp_flash_t *chip, bool *write_protected)
Read if the entire chip is write protected.
Note A correct result for this flag depends on the SPI flash chip model and chip_drv in use (via the‘chip->drv’
field).
Return ESP_OK on success, or a flash error code if operation failed.
Parameters
• chip: Pointer to identify flash chip. Must have been successfully initialised via esp_flash_init()
• [out] write_protected: Pointer to boolean, set to the value of the write protect flag.
esp_err_t esp_flash_set_chip_write_protect(esp_flash_t *chip, bool write_protect)
Set write protection for the SPI flash chip.
Some SPI flash chips may require a power cycle before write protect status can be cleared. Otherwise, write
protection can be removed via a follow-up call to this function.
Note Correct behaviour of this function depends on the SPI flash chip model and chip_drv in use (via the
‘chip->drv’field).
Parameters
• chip: Pointer to identify flash chip. Must have been successfully initialised via esp_flash_init()
• write_protect: Boolean value for the write protect flag
Return ESP_OK on success, or a flash error code if operation failed.
esp_err_t esp_flash_get_protectable_regions(const esp_flash_t *chip, const
esp_flash_region_t **out_regions, uint32_t
*out_num_regions)
Read the list of individually protectable regions of this SPI flash chip.
Note Correct behaviour of this function depends on the SPI flash chip model and chip_drv in use (via the
‘chip->drv’field).
Return ESP_OK on success, or a flash error code if operation failed.
Espressif Systems 748
Submit Document Feedback
Release v4.4