From a1a1e0740ebc9db87e3d57ba982cc1fef2e020ad Mon Sep 17 00:00:00 2001 From: "Andrew J. Kroll" Date: Sun, 15 Nov 2015 05:22:44 -0500 Subject: [PATCH 1/2] Alternate dynamic linking for Linux --- Makefile-linux-dynamic | 83 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 Makefile-linux-dynamic diff --git a/Makefile-linux-dynamic b/Makefile-linux-dynamic new file mode 100644 index 0000000..53699ba --- /dev/null +++ b/Makefile-linux-dynamic @@ -0,0 +1,83 @@ +CC = gcc + +GITCOUNT = $(shell git rev-list HEAD --count) +UNAME = $(shell uname) +CFLAGS = -Wall -g -O -Ihidapi -DGITCOUNT='"$(GITCOUNT)"' +LDFLAGS = -g + +# Linux +ifeq ($(UNAME),Linux) + LIBS += -lusb-1.0 -lpthread -ludev + HIDSRC = hidapi/hid-libusb.c +endif + +# Mac OS X +ifeq ($(UNAME),Darwin) + LIBS += -framework IOKit -framework CoreFoundation + HIDSRC = hidapi/hid-mac.c + UNIV_ARCHS = $(shell grep '^universal_archs' /opt/local/etc/macports/macports.conf) + ifneq ($(findstring i386,$(UNIV_ARCHS)),) + CC += -arch i386 + endif + ifneq ($(findstring x86_64,$(UNIV_ARCHS)),) + CC += -arch x86_64 + endif +endif + +PROG_OBJS = pic32prog.o target.o executive.o hid.o serial.o \ + adapter-pickit2.o adapter-hidboot.o adapter-an1388.o \ + adapter-bitbang.o adapter-stk500v2.o adapter-uhb.o \ + adapter-an1388-uart.o configure.o \ + family-mx1.o family-mx3.o family-mz.o + +# Olimex ARM-USB-Tiny JTAG adapter: requires libusb-0.1 +CFLAGS += -DUSE_MPSSE +PROG_OBJS += adapter-mpsse.o +ifeq ($(UNAME),Linux) + # Use 'sudo port install libusb-0.1-dev' + LIBS += -lusb +endif +ifeq ($(UNAME),Darwin) + # Use 'sudo port install libusb-legacy' + CFLAGS += -I/opt/local/include/libusb-legacy + LIBS += /opt/local/lib/libusb-legacy/libusb-legacy.a +endif + +all: pic32prog + +pic32prog: $(PROG_OBJS) + $(CC) $(LDFLAGS) -o $@ $(PROG_OBJS) $(LIBS) + +hid.o: $(HIDSRC) + $(CC) $(CFLAGS) -c -o $@ $< + +load: demo1986ve91.srec + pic32prog $< + +adapter-mpsse: adapter-mpsse.c + $(CC) $(LDFLAGS) $(CFLAGS) -DSTANDALONE -o $@ adapter-mpsse.c $(LIBS) + +pic32prog.po: *.c + xgettext --from-code=utf-8 --keyword=_ pic32prog.c target.c adapter-lpt.c -o $@ + +pic32prog-ru.mo: pic32prog-ru.po + msgfmt -c -o $@ $< + +pic32prog-ru-cp866.mo ru/LC_MESSAGES/pic32prog.mo: pic32prog-ru.po + iconv -f utf-8 -t cp866 $< | sed 's/UTF-8/CP866/' | msgfmt -c -o $@ - + cp pic32prog-ru-cp866.mo ru/LC_MESSAGES/pic32prog.mo + +clean: + rm -f *~ *.o core pic32prog adapter-mpsse pic32prog.po + +install: pic32prog #pic32prog-ru.mo + install -c -s pic32prog /usr/local/bin/pic32prog +# install -c -m 444 pic32prog-ru.mo /usr/local/share/locale/ru/LC_MESSAGES/pic32prog.mo +### +adapter-an1388.o: adapter-an1388.c adapter.h hidapi/hidapi.h pic32.h +adapter-hidboot.o: adapter-hidboot.c adapter.h hidapi/hidapi.h pic32.h +adapter-mpsse.o: adapter-mpsse.c adapter.h +adapter-pickit2.o: adapter-pickit2.c adapter.h pickit2.h pic32.h +executive.o: executive.c pic32.h +pic32prog.o: pic32prog.c target.h localize.h +target.o: target.c target.h adapter.h localize.h pic32.h From 4181971b23ef81cfd57e97324176a30479435a3f Mon Sep 17 00:00:00 2001 From: "Andrew J. Kroll" Date: Sun, 15 Nov 2015 05:39:31 -0500 Subject: [PATCH 2/2] Add the all important RTS|DTR toggle to reset UNO32. --- serial.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/serial.c b/serial.c index 26db706..ae09c68 100644 --- a/serial.c +++ b/serial.c @@ -22,6 +22,8 @@ void *alloca(size_t size); #else #include + #include + #include static int fd = -1; static struct termios saved_mode; #endif @@ -238,6 +240,8 @@ int serial_open (const char *devname, int baud_rate, int timeout) COMMTIMEOUTS ctmo; #else struct termios new_mode; + unsigned int ctl; + int rv; #endif timeout_msec = timeout; @@ -337,6 +341,29 @@ int serial_open (const char *devname, int baud_rate, int timeout) int flags = fcntl (fd, F_GETFL, 0); if (flags >= 0) fcntl (fd, F_SETFL, flags & ~O_NONBLOCK); + + rv = ioctl(fd, TIOCMGET, &ctl); + if (rv < 0) { + perror("ioctl(\"TIOCMGET\")"); + return -1; + } + ctl &= ~(TIOCM_DTR | TIOCM_RTS); + rv = ioctl(fd, TIOCMSET, &ctl); + if (rv < 0) { + perror("ioctl(\"TIOCMSET\")"); + return -1; + } + + usleep(250*1000); + + ctl |= (TIOCM_DTR | TIOCM_RTS); + rv = ioctl(fd, TIOCMSET, &ctl); + if (rv < 0) { + perror("ioctl(\"TIOCMSET\")"); + return -1; + } + + usleep(50*1000); #endif return 0; }