# Very Slow Flash Writing

**URL:** <https://forums.digi.com/t/very-slow-flash-writing/5200>\
**Category:** NET+OS\
**Created:** [September 18, 2003, 8:31am UTC](https://forums.digi.com/t/very-slow-flash-writing/5200 "2003-09-18T08:31:18Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fredric](https://avatars.discourse-cdn.com/v4/letter/f/f08c70/32.png) [@Fredric](https://forums.digi.com/u/Fredric)\
**Post date:** [September 18, 2003, 8:31am UTC](https://forums.digi.com/t/very-slow-flash-writing/5200/1 "2003-09-18T08:31:18Z")

</div>

When using the flash API in NET+OS for writing data to the flash, it takes extremely long time to complete a write operation (several seconds). This is the case even if you just write one byte. How should one do to reduce this time? As it is now it is completely unusable in a real application. It is of course crucial that this problem is solved very soon. Best Regards, Fredric

---

<div class="post-metadata">

**Author:** ![muscleman](https://avatars.discourse-cdn.com/v4/letter/m/f1d935/32.png) [@muscleman](https://forums.digi.com/u/muscleman)\
**Post date:** [September 18, 2003, 2:12pm UTC](https://forums.digi.com/t/very-slow-flash-writing/5200/2 "2003-09-18T14:12:20Z")

</div>

If the flash is configured in 16 bit mode, we program 2 bytes of data to the flash per command and will require 64K / 2 or 32K write commands to progran the entire sector. If the flash is configured in 32 bit mode, we can program 4 bytes of data to the flash per command and will require (assuming the same 64K bytes sector) (64K / 2) / 2 or 16K write commands to progam the entire sector.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex016/uploads/digi/original/1X/11da31a6a1fbcd03ef21d3f785c317c824009ae2.png) [@system](https://forums.digi.com/u/system)\
**Post date:** [September 20, 2003, 11:30pm UTC](https://forums.digi.com/t/very-slow-flash-writing/5200/3 "2003-09-20T23:30:19Z")

</div>

There are several write options for NAFlashWrite() as described below: ERASE\_AS\_NEEDED  For a full sector write, erases the sector (if necessary) and writes the new data. For a partial sector write, updates the new data but does not destroy the rest of the sector data. ALWAYS\_ERASE  For a full sector write, erases the sector before writing new data. For a partial sector write, updates the new data and erases the rest of the sector. DO\_NOT\_ERASE  Writes new data without first erasing the sector. If the write operation changes a bit from 0 to 1, the function returns NAFLASH\_WRITE\_FAILED. You need to select the appropriate write option for your application.

---

<div class="post-metadata">

**Author:** ![muscleman](https://avatars.discourse-cdn.com/v4/letter/m/f1d935/32.png) [@muscleman](https://forums.digi.com/u/muscleman)\
**Post date:** [September 22, 2003, 1:06pm UTC](https://forums.digi.com/t/very-slow-flash-writing/5200/4 "2003-09-22T13:06:48Z")

</div>

Using our Flash driver, we use a 50us delay after each word (16-bit or 32-bit) write. So if we have a 16-bit flash configuration where one sector is 64K bytes (or 32K words), we can estimate that writing one 16-bit 64K flash sector would take: (50 x 10e-6) x 32768 = 1.6384 seconds. The above number does not take into account the additional overhead of verifying each word write and the overhead of calling the NAFlashWrite() function. Also, writing a whole sector with one NAFlashWrite() is faster than writing a whole sector using multiple NAFlashWrite() calls due to overhead.

---

<div class="post-metadata">

**Author:** ![Fredric](https://avatars.discourse-cdn.com/v4/letter/f/f08c70/32.png) [@Fredric](https://forums.digi.com/u/Fredric)\
**Post date:** [September 22, 2003, 1:34pm UTC](https://forums.digi.com/t/very-slow-flash-writing/5200/5 "2003-09-22T13:34:36Z")

</div>

Hello and thank you for your answers. I have been using the ERASE\_AS\_NEEDED option to make it as convenient as possible to write to the flash without having to worry about what bit patterns are stored in the flash prior to the write. Looking at the code in NAFlashWrite() there is reading, erasing, writing and verifying of at least a whole sector for every call to NAFlashWrite(), even if it is just a one byte write. Obviously this takes a lot of time. I was hoping that it would be possible to reduce this time significantly and still have the convenient ERASE\_AS\_NEEDED functionality. Is it technically possible to do this or not considering the flash technology limitations?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex016/uploads/digi/original/1X/11da31a6a1fbcd03ef21d3f785c317c824009ae2.png) [@system](https://forums.digi.com/u/system)\
**Post date:** [September 22, 2003, 2:25pm UTC](https://forums.digi.com/t/very-slow-flash-writing/5200/6 "2003-09-22T14:25:18Z")

</div>

You have to erase the entire sector if you want to write one byte unless the address at which you are trying to write the data is already erased (all ones).
