Wednesday, January 14, 2009

Programming Flash Chips

I dug some Flash chips off a few old motherboards, and I wondered how difficult they would be to interface? It turns out, it's not that difficult at all.

I was lucky though. Some flash and eeprom chips require high voltage to be able to program, this one I have here requires only 5v. It's a 39SF020 flash chip. So how to program it with the Arduino?

The first problem to solve is accessing all the pins from the Arduino. The flash chip has 18 address pins, 8 data pins and 3 control pins. The Arduino just doesn't have this many pins, so you have to extend the Arduino's capabilities a little.

So I draw up a little schematic using some serial in parallel out (SIPO) shift registers. A SIPO shift register is a number of cascaded or chain flip flops. The input of the first flip flop in the chain is exposed to you, however the input of the other flip flops are connected to the output of the flip flop preceeding it in the chain. Also, the output of the final flip flop in the chip is also exposed on a pin, so you can use it to chain another chip onto the end of that chip. Each flip flop also drives an output pin, so the state of the flip flops are always being output. Using flip flops, you can change 2 pins (1 for data to the flip flops, another to clock it all) into literally as many as you want.

My first attempt at designing this on paper was a big mistake. I decided I'd try to use as few pins as possible from the Arduino. I chained up 4 shift registers to reach all data and address pins using only two pins. However, I realized that the data bus is bi-directional, the data bus has to be both read and written. In order to do that, I had to manipulate the output latch of the shift register on the data bus so it'll go into high impedence mode when I need to read it. Then, since I didn't want to use many pins on the Arduino, I also used a parallel in serial out shift register to read the data bus. It would have worked this way, but it would have taken 5 chips in total, and that won't fit on a proto board at all.

It was much easier to use just 2 shift registers to reach 16 of the address pins, and then use pins on the Arduino for everything else. It takes only two chips, but it uses just about every single pin the Arduino has, including re-assigning the analog pins to digital pins. And the best part, it'll fit onto a shield without too much work. A little work to overcome the non-standard spacing of the Arduino's pin headers, and I have all the stuff I need (except the ZIF socket and shift registers) in my junk bin.

As for programming the chips, it's pretty easy. Programming the chip involves putting commands on the data and address pins, pulsing some of the control pins low and waiting a set amount of time. That part looks pretty easy.

I'm pretty sure I'll be able to program all kinds of chips with this as well. There's a JEDEC standard that ensures the pinouts and command codes are the same for these chips. I looked at the datasheet for a similar chip made by AMD, and it all looked very familiar. I think any differences (except if the chip needs 12v to program) will be in software.

One more thing to note: shift registers are slow. It takes time to shift out 16 bits. Not much time, but if timing is really important, shift registers might not be the right thing to use. Another option is the octal latch. An octal latch has 8 inputs, 8 output and a latch pin. When you pulse the latch pin high, it will latch the 8 input pins into the inputs of 8 flip flops attached to the output pins. Using just 8 pins on the Arduino plus one pin for every latch chip you need, you can achieve much faster outputs.

There's even more options here as well. One chip made by Microchip uses the i2c bus to provide 2 8-pin bi-directional ports for just 2 pins. Multiple chips can be on the same i2c bus as well, provided you use a few more (up to 3) pins to define which chip you're addressing. This is a much more sophisticated option, and much more flexible. However, shift registers are easy to understand and can be as cheap as 25 cents each.

No comments: