Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

Not applicable

Using SDK 3.1.2 and the Macronix MX25Lxxxx series of flash, you may have noticed that write operation is very slow.

Bytes are in fact written one by one, with a lots of overhead on the SPI, here is how to speed it up:

spi_flash.c in sflash_write()

Line 163 change:

max_write_size = (unsigned int) 1;  /* TODO: this should be 256, but that causes write errors */


max_write_size = (unsigned int) 256;

and later, line 197 replace:

write_size = ( size > max_write_size )? max_write_size : size;


if (device_address % max_write_size) {

     /* Not on a page boundary, limit write within the page*/

     unsigned int nbBytesLeftOnPage = max_write_size - (device_address % max_write_size);

     write_size = (size > nbBytesLeftOnPage) ? nbBytesLeftOnPage : size;

} else {

     /* Page boundary, write as many bytes as we can */

     write_size = size > max_write_size ? max_write_size : size;


Message was edited by: Guillaume Brivet Fix logic when write is not page-aligned

1 Reply
Not applicable

There is another optimization possible, add a "sflash_erase_range()" API and erase blocks instead of sector when possible, it does make a bit faster, but this is not as dramatic as the write change above. (3000ms to erase 600KB instead of 4500ms with current driver).