W25Qxx and W25Xxx Serial NOR Flash

Winbond W25Qxx and W25Xxx chips (eg. W25Q32, W25Q64, W25X05, etc) are SPI flash memory chips with capacities ranging from 512K-bit to 512M-bit.

This W25 (About Modules) module is based on the code in https://github.com/pastaclub/espruino-w25q by Dennis Bemmann and atmelino


W25Q Espruino WiFi wiring

Find out which pins of your Espruino are SPI-capable. Connect the SPI pins to the corresponding pins on the W25Q Flash memory, add GND, and 3.3v, and a pin for Chip Select (CS) which can be connected to any IO.

Note: Software SPI may also be used but is just slightly slower.


var W25 = require("W25");
var myflash = new W25(SPI1, B6 /*CS*/);
SPI1.setup({ mosi: B5, miso: B4, sck: B3});

The memory of the W25Q Flash is organized in pages of 256 bytes each, and sectors of 16 pages each.

Sector Start Page End Page
0 0 15
1 16 31
2 32 47


Preparation for Writing

Before you can write to Flash memory, you must first erase the flash memory at the address which you want to write to. In the case of Winbond WQ25, individual bytes or pages cannot be erased-the minimum quantity that can be erased is a sector(16 pages at once.)


Note: If you send a command to erase a section with a page number in between start and end, the sector in which the page is will be erased. For example: If you send a command to erase at page 5, then pages 0 to 15 will be erased.

Writing and Reading

var page = 345;
const uint8 = new Uint8Array(256);
uint8.fill(101, 0, 256);        //(value, start position, end position);
myflash.writePage(page, uint8);

Sector Modification

If you want to modify data in a sector without losing the rest of the data of the sector, you would have to first read the sector into an array, modify the array, and then write the (modified) array back to the flash memory.

var mysector = myflash.readSector(1);
mysector[123] = 72;
myflash.writeSector(16, mysector);

This page is auto-generated from GitHub. If you see any mistakes or have suggestions, please let us know.