Re: First port of OpenOCD firmware to Bus Pirate

OpenOCD JTAG debugging with the Bus Pirate.

First port of OpenOCD firmware to Bus Pirate

Postby ian » Mon Jan 04, 2010 10:07 am

We finished porting the OpenOCD support code from the USBPROG project to the Bus Pirate. Get the latest source and compiled firmware from here:
http://code.google.com/p/the-bus-pirate ... ce/OpenOCD

This is untested because there's no PC software to work with yet.
Got a question? Please ask in the forum for the fastest answers.
User avatar
ian
Crew
Crew
 
Posts: 10803
Joined: Mon Jul 06, 2009 6:14 am

Re: First port of OpenOCD firmware to Bus Pirate

Postby robots » Mon Jan 18, 2010 11:06 am

You are wondering (in the source code), why do they use 320 byte long packets.

But usbprog jtag has one problem . They are using interrupt transfers on usb, and they send one packet every 1ms - resulting in 300-400 bytes/sec flashing speed. http://forum.embedded-projects.net/viewtopic.php?id=344

The FT232 that is on BP uses Bulk transfers, so the same problem "should not" occur here.

I would be more than happy to help with this project as I want something a bit better than just wiggler cable ;)
User avatar
robots
Hero Member
Hero Member
 
Posts: 569
Joined: Sat Dec 05, 2009 11:19 am
Location: CZ/Prague

Re: First port of OpenOCD firmware to Bus Pirate

Postby ian » Mon Jan 18, 2010 11:09 am

Thanks robots -

Any help would be greatly appreciated. What do you have in mind? Are you able to mod the existing usbprog code to work with a serial port (the Bus Pirate)?
Got a question? Please ask in the forum for the fastest answers.
User avatar
ian
Crew
Crew
 
Posts: 10803
Joined: Mon Jul 06, 2009 6:14 am

Re: First port of OpenOCD firmware to Bus Pirate

Postby robots » Mon Jan 18, 2010 11:23 am

Well ... it should be as easy as replacing all the libusb stuff with serial stuff.
User avatar
robots
Hero Member
Hero Member
 
Posts: 569
Joined: Sat Dec 05, 2009 11:19 am
Location: CZ/Prague

Re: First port of OpenOCD firmware to Bus Pirate

Postby ian » Mon Jan 18, 2010 11:29 am

Yup, that's my thought too. I'm not a PC programmer though. I can do the microcontroller stuff, but I can't get OpenOCD to compile (yet).

If you are able to do that, please let me know how I can help.
Got a question? Please ask in the forum for the fastest answers.
User avatar
ian
Crew
Crew
 
Posts: 10803
Joined: Mon Jul 06, 2009 6:14 am

Re: First port of OpenOCD firmware to Bus Pirate

Postby robots » Mon Jan 18, 2010 1:15 pm

I have changed the source code, so that it uses serial port. I haven't tried it yet.

Does the code for BP work ? I mean, have you tried to send arbitrary commands and did the outputs work as expected?
User avatar
robots
Hero Member
Hero Member
 
Posts: 569
Joined: Sat Dec 05, 2009 11:19 am
Location: CZ/Prague

Re: First port of OpenOCD firmware to Bus Pirate

Postby ian » Mon Jan 18, 2010 1:17 pm

No, it has not yet been tested. I used my standard framework for porting things to the Bus Pirate, so it should have at least minimal functionality. There any be bugs though.

If you test, be sure you're using the correct firmware for your bootloader version.
Got a question? Please ask in the forum for the fastest answers.
User avatar
ian
Crew
Crew
 
Posts: 10803
Joined: Mon Jul 06, 2009 6:14 am

Re: First port of OpenOCD firmware to Bus Pirate

Postby robots » Mon Jan 18, 2010 1:22 pm

Which one is for the v2go  from preorder 2 ? :)
User avatar
robots
Hero Member
Hero Member
 
Posts: 569
Joined: Sat Dec 05, 2009 11:19 am
Location: CZ/Prague

Re: First port of OpenOCD firmware to Bus Pirate

Postby ian » Mon Jan 18, 2010 1:41 pm

v2go and v3 use the same firmware now. They shipped with v2 bootloader, but today we released the v4 bootloader upgrade. If you upgrade your bootloader, then you can use the OpenOCD firmware in this download:
http://the-bus-pirate.googlecode.com/fi ... e.v4.1.zip

