Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added functions for chip status and chip reset. #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 39 additions & 2 deletions src/examples/spiflash.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@ class SPIFlash(object):
WECMD = "\x06" # Standard SPI flash write enable command (0x06)
CECMD = "\xc7" # Standard SPI flash chip erase command (0xC7)
IDCMD = "\x9f" # Standard SPI flash chip ID command (0x9F)
STCMD = "\x05" # winbond w25q256 status register
RSTENCMD = "\x66" # winbond w25q256 reset enable command
RSTCMD = "\x99" # winbond w25q256 reset command

ID_LENGTH = 3 # Normal SPI chip ID length, in bytes
ST_LENGTH = 2 # status register-1 length, in bytes
ADDRESS_LENGTH = 3 # Normal SPI flash address length (24 bits, aka, 3 bytes)
BLOCK_SIZE = 256 # SPI block size, writes must be done in multiples of this size
PP_PERIOD = .025 # Page program time, in seconds
PP_PERIOD = .003 # Page program time, in seconds

def __init__(self, speed=FIFTEEN_MHZ):

Expand Down Expand Up @@ -83,6 +87,22 @@ def ChipID(self):
self.flash.Stop()
return chipid

def Status(self):
self.flash.Start()
self.flash.Write(self.STCMD)
chipstatus = self.flash.Read(self.ST_LENGTH)
self.flash.Stop()
return chipstatus

def Reset(self):
print "Sending reset."
self.flash.Start()
self.flash.Write(self.RSTENCMD)
self.flash.Stop()
self.flash.Start()
self.flash.Write(self.RSTCMD)
self.flash.Stop()

def Close(self):
self.flash.Close()

Expand Down Expand Up @@ -123,6 +143,8 @@ def usage():
print "\t-v, --verify Verify data that has been read/written"
print "\t-e, --erase Erase the entire chip"
print "\t-p, --pin-mappings Display a table of SPI flash to FTDI pin mappings"
print "\t-b, Status (busy)"
print "\t-x, Reset"
print "\t-h, --help Show help"
print ""

Expand All @@ -138,7 +160,7 @@ def main():
data = ""

try:
opts, args = GetOpt(sys.argv[1:], "f:s:a:r:w:eipvh", ["frequency=", "size=", "address=", "read=", "write=", "id", "erase", "verify", "pin-mappings", "help"])
opts, args = GetOpt(sys.argv[1:], "f:s:a:r:w:eipvhbx", ["frequency=", "size=", "address=", "read=", "write=", "id", "erase", "verify", "pin-mappings", "help", "status", "reset"])
except GetoptError, e:
print e
usage()
Expand All @@ -158,6 +180,10 @@ def main():
fname = arg
elif opt in ('-i', '--id'):
action = "id"
elif opt in ('-b', '--status'):
action = "status"
elif opt in ('-x', '--reset'):
action = "reset"
elif opt in ('-e', '--erase'):
action = "erase"
elif opt in ('-v', '--verify'):
Expand Down Expand Up @@ -205,6 +231,17 @@ def main():
print ("%.2X" % ord(byte)),
print ""

elif action == "status":

for byte in spi.Status():
print ("%.2X" % ord(byte)),
print ""

elif action == "reset":

spi.Reset()
print "Sent reset."

elif action == "erase":

data = "\xFF" * size
Expand Down