libftdi Archives

Subject: Understanding the jtag/mpsse example

From: Vaughan Moss <vaughan@xxxxxxxxx>
To: libftdi@xxxxxxxxxxxxxxxxxxxxxxx
Date: Mon, 26 Jul 2010 11:43:55 +0200
Hi,

I am experimenting using libftdi to implement jtag in our project to try and get away from using the expensive jtag tools each manufacturer wants to sell with their respective chips. We are hoping to place an ft2232h chip on our board and have one interface to do all the testing and/or programming.

I have played around with bitbang mode finding all the examples i could and have now been trying to play with mpsse mode normally in c and using the python bindings, the area which i am confused by is the buffer being passed to the chip using 
ftdi_write_data.

If anyone could explain what happens below or could point me in the correct direction I would greatly appreciate it.

Regards

>(Nearly) Endless loops of USBDEVFS_REAPURBNDELAY 
>Uwe Bonnes
>Mon, 20 Apr 2009 09:14:52 -0700
>#include <ftdi.h>
>#include <usb.h>
>#include <stdio.h>
>
>#define VENDOR 0x0403
>#define PRODUCT 0x6010
>
>/* Sampe libftdi code to read out the JTAG IDs of devices connected 
>to the MPSSE (JTAG) pins of a FD2232
>Compile like
>gcc -g -o test main.c -lftdi -l usb
>*/
>int main(void)
>{
>  struct ftdi_context ftdi;
>  unsigned long id;
>  int read=0, to_read, last_read, retries = 0;
>  unsigned char buf[256] = { SET_BITS_LOW, 0x08, 0x0b,
>                                 TCK_DIVISOR,  0x01, 0x00 ,
>                                 SET_BITS_HIGH, ~0x04, 0x04};
>  ftdi_init(&ftdi);
>  if (ftdi_usb_open_desc(&ftdi, VENDOR, PRODUCT, 0, 0) < 0)
>    {
>      printf("Can't open device\n");
>      return 1;
>    }
>  ftdi_usb_reset(&ftdi);
>  ftdi_set_interface(&ftdi, INTERFACE_A);
>  ftdi_set_latency_timer(&ftdi, 1);
>  ftdi_set_bitmode(&ftdi, 0xfb, BITMODE_MPSSE);
>  buf[9] = SEND_IMMEDIATE;
>  if (ftdi_write_data(&ftdi,buf, 10) != 10)
>    printf("Write failed\n");
>  /* Send 5 Clocks with TMS = 1 to reset the chain*/
>  buf[0]= MPSSE_WRITE_TMS|MPSSE_LSB|MPSSE_BITMODE|MPSSE_WRITE_NEG;
I guess from the above that buf[0] is telling the chip how it is receiving the data etc?
>  buf[1]= 5;
buf[1] is the no of clocks?
>  buf[2]= 0x9f;
buf[3] is tms = 10011111
>  if (ftdi_write_data(&ftdi,buf, 3) != 3)
>    printf("Write1 failed\n");
>  /* Send 4 Clocks with TMS = 0 1 0 0 to reach SHIFTDR*/
>  buf[1]= 4;
>  buf[2]= 0x82;
tms = 10000010?
>  if (ftdi_write_data(&ftdi,buf, 3) != 3)
>    printf("Write1 failed\n");
>  /* In SHIFTDR, clock 32 times to get the ID (last device first)*/
>  do
>    {
what are each of the elements in the array for now, and what is the do while loop doing?
>      buf[0] = MPSSE_DO_READ|MPSSE_DO_WRITE|MPSSE_LSB|MPSSE_WRITE_NEG;
>      buf[1] = 3;
>      buf[2] = 0;
>      buf[3] = 0;
>      buf[4] = 0;
>      buf[5] = 0;
>      buf[6] = 0;
>      if (ftdi_write_data(&ftdi,buf, 7) != 7)
>        printf("Write loop failed\n");
>      to_read = 4;
>      read = 0;
>      last_read = ftdi_read_data(&ftdi, buf, to_read );
>      if (last_read > 0)
>        read += last_read;
>      while (read <to_read)
>        {
>          retries++;
>          last_read = ftdi_read_data(&ftdi, buf+read, to_read -read);
>          if (last_read > 0)
>            read += last_read;
>        }
>      id = 
>        (unsigned long) buf[3] <<24 |
>        (unsigned long) buf[2] <<16 |
>        (unsigned long) buf[1] << 8 |
>        (unsigned long) buf[0];
>      if (id)
>        printf("0x%08lx\n", id);
>    } while( id !=0 && id!=0xffffffff);
>
>  ftdi_usb_reset(&ftdi);
>  ftdi_usb_close(&ftdi);
>  ftdi_deinit(&ftdi);
>  return 0;
>}

--
Vaughan Moss
DBE Test Engineer
SKA  South Africa
Unit 12 Lonsdale Building
Lonsdale Way, Pinelands
7405
Tel:        +27 (21) 531 7282
Fax:       +27 (21) 531 9761
Email:    vaughan@xxxxxxxxx
Web:     www.ska.ac.za


libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to libftdi+unsubscribe@xxxxxxxxxxxxxxxxxxxxxxx


Current Thread