arduino mx25l 4mb flash

The above image is a MX25L3205 4MB flash chip mounted on a stripboard breakout. It was salvaged from a laptop motherboard that had been water damaged (a couple of the bigger power transistors were melted along with some burn marks where I presume tracks used to be).
I carefully desoldered it and measured it against a small, scrap piece of stripboard. The original plan was to bug wire it but as the inner legs happen to have the same spacing as the stripboard tracks I just needed to bend the outer legs first up so they were now flat rather than pointing down and then out into an L shape, so that when on the stripboard the tips would just be above next track along. A single blob of solder was used on an inner leg to position and hold the it in place while the others were soldered. To minimise the likely-hood of shorts - and particularly on the outer legs - I tried to use only just enough solder to let the surface tension touch the tips. It's not beautiful but as my first attempt to solder an SMD part I'm quite pleased with the result - and there were no shorts either!

The arduino is connected over the SPI bus, but as the MX25L3205 is a 3.3v part the three output pins (SCK/yellow, MOSI/green, SS/blue) are put through voltage dividers (1.8KOhm/3.3KOhm) to protect it. As 3.3v is above the threshold needed for the arduino to register a line as high, MISO/orange is just directly connected.
Pin configuration:

- CS - SS/D10
- SO - MISO/D12
- WP/ACC - 3.3v
- GND
- VCC - 3.3v
- HOLD - 3.3v
- SCLK - SCK/D13
- SI - MOSI/D11
With the hardware side completed I wrote some simple code to issue the 'read identification'/RDID command. It took some minor tweaks to get the data I was expecting but once I got 0xC2, 0x20, 0x15 I knew the chip was good.
I suspected that it was the dead laptop's bios chip so decided next to dump the contents to a file to find out. For this I implemented the READ command and pushed the results to the PC via the arduino's serial. It took a while to dump the whole 4 MB - the method I used was less than optimal - but running the dump file through strings produced this snippet:
?d?d?d?dn
... DEBUG BUFFER OVERFLOW!!!
EFI_LOAD_ERROR
EFI_INVALID_PARAMETER
EFI_UNSUPPORTED
EFI_BAD_BUFFER_SIZE
EFI_BUFFER_TOO_SMALL
EFI_NOT_READY
EFI_DEVICE_ERROR
EFI_WRITE_PROTECTED
EFI_OUT_OF_RESOURCES
EFI_VOLUME_CORRUPTED
EFI_VOLUME_FULL
Which seems to confirm it's an EFI bios. Also in there was:
9p?-
w(mA
DELL
0102$DELG
Inspiron N5010
$BV#
A02$DI$G
I've extended the code out to be interactively command driven, and implemented enough commands to be able to read and write to it. The currently available commands are:
h : print help
d : print RDID
s : print RDSR
u<x> <y> : dump from x for y bytes
w : WREN (write enable)
i : WRDI (write disable)
c : CE (chip erase)
e<sector>: SE (sector erase)
b<block> : BE (block erase)
q<x> <y> : PP write byte y at address x
The code expects 'Newline' to be selected in the arduino serial monitor. Where a parameter is required you can use any notation strtol() allows e.g. to dump the first ten bytes both "u0 10" and "u0x00 0x0a" will work. To write to the chip you first need to issue a 'write enable'/WREN command and then a 'program page'/PP. Be aware that PP only flips bits to 0, it doesn't flip them to 1 because of this it's recommended you erase the chip(CE)/sector(SE)/block(BE) before writing. For more information please see the datasheet.
/*
MX25L3205D
Requires PC side sending \n (Newline) as line ending
*/
#include <SPI.h>
const int slaveSelectPin = 10;
void setup() {
Serial.begin(9600);
pinMode (slaveSelectPin, OUTPUT);
// initialize SPI:
SPI.begin();
SPI.setDataMode(SPI_MODE3);
SPI.setBitOrder(MSBFIRST);
}
void Print_Help(){
Serial.println(" h : print help");
Serial.println(" d : print RDID");
Serial.println(" s : print RDSR");
Serial.println(" u<x> <y> : dump from x for y bytes");
Serial.println(" w : WREN (write enable)");
Serial.println(" i : WRDI (write disable)");
Serial.println(" c : CE (chip erase)");
Serial.println(" e<sector>: SE (sector erase)");
Serial.println(" b<block> : BE (block erase)");
Serial.println(" q<x> <y> : PP write byte y at address x");
}
unsigned long SerialReadLongUntil(char until){
String s;
char c = 0;
while(c != until){
if(Serial.available() > 0){
c = Serial.read();
s += c;
}
}
char buf[16];
s.toCharArray(buf, 16);
return (unsigned long)strtol(buf, NULL, 0);
}
void loop() {
if (Serial.available() > 0) {
switch(Serial.read()){
case 'h':
Print_Help();
break;
case 'd':
Print_RDID();
break;
case 's':
Print_RDSR();
break;
case 'u': { //some validation would be nice...
unsigned long start = SerialReadLongUntil(' ');
unsigned long len = SerialReadLongUntil('\n');
Dump(start, len);
break;
}
case 'w':
WREN();
break;
case 'i':
WRDI();
break;
case 'c':
CE();
break;
case 'e': {
unsigned long addr = SerialReadLongUntil('\n');
_SE(addr);
break;
}
case 'b': {
unsigned long addr = SerialReadLongUntil('\n');
BE(addr);
break;
}
case 'q': { //write a single byte
unsigned long addr = SerialReadLongUntil(' ');
byte val = SerialReadLongUntil('\n');
WritePP1(addr, val);
Dump(addr, 1);
break;
}
}
}
}
/*
(6) Read Data Bytes (READ)
The read instruction is for reading data out. The address is latched on rising edge of SCLK, and data shifts out on the falling
edge of SCLK at a maximum frequency fR. The first address byte can be at any location. The address is automatically
increased to the next higher address after each byte data is shifted out, so the whole memory can be read out at a single
READ instruction. The address counter rolls over to 0 when the highest address has been reached.
The sequence of issuing READ instruction is: CS# goes low-> sending READ instruction code-> 3-byte address on SI
-> data out on SO-> to end READ operation can use CS# to high at any time during data out. (see Figure. 17)
*/
void READ(){
digitalWrite(slaveSelectPin,LOW);
SPI.transfer(0x03); //READ
SPI.transfer(0x00); // start at 0x000000
SPI.transfer(0x00);
SPI.transfer(0x00);
unsigned long addr = 0x000000;
while(addr <= 0x3FFFFF){ //3FFFFFh 32 Mb
byte val = SPI.transfer(0x00);
Serial.println(val, HEX);
addr++;
}
digitalWrite(slaveSelectPin,HIGH);
}
/*
(3) Read Identification (RDID)
The RDID instruction is for reading the manufacturer ID of 1-byte and followed by Device ID of 2-byte. The MXIC
Manufacturer ID is C2(hex), the memory type ID is 20(hex) as the first-byte device ID, and the individual device ID of
second-byte ID are listed as table of "ID Definitions".
The sequence of issuing RDID instruction is: CS# goes low-> sending RDID instruction code -> 24-bits ID data out on SO
-> to end RDID operation can use CS# to high at any time during data out. (see Figure. 14)
While Program/Erase operation is in progress, it will not decode the RDID instruction, so there's no effect on the cycle of
program/erase operation which is currently in progress. When CS# goes high, the device is at standby stage.
*/
void RDID(byte *manufacturerID, byte *memorytypeID, byte *memory){
digitalWrite(slaveSelectPin,LOW);
SPI.transfer(0x9f);
*manufacturerID = SPI.transfer(0x00);
*memorytypeID = SPI.transfer(0x00);
*memory = SPI.transfer(0x00);
digitalWrite(slaveSelectPin,HIGH);
}
void Print_RDID(){
byte manufacturerID, memorytypeID, memory;
RDID(&manufacturerID, &memorytypeID, &memory);
Serial.print("manufacturerID: ");
Serial.println(manufacturerID, HEX);
Serial.print("memorytypeID: ");
Serial.println(memorytypeID, HEX);
Serial.print("memory: ");
Serial.println(memory, HEX);
}
/*
(4) Read Status Register (RDSR)
The RDSR instruction is for reading Status Register Bits. The Read Status Register can be read at any time (even in
program/erase/write status register condition) and continuously. It is recommended to check the Write in Progress (WIP)
bit before sending a new instruction when a program, erase, or write status register operation is in progress.
The sequence of issuing RDSR instruction is: CS# goes low-> sending RDSR instruction code-> Status Register data out
on SO (see Figure. 15)
*/
void RDSR(byte *rdsr){
digitalWrite(slaveSelectPin,LOW);
SPI.transfer(0x05);
*rdsr = SPI.transfer(0x00);
digitalWrite(slaveSelectPin,HIGH);
}
void Print_RDSR(){
byte rdsr = 0;
RDSR(&rdsr);
Serial.print("WIP : ");
Serial.println(rdsr & 1);
Serial.print("WEL : ");
Serial.println(rdsr >> 1 & 1);
Serial.print("BP0 : ");
Serial.println(rdsr >> 2 & 1);
Serial.print("BP1 : ");
Serial.println(rdsr >> 3 & 1);
Serial.print("BP2 : ");
Serial.println(rdsr >> 4 & 1);
Serial.print("BP3 : ");
Serial.println(rdsr >> 5 & 1);
Serial.print("CP : ");
Serial.println(rdsr >> 6 & 1);
Serial.print("SRWD: ");
Serial.println(rdsr >> 7 & 1);
}
/*
(1) Write Enable (WREN)
The Write Enable (WREN) instruction is for setting Write Enable Latch (WEL) bit. For those instructions like PP, CP, SE,
BE, CE, and WRSR, which are intended to change the device content, should be set every time after the WREN instruction
setting the WEL bit.
The sequence of issuing WREN instruction is: CS# goes low-> sending WREN instruction code-> CS# goes high. (see
Figure 12)
*/
void WREN(){
digitalWrite(slaveSelectPin,LOW);
SPI.transfer(0x06);
digitalWrite(slaveSelectPin,HIGH);
}
/*
The Write Disable (WRDI) instruction is for resetting Write Enable Latch (WEL) bit.
The sequence of issuing WRDI instruction is: CS# goes low-> sending WRDI instruction code-> CS# goes high. (see Figure
13)
*/
void WRDI(){
digitalWrite(slaveSelectPin,LOW);
SPI.transfer(0x04);
digitalWrite(slaveSelectPin,HIGH);
}
/* chip erase */
void CE(){
digitalWrite(slaveSelectPin,LOW);
SPI.transfer(0x60);
digitalWrite(slaveSelectPin,HIGH);
}
/* sector erase */
//needs the damn underscore as SE is defined elsewhere...
void _SE(unsigned long addr){
digitalWrite(slaveSelectPin,LOW);
SPI.transfer(0xd8);
SPI.transfer(addr >> 16 & 0xff);
SPI.transfer(addr >> 8 & 0xff);
SPI.transfer(addr & 0xff);
digitalWrite(slaveSelectPin,HIGH);
}
/* block erase */
void BE(unsigned long addr){
digitalWrite(slaveSelectPin,LOW);
SPI.transfer(0xd8);
SPI.transfer(addr >> 16 & 0xff);
SPI.transfer(addr >> 8 & 0xff);
SPI.transfer(addr & 0xff);
digitalWrite(slaveSelectPin,HIGH);
}
void PP(){
digitalWrite(slaveSelectPin,LOW);
SPI.transfer(0x02);
SPI.transfer(0x00); // start at 0x000000
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer('A');
SPI.transfer('B');
SPI.transfer('C');
SPI.transfer('D');
SPI.transfer('E');
SPI.transfer('F');
SPI.transfer('G');
SPI.transfer('H');
SPI.transfer('I');
SPI.transfer('J');
SPI.transfer('K');
digitalWrite(slaveSelectPin,HIGH);
}
void DumpStart(unsigned long count){
digitalWrite(slaveSelectPin,LOW);
SPI.transfer(0x03); //READ
SPI.transfer(0x00); // start at 0x000000
SPI.transfer(0x00);
SPI.transfer(0x00);
unsigned long addr = 0x000000;
while(addr < count){ //3FFFFFh 32 Mb
byte val = SPI.transfer(0x00);
Serial.print(addr, HEX);
Serial.print('\t');
Serial.print('\t');
Serial.print(val, HEX);
Serial.print('\t');
Serial.println(char(val));
addr++;
//delay(100);
}
digitalWrite(slaveSelectPin,HIGH);
}
void Dump(unsigned long addr, unsigned long count){
digitalWrite(slaveSelectPin,LOW);
SPI.transfer(0x03); //READ
SPI.transfer(addr >> 16 & 0xff);
SPI.transfer(addr >> 8 & 0xff);
SPI.transfer(addr & 0xff);
count = addr + count;
while(addr < count){ //3FFFFFh 32 Mb
byte val = SPI.transfer(0x00);
Serial.print(addr, HEX);
Serial.print('\t');
Serial.print('\t');
Serial.print(val, HEX);
Serial.print('\t');
Serial.println(char(val));
addr++;
}
digitalWrite(slaveSelectPin,HIGH);
}
void WritePP1(unsigned long addr, byte val){
digitalWrite(slaveSelectPin,LOW);
SPI.transfer(0x02);
SPI.transfer(addr >> 16 & 0xff);
SPI.transfer(addr >> 8 & 0xff);
SPI.transfer(addr & 0xff);
SPI.transfer(val);
digitalWrite(slaveSelectPin,HIGH);
}
I've left a couple of unexposed functions in the code (PP(), DumpStart() and READ()) as they might be useful if someone needs to extend it any further.