aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarti Bolivar <mbolivar@mit.edu>2010-08-29 20:29:31 -0400
committerMarti Bolivar <mbolivar@mit.edu>2010-08-29 20:29:31 -0400
commit42fd9fdf2db14f4f442c409c4fbd4ac6e9ce9a51 (patch)
tree3c83fbfb8b0d8fa3f0ed03a127427e08e0e396c0
parentb10ef4875fb5a48cf6c702a36b7a0bf6d84c5f78 (diff)
downloadlibrambutan-42fd9fdf2db14f4f442c409c4fbd4ac6e9ce9a51.tar.gz
librambutan-42fd9fdf2db14f4f442c409c4fbd4ac6e9ce9a51.zip
Toolchain improvements
Updated Makefile to read the directory where libmaple is from the environment variable LIBMAPLE_PATH, if it exists, defaulting to the current working directory otherwise. Updated reset.py to look around in /dev for the Maple serial port, prompting the user if there appear to be multiple possibilities and complaining if there aren't any.
-rw-r--r--Makefile23
-rwxr-xr-xsupport/scripts/reset.py60
2 files changed, 53 insertions, 30 deletions
diff --git a/Makefile b/Makefile
index b1858c7..590e6d1 100644
--- a/Makefile
+++ b/Makefile
@@ -4,9 +4,14 @@ BOARD ?= maple
MAPLE_TARGET ?= flash
# Useful paths
+ifeq ($(LIB_MAPLE_HOME),)
SRCROOT := $(dir)
+else
+SRCROOT := $(LIB_MAPLE_HOME)
+endif
BUILD_PATH = build
-LIBMAPLE_PATH := libmaple
+LIBMAPLE_PATH := $(SRCROOT)/libmaple
+SUPPORT_PATH := $(SRCROOT)/support
# Useful variables
GLOBAL_CFLAGS := -Os -g -mcpu=cortex-m3 -mthumb -march=armv7-m -nostdlib \
@@ -14,14 +19,14 @@ GLOBAL_CFLAGS := -Os -g -mcpu=cortex-m3 -mthumb -march=armv7-m -nostdlib \
GLOBAL_CXXFLAGS := -fno-rtti -fno-exceptions -Wall
-LDDIR := support/ld
+LDDIR := $(SUPPORT_PATH)/ld
LDFLAGS = -T$(LDDIR)/$(LDSCRIPT) -L$(LDDIR) \
-mcpu=cortex-m3 -mthumb -Xlinker \
--gc-sections --print-gc-sections --march=armv7-m -Wall
# Set up build rules and some useful templates
-include support/make/build-rules.mk
-include support/make/build-templates.mk
+include $(SUPPORT_PATH)/make/build-rules.mk
+include $(SUPPORT_PATH)/make/build-templates.mk
# Maple USB id
VENDOR_ID := 1EAF
@@ -42,22 +47,22 @@ ifeq ($(MAPLE_TARGET), jtag)
endif
# Set all submodules here
-LIBMAPLE_MODULES := libmaple
-LIBMAPLE_MODULES += wirish
+LIBMAPLE_MODULES := $(SRCROOT)/libmaple
+LIBMAPLE_MODULES += $(SRCROOT)/wirish
# call each module rules.mk
$(foreach m,$(LIBMAPLE_MODULES),$(eval $(call LIBMAPLE_MODULE_template,$(m))))
# Main target
-include support/make/build-targets.mk
+include $(SUPPORT_PATH)/make/build-targets.mk
.PHONY: install sketch clean help debug cscope tags ctags ram flash jtag
# Target upload commands
-UPLOAD_ram := support/scripts/reset.py && \
+UPLOAD_ram := $(SUPPORT_PATH)/scripts/reset.py && \
sleep 1 && \
$(DFU) -a0 -d $(VENDOR_ID):$(PRODUCT_ID) -D $(BUILD_PATH)/$(BOARD).bin -R
-UPLOAD_flash := support/scripts/reset.py && \
+UPLOAD_flash := $(SUPPORT_PATH)/scripts/reset.py && \
sleep 1 && \
$(DFU) -a1 -d $(VENDOR_ID):$(PRODUCT_ID) -D $(BUILD_PATH)/$(BOARD).bin -R
UPLOAD_jtag := $(OPENOCD) -f support/openocd/flash.cfg
diff --git a/support/scripts/reset.py b/support/scripts/reset.py
index 7cafefc..9be5607 100755
--- a/support/scripts/reset.py
+++ b/support/scripts/reset.py
@@ -1,25 +1,25 @@
#!/usr/bin/python
-# NOTE: On Mac OSX this script must be run as sudo?
-
import serial
import os
import sys
from struct import pack
-def get_maple_device_path_osx():
- """Try to find the device file for the Maple on OS X. If there
- are multiple possibilities, ask the user what to do. If the user
- chooses not to say, returns None."""
- possible_maple_paths = [x for x in os.listdir('/dev') if \
- 'tty.usbmodem' in x]
- if len(possible_maple_paths) == 1:
- return possible_maple_paths[0]
+def get_maple_device_path(file_prefix):
+ """Try to find the device file for the Maple on OS X; assuming
+ that it looks like /dev/<file_prefix>*. If there are multiple
+ possibilities, ask the user what to do. If the user chooses not
+ to say, returns None."""
+ possible_paths = [os.path.join('/dev', x) for x in os.listdir('/dev') \
+ if x.startswith(file_prefix)]
+ if len(possible_paths) == 0:
+ return None
+ elif len(possible_paths) == 1:
+ return possible_paths[0]
else:
- print 'Attempting to reset Maple, but found multiple ' + \
- 'candidates for the Maple device:'
- for (i,p) in enumerate(possible_maple_paths):
- print '\t%d. %s' % (i+1,os.path.join('/dev',p))
+ print 'Found multiple candidates for the Maple device:'
+ for (i,p) in enumerate(possible_paths):
+ print '\t%d. %s' % (i+1, p)
prompt = 'Enter a number to select one, or q to quit: '
while True:
@@ -31,20 +31,37 @@ def get_maple_device_path_osx():
except ValueError:
pass
else:
- if 0 <= i-1 < len(possible_maple_paths):
- return os.path.join('/dev',possible_maple_paths[i-1])
+ if 0 <= i-1 < len(possible_paths):
+ return possible_paths[i-1]
+
prompt = 'Please enter a number from the list, or q to quit: '
os_sysname = os.uname()[0]
if os_sysname == 'Linux':
- maple_path = '/dev/maple'
+ maple_path = get_maple_device_path('ttyACM')
+ # fall back on /dev/maple if that doesn't work
+ if maple_path is None:
+ maple_path = '/dev/maple'
+ print 'Could not find Maple serial port; defaulting to /dev/maple.'
elif os_sysname == 'Darwin':
- maple_path = get_maple_device_path_osx()
- if maple_path is None: sys.exit()
+ maple_path = get_maple_device_path('tty.usbmodem')
else:
- # TODO [mbolivar] special cases for windows, BSD, whatever?
+ # TODO [mbolivar] what to do for windows, BSD, whatever?
maple_path = '/dev/maple'
+if maple_path is None:
+ print 'Could not find the Maple serial port for reset.', \
+ 'Perhaps this is your first upload, or the board is already', \
+ 'in bootloader mode.'
+ print
+ print "If your sketch doesn't upload, try putting your Maple", \
+ 'into bootloader mode manually by pressing the RESET button', \
+ 'then letting it go and quickly pressing button BUT', \
+ '(hold for several seconds).'
+ sys.exit()
+
+print 'Using %s as Maple serial port' % maple_path
+
try:
ser = serial.Serial(maple_path, baudrate=115200, xonxoff=1)
ser.open()
@@ -65,5 +82,6 @@ try:
ser.close()
except:
- print "Failed to open the serial port for reset, perhaps this is your first upload or the board was already in bootloader mode"
+ print 'Failed to open serial port %s for reset.' % maple_path
+ sys.exit()