[prev in list] [next in list] [prev in thread] [next in thread] 

List:       openocd-development
Subject:    [OpenOCD-devel] [PATCH]: 120c573 Add RaspberryPi interface driver (broken)
From:       gerrit () openocd ! zylin ! com
Date:       2012-07-22 15:41:05
Message-ID: 20120722154105.D86CE2497F () openocd ! zylin ! com
[Download RAW message or body]

This is an automated email from Gerrit.

Paul Fertser (fercerpav@gmail.com) just uploaded a new patch set to Gerrit, which you \
can find at http://openocd.zylin.com/758

-- gerrit

commit 120c5737270b73519fde853fdb906303e86a7c36
Author: Paul Fertser <fercerpav@gmail.com>
Date:   Sun Jul 22 17:28:02 2012 +0400

    Add RaspberryPi interface driver (broken)
    
    This adds support for JTAG programming by bitbanging GPIOs exposed on
    RaspberryPi's expansion header.
    
    Currently not working, with an AVR32 gives 0xf000203f instead of
    0x21e8203f for the ID, on STM32 it gives 0xfffffe11.
    
    I've just connected the RPi pins to the stm32vldiscovery directly,
    without any additional pulls or buffers, so it might be an hardware
    issue too.
    
    I hope to do some more instrumented testing tomorrow, but submitting
    early for some preliminary review. TIA.
    
    Change-Id: Ib78168be27f53c2a3c88c3dd8154d1190c318c78
    Signed-off-by: Paul Fertser <fercerpav@gmail.com>

diff --git a/configure.ac b/configure.ac
index 48e7d64..1dd3f32 100644
--- a/configure.ac
+++ b/configure.ac
@@ -422,11 +422,16 @@ case "${host_cpu}" in
     AC_ARG_ENABLE([at91rm9200],
       AS_HELP_STRING([--enable-at91rm9200], [Enable building support for AT91RM9200 \
based SBCs]),  [build_at91rm9200=$enableval], [build_at91rm9200=no])
+
+    AC_ARG_ENABLE([raspberrypi],
+      AS_HELP_STRING([--enable-raspberrypi], [Enable building support for \
RaspberryPi-based adapter]), +      [build_raspberrypi=$enableval], \
[build_raspberrypi=no])  ;;
 
   *)
     build_ep93xx=no
     build_at91rm9200=no
+    build_raspberrypi=no
     ;;
 esac
 