If you still have v2 bootloader use this one:
http://code.google.com/p/the-bus-pirate ... ghtly/BPv3

At the moment there seems to be a problem with the ds30 Loader bootloader app on Mac/Linux with Mono, so please don't upgrade unless you have access to a windows box:
http://dangerousprototypes.com/2010/01/ ... 4-upgrade/
Got a question? Please ask in the forum for the fastest answers.
User avatar
ian
Crew
Crew
 
Posts: 10803
Joined: Mon Jul 06, 2009 6:14 am

Re: First port of OpenOCD firmware to Bus Pirate

Postby robots » Mon Jan 18, 2010 4:33 pm

Thanks :) .. I'll have a look at it tomorow.
User avatar
robots
Hero Member
Hero Member
 
Posts: 569
Joined: Sat Dec 05, 2009 11:19 am
Location: CZ/Prague

Re: First port of OpenOCD firmware to Bus Pirate

Postby robots » Tue Jan 19, 2010 6:16 pm

I have some "results". The openocd wants to talk to Bus Pirate, but it doesn't reply with anything.

The firmware must be working, as the ModeLed turns off.

The log is here http://pastebin.com/m2d36f3b1

After each write/read I print out what was actually sent/read.
User avatar
robots
Hero Member
Hero Member
 
Posts: 569
Joined: Sat Dec 05, 2009 11:19 am
Location: CZ/Prague

Re: First port of OpenOCD firmware to Bus Pirate

Postby robots » Tue Jan 19, 2010 6:24 pm

Atmega32 and PIC different meaning of the direction registers !

My buspirate now blinks as the openocd says ;)

