Sunday, July 13, 2014

How to read serial flash chips

Serial flash have become so prevalent in all electronic devices, replacing parallel based ones. Wondering how you can read off the data from them?  The UM232H USB device can be used for this purpose.  It can be purchased from or for $20.  In order to power the device, you need to wire things up based on Section 7.2 of the spec -- the VIO/3v3 and 5VO/USB pins should be shorted accordingly:

To verify the USB device is powered, an LED light should be lighted once you plug a Mini-USB cable to the connector.   If you're using OS X, you can check that the device is connected on USB (system_profiler SPUSBDataType).

          Product ID: 0x6014
          Vendor ID: 0x0403  (Future Technology Devices International Limited)
          Version:  9.00
          Serial Number: FTVRYH0J
          Speed: Up to 480 Mb/sec
          Manufacturer: FTDI
          Location ID: 0x14500000 / 10
          Current Available (mA): 500
          Current Required (mA): 90

In addition to the UM232H device, I ordered the Winbond W25Q serial flash chips from DigiKey, an SOIC to DIP adapter, and a small breadboard with wires to connect the chips.   I originally ordered the Adesco AT45 SPI flash chips from Mouser, but these chips were too wide for the 150mil SOIC to DIP adapter I ordered.  In order to make these chips work, I had to order the 208mil SOIC to DIP adapter, which is currently taking 2-3 weeks from China to arrive.

The pyftdi project provides Python bindings to interface with the UM232H controller, which in turn can send SPI commands to serial flash chips.  What the pyftdi project does is enable MPSSE mode on the UM232H device, which in turn enables pins AD0-AD4 to act as SCK, DI, DO, and CS select signals.   Note the MPSSE column in the UM232H manual:

In order to discern what pins 13-16, I had to look at the circuit schematic, which shows that ADBUS0-ADBUS3 corresponds to the AD0-AD3 pins of the UM232H device.    Note that the UM232H spec also has things listed according to the target device relative to the UM232H device. For instance, TDI/DO, means the wires should run to the DI input of the SPI Flash and match the data output of the UM232H device.  I've included the schematics from the UM232H and the W25Q serial flash chip below:

Using the pyftdi project, I was able to issue the JEDEC command to get the manufacturer and device information back from the chip, which helped confirm that everything was working.  The 0x403 and 0x6014 correspond to the vendor and product ID of the UM232H USB device:

from serialflash import SerialFlashManager
from pyftdi.pyftdi.spi import SpiController

flash = SerialFlashManager.get_flash_device(0x403, 0x6014)
print flash

I had to make a few tweaks to ensure that the JEDEC information could be correctly.  The setup is currently using somewhat long wires between devices, so my goal is to reduce this length since it takes a couple of tries before the device returns the manufacturer ID correctly.

No comments:

Post a Comment