diff -urN MSPDebugStack_OS_Package.orig/DLL430_v3/src/TI/DLL430/EnergyTrace_TSPA/EnergyTraceProcessorId7.h MSPDebugStack_OS_Package/DLL430_v3/src/TI/DLL430/EnergyTrace_TSPA/EnergyTraceProcessorId7.h
--- MSPDebugStack_OS_Package.orig/DLL430_v3/src/TI/DLL430/EnergyTrace_TSPA/EnergyTraceProcessorId7.h	2014-01-31 12:54:30.000000000 +0100
+++ MSPDebugStack_OS_Package/DLL430_v3/src/TI/DLL430/EnergyTrace_TSPA/EnergyTraceProcessorId7.h	2014-03-29 13:56:51.482910184 +0100
@@ -56,7 +56,7 @@
 #include "EnergyTraceProcessor.h"
 #include "EnergyTraceProcessorJState.h"
 #include <DoubleBuffer.h>
-
+#include <cstdio>
 
 //#define ETLOG
 
diff -urN MSPDebugStack_OS_Package.orig/Makefile MSPDebugStack_OS_Package/Makefile
--- MSPDebugStack_OS_Package.orig/Makefile	2014-01-31 12:54:30.000000000 +0100
+++ MSPDebugStack_OS_Package/Makefile	2014-03-29 13:56:59.762806092 +0100
@@ -22,10 +22,16 @@
 DEFINES += -DNDEBUG
 endif
 
+OS := $(shell uname -s)
+use_system_hidapi := $(shell pkg-config --modversion hidapi-libusb >/dev/null 2>/dev/null && echo 'yes' || echo 'no')
+
 export BOOST_DIR
 export BIT32
 export STATIC
 export DEBUG
+export OS
+export MAKE
+export use_system_hidapi
 
 INCLUDES := \
 	-I./DLL430_v3/src/TI/DLL430 \
@@ -39,6 +45,13 @@
 
 BSLLIB := ./ThirdParty/lib/libbsl430.a
 
+ifeq ($(OS),FreeBSD)
+	INCLUDES += -I/usr/local/include
+	LIBDIRS += -L/usr/local/lib
+else
+	LIBUSBSUFFIX := -1.0
+endif
+
 ifdef BOOST_DIR
 INCLUDES += -I$(BOOST_DIR)
 LIBDIRS += -L$(BOOST_DIR)/stage/lib
@@ -48,13 +61,25 @@
 STATIC_LIBS :=
 
 ifdef STATIC
-STATIC_LIBS += -lboost_thread -lboost_filesystem -lboost_date_time -lboost_system -lbsl430 -lusb-1.0 -lrt
+STATIC_LIBS += -lboost_thread -lboost_filesystem -lboost_date_time -lboost_system -lbsl430 -lusb$(LIBUSBSUFFIX) -lrt
 else
-LIBS += -lboost_thread -lboost_filesystem -lboost_date_time -lboost_system -lbsl430 -lusb-1.0 -lrt
+LIBS += -lboost_thread -lboost_filesystem -lboost_date_time -lboost_system -lbsl430 -lusb$(LIBUSBSUFFIX) -lrt
 endif
 
 LIBS += -lpthread
 
+ifeq ($(use_system_hidapi),yes)
+	INCLUDES += $(shell pkg-config --cflags hidapi-libusb)
+	LIBS += $(shell pkg-config --libs hidapi-libusb)
+	HIDAPI := -lhidapi-libusb
+else
+	HIDAPI := ThirdParty/lib/hid-libusb.o
+endif
+
+ifeq ($(OS),FreeBSD)
+        INCLUDES += -I/usr/local/include
+        LIBDIRS += -L/usr/local/lib
+endif
 
 
 SRC := \
@@ -83,7 +108,7 @@
 OUTPUT := libmsp430.so
 
 all: $(BSLLIB) $(OBJS)
-	$(CXX) $(CXXFLAGS) -shared -Wl,-soname,$(OUTPUT) -o $(OUTPUT) $(OBJS) ThirdParty/lib/hid-libusb.o $(LIBDIRS) -Wl,-Bstatic $(STATIC_LIBS) -Wl,-Bdynamic $(LIBS)
+	$(CXX) $(CXXFLAGS) -shared -Wl,-soname,$(OUTPUT) -o $(OUTPUT) $(OBJS) $(HIDAPI) $(LIBDIRS) -Wl,-Bstatic $(STATIC_LIBS) -Wl,-Bdynamic $(LIBS)
 
 $(PCH_COMPILED): $(PCH_HEADER)
 	$(CXX) -c -o $@ $< $(MAKE_PCH) $(CXXFLAGS) $(INCLUDES) $(DEFINES)
@@ -92,6 +117,9 @@
 	$(CXX) -c -o $@ $< $(USE_PCH) $(CXXFLAGS) $(INCLUDES) $(DEFINES)
 
 $(BSLLIB):
