Erase only 10 bytes from the flash

ningappa BS
Posts: 51
Joined: Sat Mar 17, 2018 4:49 am

Erase only 10 bytes from the flash

Postby ningappa BS » Fri Nov 23, 2018 6:57 am

Hi,

i am accessing flash memory where i read/write/erase but am unable to erase less then 4kB at a time using spi_flash_erase_range() API. In the document mentioned only multiple of 4kB is able to erase but i want to erase let's say 10 bytes means less then 4kB, how do i achieve this. Any other API's to solve this.

Thanks

ESP_Sprite
Posts: 9727
Joined: Thu Nov 26, 2015 4:08 am

Re: Erase only 10 bytes from the flash

Postby ESP_Sprite » Fri Nov 23, 2018 10:57 am

That's not an option, as the flash chip itself does not support it; it's a hard limit in the design of flash chips. Note that flash does allow writes to an un-erased sector; these writes can only change 1s into 0s, not the other way around. Perhaps you can use that to your advantage?

Alternatively, you can read the 4K into memory, change it there to what you want, erase the sector, then write the data back. Do note that this is not safe against power-offs during that operation, and that flash only has a limited amount of erase cycles.

Also, if you only need to erase/write 10 bytes, why not use NVS?

Who is online

Users browsing this forum: Bing [Bot], Cimby1 and 103 guests