Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
12600 Discussions

How long should it take to write to flash?

Altera_Forum
Honored Contributor II
1,386 Views

I am just wondering how long it should take to write to flash, the following line of code takes about 8 seconds to update a 128k block of CFI flash memory. Is this normal? 

 

alt_write_flash 

(fd, 

address, 

(unsigned int*)CONF_RAM_OUTPUT_UCBASE, 

0x20000);
0 Kudos
5 Replies
Altera_Forum
Honored Contributor II
439 Views

Seems somewhat slow. 

I'd expect a moderate fraction of a second - something like 100ms but it is a long time since I've written/used flash writing code.
0 Kudos
Altera_Forum
Honored Contributor II
439 Views

What flash device are you using? 

Usually CFI flash memories have a byte programming time of few us. 

But if I remember correctly alt_write_flash includes the erase sector cycles, even if memory is already blank. Each sector erase may require tens of ms, so you must consider it.
0 Kudos
Altera_Forum
Honored Contributor II
439 Views

Here is the part number that shows up when I use the USB Blaster. 

 

Info: Device 2 CFI Flash 1 is Numonyx JS28F256P33 Bottom Boot (16 bits data bus) 

 

And the settings out of system.h.# define ALT_MODULE_CLASS_cfi_flash altera_avalon_cfi_flash# define CFI_FLASH_HOLD_VALUE 0# define CFI_FLASH_IRQ -1# define CFI_FLASH_IRQ_INTERRUPT_CONTROLLER_ID -1# define CFI_FLASH_NAME "/dev/cfi_flash"# define CFI_FLASH_SETUP_VALUE 80# define CFI_FLASH_SIZE 33554432u# define CFI_FLASH_SPAN 33554432# define CFI_FLASH_TIMING_UNITS "ns"# define CFI_FLASH_TYPE "altera_avalon_cfi_flash"# define CFI_FLASH_WAIT_VALUE 50 

 

The alt_write _flash function appears to compare the memory, erase, then write. If the data to be written is the same as the flash it only takes a fraction of a second, so I assume it only erases and writes the block if necessary. 

 

Is there a formula that I could use to calculate how long a block write should take?
0 Kudos
Altera_Forum
Honored Contributor II
439 Views

If you browse the JS28F256P33 datasheet you will see a couple of seconds may be required for erasing the memory. I think alt_write_flash will erase a block at a time, so you need typically 1.6s. Then, the programming time for 128KB in single word mode (I assume this is what HAL driver uses) is about 5.9s. 

With some extra time due to code and function calls, you obtain your measured 8 seconds, if I calculated correctly. 

If you always need to write the full 128KB content you can greatly improve performance by writing your own flash programming function which exploits full chip erase (typ 0.85s) and programming 32 word buffers (need less than 1s for 128KB).
0 Kudos
Altera_Forum
Honored Contributor II
439 Views

Thanks for the info, I found in the datasheet that typical block erase time is 0.8 seconds and single word writes are typical 150 us. So it looks like 9.8s is typical to write a block. Thanks for the explanation, it looks like I can suggest implementing buffered programming to cut the update time by 20-25 minutes.

0 Kudos
Reply