Skip to content

Commit

Permalink
Added proper support for specifying an alternate serial port to all G…
Browse files Browse the repository at this point in the history
…umbi subclasses. Also added auto-detection code to find the appropriate serial port if none is specified.
  • Loading branch information
heffnercj committed Aug 23, 2012
1 parent a8d9789 commit 761483b
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 12 deletions.
33 changes: 33 additions & 0 deletions docs/INSTALL
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
PREREQUISITES

The Gumbi API is written in Python, and requires no additional modules
outside of those included with the standard Python installation.

The firmware is written in C, and must be built for the AVR architecture;
thus, you must have the AVR cross-compiler and toolchain installed on
your system in order to build the firmware.

To install the firmware via the Makefile, you must also have the dfu-programmer
utility installed. Alternately, you can install the firmware using the
Atmel Flip utility.

The majority of the API code is platform independant, and should work on
most systems; currently however, it has only been tested under Linux.

INSTALLATION PROCEDURES

To install the Gumbi API modules and associated Gumbi utilities:

$ cd src/python
$ ./configure
# make

To install the firmware onto the Gumbi board:

$ cd src/avr
$ make
# make install

Note that prior to installing the Gumbi board firmware, you must first
put the board into programming mode, by shorting the two RESET pins while
also shorting the two PROGRAM pins together.
6 changes: 6 additions & 0 deletions src/python/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,11 @@ data:
cp bin/config/* $(FLASHCONFDIR)/

clean:
rm -f gumbi/*.pyc
rm -rf *.cache config.* build
rm -f Makefile

uninstall:
rm -f $(BINDIR)/gumbictl
rm -f $(BINDIR)/flashbin
rm -rf $(FLASHCONFDIR)
13 changes: 10 additions & 3 deletions src/python/bin/flashbin.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ def EraseChip(self):

CONFIG_PATH = "bin/config/"
CONF_EXT = '.conf'
PORT = None

def wordflip(data):
"""
Expand Down Expand Up @@ -125,6 +124,7 @@ def usage():
print "\t-a, --address=<int> Specify the starting address [0]"
print "\t-s, --size=<int> Specify the number of bytes to read/write"
print "\t-f, --word-flip=<file> Word-flip the contents of the specified file"
print "\t-P, --port=<port> Set the Gumbi board's virtual serial port [/dev/ttyACM0]"
print "\t-p, --path=<path> Set the path to the chip configuration files [%s]" % CONFIG_PATH
print "\t-v, --verbose Enabled verbose output"
print "\t-h, --help Show help"
Expand All @@ -145,13 +145,14 @@ def usage():
doerase = False
verbose = False
chip = None
port = None
infile = None
config = None
outfile = None
flipfile = None

try:
opts, args = GetOpt(sys.argv[1:], "iela:s:r:w:c:f:p:vh", ["id", "erase", "list", "address=", "size=", "read=", "write=", "chip=", "word-flip=", "--path=", "help"])
opts, args = GetOpt(sys.argv[1:], "iela:s:r:w:c:f:P:p:vh", ["id", "erase", "list", "address=", "size=", "read=", "write=", "chip=", "word-flip=", "port=", "path=", "verbose", "help"])
except GetoptError, e:
print e
usage()
Expand Down Expand Up @@ -179,6 +180,8 @@ def usage():
open("%s.flip" % flipfile, "wb").write(wordflip(open(arg, "rb").read()))
print "File saved to: %s.flip" % arg
sys.exit(0)
elif opt in ('-P', '--port'):
port = arg
elif opt in ('-p', '--path'):
CONFIG_PATH = arg + '/'
elif opt in ('-v', '--verbose'):
Expand All @@ -193,6 +196,10 @@ def usage():
print "Please specify the chip type!"
usage()

if len(ACTIONS) == 0:
print "Please specify an action (id, read, write, etc)!"
usage()

for action in ACTION_LIST:

if ACTIONS.has_key(action):
Expand All @@ -202,7 +209,7 @@ def usage():
sys.stdout.write("Connecting to Gumbi board...")
sys.stdout.flush()

flash = NORFlash(config=config, port=PORT)
flash = NORFlash(config=config, port=port)

if verbose:
print "connected."
Expand Down
4 changes: 2 additions & 2 deletions src/python/gumbi/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class Configuration(Gumbi):
"VOLTAGE" : [None]
}

def __init__(self, config, mode):
def __init__(self, config, mode, port=None):
"""
Class initializer. Must be called BEFORE Gumbi.SetMode so that it can retrieve the current pin count from the Gumbi board.
Expand All @@ -143,7 +143,7 @@ def __init__(self, config, mode):
self.package_pins = 0
self.pins_shifted = False

Gumbi.__init__(self)
Gumbi.__init__(self, port=port)

# Get the number of available pins on the Gumbi board
self.num_pins = self.PinCount()
Expand Down
2 changes: 1 addition & 1 deletion src/python/gumbi/gpio.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def __init__(self, config=None, voltage=None, port=None):
Returns None.
"""
self.config = Configuration(config, self.MODE)
self.config = Configuration(config, self.MODE, port)
Gumbi.__init__(self, port=port)
if voltage is not None:
self.SetVoltage(voltage)
Expand Down
26 changes: 21 additions & 5 deletions src/python/gumbi/gumbi.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Gumbi:
NULL = "\x00"
DUMMY_BYTE = "\xFF"
SERIAL_PORT = "/dev/ttyACM0"

TBP_DEFAULT = 25
TOE_DEFAULT = 0

Expand Down Expand Up @@ -81,17 +81,33 @@ def __init__(self, port=None, new=True):
self.port = port
self.num_pins = 0

if self.port is None:
self.port = self.SERIAL_PORT

if new:
self._open()

def _open(self):
"""
Opens a connection to the Gumbi board. For internal use only.
"""
self.serial = serial.Serial(self.port)

if self.port is not None:
self.serial = serial.Serial(self.port)
else:
n = 0
last_error = ''
prefix = self.SERIAL_PORT[:-1]

while n < 10:
try:
self.port = prefix + str(n)
self.serial = serial.Serial(self.port)
break
except Exception, e:
last_error = str(e)
n += 1
self.port = None

if self.port is None:
raise Exception(last_error)

def _exit(self):
"""
Expand Down
2 changes: 1 addition & 1 deletion src/python/gumbi/parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def __init__(self, config=None, voltage=None, port=None):
Returns None.
"""
self.config = Configuration(config, self.MODE)
self.config = Configuration(config, self.MODE, port)
Gumbi.__init__(self, port=port)
if voltage is not None:
self.SetVoltage(voltage)
Expand Down

0 comments on commit 761483b

Please sign in to comment.