@@ -656,6 +661,13 @@ else
   AC_DEFINE([BUILD_AT91RM9200], [0], [0 if you don't want at91rm9200.])
 fi
 
+if test $build_raspberrypi = yes; then
+  build_bitbang=yes
+  AC_DEFINE([BUILD_RASPBERRYPI], [1], [1 if you want raspberrypi.])
+else
+  AC_DEFINE([BUILD_RASPBERRYPI], [0], [0 if you don't want raspberrypi.])
+fi
+
 if test x$parport_use_ppdev = xyes; then
   AC_DEFINE([PARPORT_USE_PPDEV], [1], [1 if you want parport to use ppdev.])
 else
@@ -1121,6 +1133,7 @@ AM_CONDITIONAL([ZY1000], [test $build_zy1000 = yes])
 AM_CONDITIONAL([ZY1000_MASTER], [test $build_zy1000_master = yes])
 AM_CONDITIONAL([IOUTIL], [test $build_ioutil = yes])
 AM_CONDITIONAL([AT91RM9200], [test $build_at91rm9200 = yes])
+AM_CONDITIONAL([RASPBERRYPI], [test $build_raspberrypi = yes])
 AM_CONDITIONAL([BITBANG], [test $build_bitbang = yes])
 AM_CONDITIONAL([FT2232_LIBFTDI], [test $build_ft2232_libftdi = yes])
 AM_CONDITIONAL([FT2232_DRIVER], [test $build_ft2232_ftd2xx = yes -o \
                $build_ft2232_libftdi = yes])
diff --git a/doc/openocd.texi b/doc/openocd.texi
index 14772e1..f067c2b 100644
--- a/doc/openocd.texi
+++ b/doc/openocd.texi
@@ -531,6 +531,10 @@ produced, PDF schematics are easily found and it is easy to \
make.  @item @b{at91rm9200}
 @* Like the EP93xx - but an ATMEL AT91RM9200 based solution using the GPIO pins on \
the chip.  
+@item @b{raspberrypi}
+@* The single-board ARM-based computer using the GPIO pins of the
+expansion header.
+
 @end itemize
 
 @node About Jim-Tcl
@@ -2820,7 +2824,6 @@ opendous-jtag is a freely programmable USB adapter.
 
 @deffn {Interface Driver} {ZY1000}
 This is the Zylin ZY1000 JTAG debugger.
-@end deffn
 
 @quotation Note
 This defines some driver-specific commands,
@@ -2831,6 +2834,22 @@ which are not currently documented here.
 Turn power switch to target on/off.
 No arguments: print status.
 @end deffn
+@end deffn
+
+@deffn {Interface Driver} {raspberrypi}
+This is a cheap single-board computer exposing some GPIOs on its
+expansion header. The pin connection is the following:
+
+@multitable {JTAG connector} {RaspberryPi Expansion connector}
+@item JTAG connector @tab RaspberryPi Expansion connector
+@item TDI @tab pin 19
+@item TDO @tab pin 21
+@item TCK @tab pin 23
+@item TMS @tab pin 22
+@item TRST @tab pin 26
+@item SRST @tab pin 18
+@end multitable
+@end deffn
 
 @section Transport Configuration
 @cindex Transport
diff --git a/src/jtag/drivers/Makefile.am b/src/jtag/drivers/Makefile.am
index 0ce06ee..9ae494f 100644
--- a/src/jtag/drivers/Makefile.am
+++ b/src/jtag/drivers/Makefile.am
@@ -107,6 +107,9 @@ endif
 if OPENDOUS
 DRIVERFILES += opendous.c
 endif
+if RASPBERRYPI
+DRIVERFILES += raspberrypi.c
+endif
 
 noinst_HEADERS = \
 	bitbang.h \
diff --git a/src/jtag/drivers/raspberrypi.c b/src/jtag/drivers/raspberrypi.c
new file mode 100644
index 0000000..a6858b2
--- /dev/null
+++ b/src/jtag/drivers/raspberrypi.c
@@ -0,0 +1,164 @@
+/***************************************************************************
+ *   Copyright (C) 2012 by Paul Fertser                                    *
+ *   fercerpav@gmail.com                                                   *
+ *                                                                         *
+ *   Based on at91rm9200.c (c) Anders Larsen                               *
+ *   and RPi GPIO examples by Gert van Loo & Dom                           *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
+ ***************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <jtag/interface.h>
+#include "bitbang.h"
+
+#include <sys/mman.h>
+
+#define TDI_PIO		10	/* pin 19 */
+#define TDO_PIO		9	/* pin 21 */
+#define TCK_PIO		11	/* pin 23 */
+#define TMS_PIO		25	/* pin 22 */
+#define TRST_PIO	7	/* pin 26 */
+#define SRST_PIO	24	/* pin 18 */
+
+#define BCM2708_PERI_BASE	0x20000000
+#define BCM2708_GPIO_BASE	(BCM2708_PERI_BASE + 0x200000) /* GPIO controller */
+
+// GPIO setup macros. Always use INP_GPIO(x) before using OUT_GPIO(x) or \
SET_GPIO_ALT(x,y) +#define INP_GPIO(g) *(pio_base+((g)/10)) &= ~(7<<(((g)%10)*3))
+#define OUT_GPIO(g) *(pio_base+((g)/10)) |=  (1<<(((g)%10)*3))
+
+#define GPIO_SET *(pio_base+7)  // sets   bits which are 1, ignores bits which are 0
+#define GPIO_CLR *(pio_base+10) // clears bits which are 1, ignores bits which are 0
+#define GPIO_LEV *(pio_base+13) // current level of the pin
+
+static int dev_mem_fd;
+static volatile uint32_t *pio_base;
+
+static int raspberrypi_read(void);
+static void raspberrypi_write(int tck, int tms, int tdi);
+static void raspberrypi_reset(int trst, int srst);
+
+static int raspberrypi_speed(int speed);
+static int raspberrypi_init(void);
+static int raspberrypi_quit(void);
+
+static struct bitbang_interface raspberrypi_bitbang = {
+	.read = raspberrypi_read,
+	.write = raspberrypi_write,
+	.reset = raspberrypi_reset,
+	.blink = NULL
+};
+
+static int raspberrypi_read(void)
+{
+	return !!(GPIO_LEV & 1<<TDO_PIO);
+}
+
+static void raspberrypi_write(int tck, int tms, int tdi)
+{
+	if (tck)
+		GPIO_SET = 1<<TCK_PIO;
+	else
+		GPIO_CLR = 1<<TCK_PIO;
+
+	if (tms)
+		GPIO_SET = 1<<TMS_PIO;
+	else
+		GPIO_CLR = 1<<TMS_PIO;
+
+	if (tdi)
+		GPIO_SET = 1<<TDI_PIO;
+	else
+		GPIO_CLR = 1<<TDI_PIO;
+}
+
+/* (1) assert or (0) deassert reset lines */
+static void raspberrypi_reset(int trst, int srst)
+{
+	if (trst)
+		GPIO_CLR = 1<<TRST_PIO;
+	else
+		GPIO_SET = 1<<TRST_PIO;
+
+	if (srst)
+		GPIO_CLR = 1<<SRST_PIO;
+	else
+		GPIO_SET = 1<<SRST_PIO;
+}
+
+static int raspberrypi_speed(int speed)
+{
+	return ERROR_OK;
+}
+
+struct jtag_interface raspberrypi_interface = {
+	.name = "raspberrypi",
+	.execute_queue = bitbang_execute_queue,
+	.speed = raspberrypi_speed,
+	.transports = jtag_only,
+	.init = raspberrypi_init,
+	.quit = raspberrypi_quit,
+};
+
+static int raspberrypi_init(void)
+{
+	bitbang_interface = &raspberrypi_bitbang;
+
+	dev_mem_fd = open("/dev/mem", O_RDWR | O_SYNC);
+	if (dev_mem_fd < 0) {
+		perror("open");
+		return ERROR_JTAG_INIT_FAILED;
+	}
+
+	pio_base = mmap(NULL, 4096, PROT_READ | PROT_WRITE,
+				MAP_SHARED, dev_mem_fd, BCM2708_GPIO_BASE);
+
+	if (pio_base == MAP_FAILED) {
+		perror("mmap");
+		close(dev_mem_fd);
+		return ERROR_JTAG_INIT_FAILED;
+	}
+
+	/*
+	 * Configure TDO as an input, and TDI, TCK, TMS, TRST, SRST
+	 * as outputs.  Drive TDI and TCK low, and TMS/TRST/SRST high.
+	 */
+	INP_GPIO(TDO_PIO);
+
+	GPIO_CLR = 1<<TDI_PIO | 1<<TCK_PIO;
+	GPIO_SET = 1<<TMS_PIO | 1<<TRST_PIO | 1<<SRST_PIO;
+	INP_GPIO(TDI_PIO);
+	OUT_GPIO(TDI_PIO);
+	INP_GPIO(TCK_PIO);
+	OUT_GPIO(TCK_PIO);
+	INP_GPIO(TMS_PIO);
+	OUT_GPIO(TMS_PIO);
+	INP_GPIO(TRST_PIO);
+	OUT_GPIO(TRST_PIO);
+	INP_GPIO(SRST_PIO);
+	OUT_GPIO(SRST_PIO);
+
+	return ERROR_OK;
+}
+
+static int raspberrypi_quit(void)
+{
+	return ERROR_OK;
+}
diff --git a/src/jtag/interfaces.c b/src/jtag/interfaces.c
index 4b054be..45bcc32 100644
--- a/src/jtag/interfaces.c
+++ b/src/jtag/interfaces.c
@@ -113,6 +113,9 @@ extern struct jtag_interface osbdm_interface;
 #if BUILD_OPENDOUS == 1
 extern struct jtag_interface opendous_interface;
 #endif
+#if BUILD_RASPBERRYPI == 1
+extern struct jtag_interface raspberrypi_interface;
+#endif
 #endif /* standard drivers */
 
 /**
@@ -194,6 +197,9 @@ struct jtag_interface *jtag_interfaces[] = {
 #if BUILD_OPENDOUS == 1
 		&opendous_interface,
 #endif
+#if BUILD_RASPBERRYPI == 1
+		&raspberrypi_interface,
+#endif
 #endif /* standard drivers */
 		NULL,
 	};
diff --git a/tcl/interface/raspberrypi.cfg b/tcl/interface/raspberrypi.cfg
new file mode 100644
index 0000000..5d1039f
--- /dev/null
+++ b/tcl/interface/raspberrypi.cfg
@@ -0,0 +1,5 @@
+# RaspberryPi expansion header GPIOs directly used for JTAG
+
+interface raspberrypi
+# dummy setting to silence the warning
+adapter_khz 1000

-- 

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
OpenOCD-devel mailing list
OpenOCD-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openocd-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic