Does ESP32 erases whole sector while writing a byte to flash

hemant.chaudhari
Posts: 16
Joined: Wed Jun 13, 2018 11:48 am

Does ESP32 erases whole sector while writing a byte to flash

Postby hemant.chaudhari » Fri Jun 29, 2018 5:52 am

Hello,

I am using WROOM32 module which is having 4MB of flash connected to ESP32, I am using "spi_flash_write" API in order to write into the flash. I want to know when I write a byte into flash, does it holds the data into RAM and erases the page and after changing that particular byte the page get written to flash?.
Does it happens every time I change the byte in sector?
What will be the scenario when I am writing continuously to flash byte by byte.

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

Re: Does ESP32 erases whole sector while writing a byte to flash

Postby ESP_Sprite » Fri Jun 29, 2018 11:43 am

No, it does not, it maps directly to the flash function of the flash chip. This means that a write is only able to clear a bit, namely make it go from 1 to 0. As an example how it works: If you erase a sector, the bits all go to 1. If you then write, for example, the first byte to 0xF0, the first byte will become that. If you then write the 2nd byte to 0xAA, the 2nd byte will become that. However, if you write the first byte to 0xAA, the actual value that will be in flash for that byte is 0xA0, as the flash cannot reset the bytes that were already set to 0, back to 1. You'd need to erase the entire 4K sector for that.

All in all, writing the page byte by byte should happily work.

ESP_igrr
Posts: 2072
Joined: Tue Dec 01, 2015 8:37 am

Re: Does ESP32 erases whole sector while writing a byte to flash

Postby ESP_igrr » Fri Jun 29, 2018 1:34 pm

Note that there are some flash chips which contain "software erase" feature, and they do erase one page even if only one byte is written (and therefore allow changing 0 -> 1 without an explicit erase operation). However, at the moment, such flash chips are not used in ESP32 modules produced by Espressif.

hemant.chaudhari
Posts: 16
Joined: Wed Jun 13, 2018 11:48 am

Re: Does ESP32 erases whole sector while writing a byte to flash

Postby hemant.chaudhari » Mon Jul 09, 2018 10:24 am

ok got it....Thanks

So I can use the esp32 wroom 32 flash for continuous data storage without having concern about read/write cycles

Who is online

Users browsing this forum: chegewara and 163 guests