+ifneq ($(HIDAPI),-lhidapi-libusb)
+	$(MAKE) -C ThirdParty
+endif
 	$(MAKE) -C ./ThirdParty/BSL430_DLL
 
 install:
diff -urN MSPDebugStack_OS_Package.orig/ThirdParty/BSL430_DLL/Makefile MSPDebugStack_OS_Package/ThirdParty/BSL430_DLL/Makefile
--- MSPDebugStack_OS_Package.orig/ThirdParty/BSL430_DLL/Makefile	2014-01-31 12:54:30.000000000 +0100
+++ MSPDebugStack_OS_Package/ThirdParty/BSL430_DLL/Makefile	2014-03-29 13:56:51.482910184 +0100
@@ -32,6 +32,15 @@
 
 LIBDIRS :=
 
+ifeq ($(use_system_hidapi),yes)
+	INCLUDES += $(shell pkg-config --cflags hidapi-libusb)
+endif
+
+ifeq ($(OS),FreeBSD)
+	INCLUDES += -I/usr/local/include
+	LIBDIRS += -L/usr/local/lib
+endif
+
 ifdef BOOST_DIR
 INCLUDES += -I$(BOOST_DIR)
 LIBDIRS += -L$(BOOST_DIR)/stage/lib
@@ -48,10 +57,12 @@
 
 OBJS := $(patsubst %.cpp, %.o, $(SRC))
 
-OUTPUT := ../lib/libbsl430.a
+OUTPUT_DIR := ../lib
+OUTPUT := $(OUTPUT_DIR)/libbsl430.a
 
 all: $(OBJS)
-	ar -cq $(OUTPUT) $(OBJS)
+	mkdir -p $(OUTPUT_DIR)
+	ar rcs $(OUTPUT) $(OBJS)
 
 $(PCH_COMPILED): $(PCH_HEADER)
 	$(CXX) -c -o $@ $< $(MAKE_PCH) $(CXXFLAGS) $(INCLUDES) $(DEFINES)
diff -urN MSPDebugStack_OS_Package.orig/ThirdParty/install_thirdparty.sh MSPDebugStack_OS_Package/ThirdParty/install_thirdparty.sh
--- MSPDebugStack_OS_Package.orig/ThirdParty/install_thirdparty.sh	1970-01-01 01:00:00.000000000 +0100
+++ MSPDebugStack_OS_Package/ThirdParty/install_thirdparty.sh	2014-03-29 13:57:08.826692144 +0100
@@ -0,0 +1,51 @@
+#!/bin/sh
+
+cd "$( dirname "${0}" )"
+
+rm -f lib/hid-libusb.o include/hidapi.h
+rm -rf hidapi
+
+git clone https://github.com/signal11/hidapi.git
+cd hidapi
+
+if [ "$( uname -s )" = "FreeBSD" ]
+then
+	# Use libusb_handle_events() instead of libusb_handle_events_completed()
+	# in libusb/hid.c
+	patch -b '' -p1 <<EOF
+diff --git a/libusb/hid.c b/libusb/hid.c
+index 6c1d247..2b4e192 100644
+--- a/libusb/hid.c
++++ b/libusb/hid.c
+@@ -757,7 +757,11 @@ static void *read_thread(void *param)
+ 	libusb_cancel_transfer(dev->transfer);
+ 
+ 	while (!dev->cancelled)
++#if defined(__FreeBSD__)
++		libusb_handle_events(usb_context);
++#else
+ 		libusb_handle_events_completed(usb_context, &dev->cancelled);
++#endif
+ 
+ 	/* Now that the read thread is stopping, Wake any threads which are
+ 	   waiting on data (in hid_read_timeout()). Do this under a mutex to
+EOF
+fi
+
+./bootstrap
+./configure
+${MAKE:-make}
+
+if [ ! -f hidapi/hidapi.h -o ! -f libusb/.libs/hid.o ]
+then
+	echo "hidapi: Build failed"
+	exit 1
+fi
+
+mkdir -p ../include ../lib
+cp hidapi/hidapi.h ../include/hidapi.h && \
+cp libusb/.libs/hid.o ../lib/hid-libusb.o && \
+cd .. && \
+rm -rf hidapi
+echo "hidapi: Build ok (ignore any errors above)"
+:
diff -urN MSPDebugStack_OS_Package.orig/ThirdParty/Makefile MSPDebugStack_OS_Package/ThirdParty/Makefile
--- MSPDebugStack_OS_Package.orig/ThirdParty/Makefile	1970-01-01 01:00:00.000000000 +0100
+++ MSPDebugStack_OS_Package/ThirdParty/Makefile	2014-03-29 13:56:51.486910134 +0100
@@ -0,0 +1,5 @@
+
+all:
+	$(SHELL) install_thirdparty.sh
+
+.PHONY: all
