From 1570f3cbdda721952271eeef8f96bdb5364c6690 Mon Sep 17 00:00:00 2001 From: Daniel Beer Date: Tue, 9 Nov 2010 09:16:31 +1300 Subject: [PATCH] Support for Olimex MSP430-JTAG-ISO. --- AUTHORS | 4 ++++ main.c | 25 +++++++++++++++++++++++-- mspdebug.man | 2 ++ uif.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++---- uif.h | 8 +++++++- 5 files changed, 85 insertions(+), 7 deletions(-) diff --git a/AUTHORS b/AUTHORS index 72b6c09..91c7370 100644 --- a/AUTHORS +++ b/AUTHORS @@ -41,3 +41,7 @@ Andrew Armenia : James Laird : * Support for CC430F5133. + +Stefan Mahr : + * Initial support, testing and analysis for Olimex + MSP430-JTAG-ISO. diff --git a/main.c b/main.c index 9dd4085..a9c1b31 100644 --- a/main.c +++ b/main.c @@ -174,7 +174,7 @@ static device_t driver_open_olimex(const struct cmdline_args *args) transport_t trans; if (args->serial_device) - trans = uif_open(args->serial_device, 1); + trans = uif_open(args->serial_device, UIF_TYPE_OLIMEX); else trans = olimex_open(args->usb_device); @@ -184,6 +184,23 @@ static device_t driver_open_olimex(const struct cmdline_args *args) return driver_open_fet(args, FET_PROTO_OLIMEX, trans); } +static device_t driver_open_olimex_iso(const struct cmdline_args *args) +{ + transport_t trans; + + if (!args->serial_device) { + printc_err("This driver does not support USB access. " + "Specify a tty device using -d.\n"); + return NULL; + } + + trans = uif_open(args->serial_device, UIF_TYPE_OLIMEX_ISO); + if (!trans) + return NULL; + + return driver_open_fet(args, FET_PROTO_OLIMEX, trans); +} + static device_t driver_open_sim(const struct cmdline_args *args) { return sim_open(fetch_io, store_io, NULL); @@ -199,7 +216,7 @@ static device_t driver_open_uif(const struct cmdline_args *args) return NULL; } - trans = uif_open(args->serial_device, 0); + trans = uif_open(args->serial_device, UIF_TYPE_FET); if (!trans) return NULL; @@ -239,6 +256,10 @@ static const struct driver driver_table[] = { .help = "Olimex MSP-JTAG-TINY.", .func = driver_open_olimex }, + { .name = "olimex-iso", + .help = "Olimex MSP-JTAG-ISO.", + .func = driver_open_olimex_iso + }, { .name = "sim", .help = "Simulation mode.", diff --git a/mspdebug.man b/mspdebug.man index e13a9f8..d17f44d 100644 --- a/mspdebug.man +++ b/mspdebug.man @@ -71,6 +71,8 @@ Connect to an eZ430-RF2500 device. Only USB connection is supported. .IP "\fBolimex\fR" Connect to an Olimex MSP-JTAG-TINY device. Both USB and tty access are supported. +.IP "\fBolimex-iso\fR" +Connect to an Olimex MSP-JTAG-ISO device. Only tty access is supported. .IP "\fBsim\fR" Do not connect to any hardware device, but instead start in simulation mode. A 64k buffer is allocated to simulate the device memory. The CPU diff --git a/uif.c b/uif.c index 5b8f052..627f98e 100644 --- a/uif.c +++ b/uif.c @@ -25,6 +25,10 @@ #include #include +#include +#include +#include + #include "uif.h" #include "util.h" #include "output.h" @@ -81,7 +85,35 @@ static void serial_destroy(transport_t tr_base) free(tr); } -transport_t uif_open(const char *device, int is_olimex) +static int open_olimex_iso(const char *device) +{ + int fd = open(device, O_RDWR | O_NOCTTY); + struct termios attr; + struct serial_struct serial_info; + + if (fd < 0) + return -1; + + tcgetattr(fd, &attr); + cfmakeraw(&attr); + cfsetispeed(&attr, B38400); + cfsetospeed(&attr, B38400); + + serial_info.flags = ASYNC_SPD_CUST; + serial_info.custom_divisor = 120; + if (ioctl(fd, TIOCSSERIAL, &serial_info) < 0) { + printc_err("open_olimex_iso: can't do ioctl TIOCSSERIAL: %s\n", + strerror(errno)); + return -1; + } + + if (tcsetattr(fd, TCSAFLUSH, &attr) < 0) + return -1; + + return fd; +} + +transport_t uif_open(const char *device, uif_type_t type) { struct uif_transport *tr = malloc(sizeof(*tr)); @@ -94,10 +126,23 @@ transport_t uif_open(const char *device, int is_olimex) tr->base.recv = serial_recv; tr->base.destroy = serial_destroy; - printc("Trying to open %s on %s...\n", - is_olimex ? "Olimex" : "UIF", device); + switch (type) { + case UIF_TYPE_FET: + printc("Trying to open UIF on %s...\n", device); + tr->serial_fd = open_serial(device, B460800); + break; + + case UIF_TYPE_OLIMEX: + printc("Trying to open Olimex on %s...\n", device); + tr->serial_fd = open_serial(device, B500000); + break; + + case UIF_TYPE_OLIMEX_ISO: + printc("Trying to open Olimex (ISO) on %s...\n", device); + tr->serial_fd = open_olimex_iso(device); + break; + } - tr->serial_fd = open_serial(device, is_olimex ? B500000 : B460800); if (tr->serial_fd < 0) { printc_err("uif: can't open serial device: %s: %s\n", device, strerror(errno)); diff --git a/uif.h b/uif.h index 77a37f7..9ada015 100644 --- a/uif.h +++ b/uif.h @@ -21,10 +21,16 @@ #include "transport.h" +typedef enum { + UIF_TYPE_FET, + UIF_TYPE_OLIMEX, + UIF_TYPE_OLIMEX_ISO +} uif_type_t; + /* This function is for opening an eZ430-F2013 or FET430UIF device via * a kernel-supported serial interface. The argument given should be the * filename of the relevant tty device. */ -transport_t uif_open(const char *device, int is_olimex); +transport_t uif_open(const char *device, uif_type_t type); #endif