How do I write to SPI flash memory?

If you are simply looking for a way to program the Winbond SPI flash with "pre-loaded" data that your microcontroller would read for use when it is running then what you will want to look into is a programmer that can do in-circuit programming of the SPI Flash chip. This also known as in-system-programming (ISP).

One choice is the programmer from DediProg. This USB connected device can program in circuit if you design your board correctly. They even sell an adapter clip that can attach into the SOW-16 package without having to design in a separate programming header on your board. DediProg has application information bulletins available to help with correct design for in circuit use. The main strategy for the design is to find a simple way to isolate the SPI interface drivers in your MCU system so that they do not interfere with the drivers in the SPI programming pod. The simplest way to do this is to put series resistors in the MCU driven lines between the MCU and the SPI Flash. The programmer would connect on the SPI flash side of the series resistors. Alternate methods could include adding a MUX or analog switches in the driven interface lines. An even more clever scheme is to add a "programming enable" input to the MCU that makes the software disconnect all the SPI I/Os from the SPI Flash chip (i.e. make all those GPIOs as inputs).

enter image description here

A second choice to also consider is the USB programer from ASIX. The Presto is able to do various types of SPI and I2C devices including SPI Flash devices. I have one of these devices specifically for programming Atmel MCUs and various types of SPI Flash devices. It is a more cost effective solution than the above unit but not quite as flexible. Their more expensive device called the Forte is able to do more things because it has more target interface pins.

enter image description here

Sometimes it can be beneficial to be able to connect a programmmer to a target board without having to add a programming header. One nice solution for this is to place a small set of pads in a special footprint defined by a company called TagConnect. They manufacture and sell a series of quick connect programming cables that have pogo pins that engage the special footprint on the board. There are 6-pin, 10-pin and 14-pin versions of the cable available to suit a range of applications. Cost of the cables are very reasonable.

enter image description here


I bet you could do it with a Bus Pirate without going through your MCU... that lets you perform somewhat arbitrary serial interactions directly to a chip using SPI, I2C, or UART communication. It might take a bit of work to "script" it, but it would let you do the job probably.

I've also seen specialized tools for loading EEPROM's over I2C directly, but not flash and not SPI specifically.


I have never heard of any other tools talking SPI directly to such a chip, and I think it is impossible since "all" chips require different calls for different operations.

The chip needs SPI calls for write, read, change sector, data size etc. Under 7.2 Instructions chapter in the datasheet you can see all the SPI commands you can send to it. Hence, since all external flash memories does not have the same instruction set, you need to write a customized application for this one.

EDIT: Being a follow up, I would really recommend one of Atmels own SPI flash memories, since most of them already has written open available code for them. Looking at this post from AVRFreaks will provide you with code for some of Atmels AT45xxxx serial flash chips.