Skip to content
Permalink
master
Switch branches/tags
Go to file
 
 
Cannot retrieve contributors at this time

W25Qxx and W25Xxx Serial NOR Flash

⚠️ Please view the correctly rendered version of this page at https://www.espruino.com/W25. Links, lists, videos, search, and other features will not work correctly when viewed on GitHub ⚠️

  • KEYWORDS: Module,SPI,flash,storage,rom,Winbond,W25,W25X,W25Q,W25Q32,W25Q64,W25X05,W25X10,spiflash

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.js]] module is based on the code in https://github.com/pastaclub/espruino-w25q by Dennis Bemmann and atmelino

Wiring

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.

Initialization

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

etc.

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.)

myflash.erase16Pages(page);

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.erase16Pages(page);
myflash.writePage(page, uint8);
console.log(myflash.readPage(page));

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.erase16Pages(16);
myflash.writeSector(16, mysector);