Edit: I have accidentally fried the pullup driver on the pgc pin :(( but i can still enter bootloader

I have found mistake in the main.c WRITE_AND_READ handler.

should be something like:
Code: Select all
case WRITE_AND_READ:// buf[1]+buf[2] extra bytes?????
      i = ((uint8_t)buf[1]*256)+(uint8_t)buf[2];
      write_and_read(buf+3, i);        // skip 3 bytes on buf,  size from openocd is actually number of bits used in the buffer (max 61 * 8 = 488)
....
      CommandAnswer(i/8+1); // for future use :) bigger packets
    break;



also in main()
Code: Select all
case WRITE_AND_READ:// buf[1]+buf[2] extra bytes?????
                                buf[1]=UART1RX();//get extra byte
                                buf[2]=UART1RX();//get extra byte
                                j=((uint8_t)buf[1]*256)+(uint8_t)buf[2]; //get data packet size
                                j=j/8+1;
                                for(i=0;i<j;i++){
                                        buf[2+i]=UART1RX();
                                }
                                break;
Last edited by robots on Wed Jan 20, 2010 2:58 am, edited 1 time in total.
User avatar
robots
Hero Member
Hero Member
 
Posts: 569
Joined: Sat Dec 05, 2009 11:19 am
Location: CZ/Prague

Re: First port of OpenOCD firmware to Bus Pirate

Postby ian » Wed Jan 20, 2010 6:32 am

Thanks robots.

I read the notice emails, so I didn't see the edit until just now. Go ahead and make another post for faster service :)



I updated the functions as follows, and committed a new compile for v4 bootloader to the nightly folder. Have you upgraded bootloaders? I can make a compile for v2 bootloader if you need it.
http://code.google.com/p/the-bus-pirate ... -v0c-1.hex

Updates...

Main():
Code: Select all
          case WRITE_TDI:// buf[1]+buf[2] extra bytes?????
         case READ_TDO:// buf[1]+buf[2] extra bytes?????
          case WRITE_AND_READ:// buf[1]+buf[2] extra bytes?????
            buf[1]=UART1RX();//get extra byte
            buf[2]=UART1RX();//get extra byte
            j=((uint8_t)buf[1]*256)+(uint8_t)buf[2]; //get data packet size
            j=(j/8)+1;
               for(i=0;i<j;i++){
               buf[2+i]=UART1RX();
            }
            break;


WRITE_AND_READ
Code: Select all
    case WRITE_AND_READ:// buf[1]+buf[2] extra bytes?????
      //write_and_read(buf,((uint8_t)buf[1]*256)+(uint8_t)buf[2]);   // size = numbers of byte not bits!!! round up
      j = ((uint8_t)buf[1]*256)+(uint8_t)buf[2];
      write_and_read(buf+3, j);        // skip 3 bytes on buf,  size from openocd is actually number of bits used in the buffer (max 61 * 8 = 488)
   
      #if 1
      // tck 0 tms 0 tdi 0
      CLEARBIT(BIT2_WRITE,BIT2);  // clk
      CLEARBIT(BIT1_WRITE,BIT1);  // tdi
      CLEARBIT(BIT3_WRITE,BIT3);  // tms
     
      // tck 1 tms 0 tdi 0
      SETBIT(BIT2_WRITE,BIT2);  // clk
      #endif

//      for(i=0;i<64;i++)
//      answer[i]=buf[i];

     j=(j/8)+1;
      for(i=0;i<j;i++)
      answer[i]=buf[i];

      //CommandAnswer(64);
      CommandAnswer(j); // for future use :) bigger packets
    break;


Because WRITE_TDI, READ_TDO and WRITE_AND_READ all share that function in main, I made these updates too:

WriteTDI (now uses buf+3)
Code: Select all
    case WRITE_TDI:// buf[1]+buf[2] extra bytes?????
      write_tdi(buf+3,((uint8_t)buf[1]*256)+(uint8_t)buf[2]);   // size = numbers of byte not bits!!! round up
      // tck 0 tms 0 tdi 0
      CLEARBIT(BIT2_WRITE,BIT2);  // clk
      CLEARBIT(BIT1_WRITE,BIT1);  // tdi
      CLEARBIT(BIT3_WRITE,BIT3);  // tms
     
      // tck 1 tms 0 tdi 0
      SETBIT(BIT2_WRITE,BIT2);  // clk
    break;


Read TDO (uses same mods as WRITE_AND_READ
Code: Select all
    case READ_TDO:// buf[1]+buf[2] extra bytes?????
      //read_tdo(buf,((uint8_t)buf[1]*256)+(uint8_t)buf[2]);   // size = numbers of byte not bits!!! round up
      j = ((uint8_t)buf[1]*256)+(uint8_t)buf[2];
     read_tdo(buf+3,j);   // size = numbers of byte not bits!!! round up

      #if 1
      // tck 0 tms 0 tdi 0
      CLEARBIT(BIT2_WRITE,BIT2);  // clk
      CLEARBIT(BIT1_WRITE,BIT1);  // tdi
      CLEARBIT(BIT3_WRITE,BIT3);  // tms
     
      // tck 1 tms 0 tdi 0
      SETBIT(BIT2_WRITE,BIT2);  // clk
      #endif
      //for(i=0;i<64;i++)
   //   answer[i]=buf[i];

     j=(j/8)+1;
      for(i=0;i<j;i++)
      answer[i]=buf[i];

      //CommandAnswer(64);
      CommandAnswer(j); // for future use :) bigger packets

    break;


Please let me know if you think any of these changes were unnecessary.
Got a question? Please ask in the forum for the fastest answers.
User avatar
ian
Crew
Crew
 
Posts: 10803
Joined: Mon Jul 06, 2009 6:14 am

Re: First port of OpenOCD firmware to Bus Pirate

Postby robots » Wed Jan 20, 2010 7:34 am

I messed up: (lines 121, 148 and 205 of main.c)
Code: Select all
j=(j/8)+1;

it should give the number of bytes used by bits, but returns +1 if (j % 8 == 0)

This should work better
Code: Select all
j = (j >> 3) + (j & 0x07)?1:0;


Another thing is to route the TRST signal to the output port, i guess that  AUX could do it.
Code: Select all
#define BIT5        0b01//jp2right(?)

could be
Code: Select all
#define BIT5        AUX


And you can remove all of those BITx_1 stuff (it was in usbprog for backward compatibility)

Too bad we are missing one IO for the SRST. :-/

After these changes i should be able to test it on real hw !
User avatar
robots
Hero Member
Hero Member
 
Posts: 569
Joined: Sat Dec 05, 2009 11:19 am
Location: CZ/Prague

Re: First port of OpenOCD firmware to Bus Pirate

Postby robots » Wed Jan 20, 2010 8:30 am

Make the AUx BIT4 instead of BIT5...

According to the wiggler schematic http://www.frozeneskimo.com/electronics ... lersch.png the tsrt it not that needed :)
User avatar
robots
Hero Member
Hero Member
 
Posts: 569
Joined: Sat Dec 05, 2009 11:19 am
Location: CZ/Prague

Next

Return to OpenOCD JTAG