Please login or register.

Login with username, password and session length
 

News:

Latest updates at DangerousPrototypes.com.


Author Topic: First port of OpenOCD firmware to Bus Pirate  (Read 2177 times)

ian

  • Crew
  • Hero Member
  • *****
  • Posts: 2861
  • Karma: +61/-0
    • View Profile
First port of OpenOCD firmware to Bus Pirate
« on: January 04, 2010, 09:07:13 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/source/browse/#svn/trunk/source/OpenOCD

This is untested because there's no PC software to work with yet.

robots

  • Full Member
  • ***
  • Posts: 185
  • Karma: +9/-0
    • View Profile
    • My Blog
Re: First port of OpenOCD firmware to Bus Pirate
« Reply #1 on: January 18, 2010, 10:06:04 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 ;)

ian

  • Crew
  • Hero Member
  • *****
  • Posts: 2861
  • Karma: +61/-0
    • View Profile
Re: First port of OpenOCD firmware to Bus Pirate
« Reply #2 on: January 18, 2010, 10:09:17 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)?

robots

  • Full Member
  • ***
  • Posts: 185
  • Karma: +9/-0
    • View Profile
    • My Blog
Re: First port of OpenOCD firmware to Bus Pirate
« Reply #3 on: January 18, 2010, 10:23:49 AM »
Well ... it should be as easy as replacing all the libusb stuff with serial stuff.

ian

  • Crew
  • Hero Member
  • *****
  • Posts: 2861
  • Karma: +61/-0
    • View Profile
Re: First port of OpenOCD firmware to Bus Pirate
« Reply #4 on: January 18, 2010, 10:29:31 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.

robots

  • Full Member
  • ***
  • Posts: 185
  • Karma: +9/-0
    • View Profile
    • My Blog
Re: First port of OpenOCD firmware to Bus Pirate
« Reply #5 on: January 18, 2010, 12:15:29 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?

ian

  • Crew
  • Hero Member
  • *****
  • Posts: 2861
  • Karma: +61/-0
    • View Profile
Re: First port of OpenOCD firmware to Bus Pirate
« Reply #6 on: January 18, 2010, 12:17:03 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.

robots

  • Full Member
  • ***
  • Posts: 185
  • Karma: +9/-0
    • View Profile
    • My Blog
Re: First port of OpenOCD firmware to Bus Pirate
« Reply #7 on: January 18, 2010, 12:22:22 PM »
Which one is for the v2go  from preorder 2 ? :)

ian

  • Crew
  • Hero Member
  • *****
  • Posts: 2861
  • Karma: +61/-0
    • View Profile
Re: First port of OpenOCD firmware to Bus Pirate
« Reply #8 on: January 18, 2010, 12:41:03 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/files/BusPirate.firmware.v4.1.zip

If you still have v2 bootloader use this one:
http://code.google.com/p/the-bus-pirate/source/browse/#svn/v3.6/firmware/v3-nightly/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/18/how-to-bus-pirate-bootloader-v4-upgrade/

robots

  • Full Member
  • ***
  • Posts: 185
  • Karma: +9/-0
    • View Profile
    • My Blog
Re: First port of OpenOCD firmware to Bus Pirate
« Reply #9 on: January 18, 2010, 03:33:09 PM »
Thanks :) .. I'll have a look at it tomorow.

robots

  • Full Member
  • ***
  • Posts: 185
  • Karma: +9/-0
    • View Profile
    • My Blog
Re: First port of OpenOCD firmware to Bus Pirate
« Reply #10 on: January 19, 2010, 05:16:13 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.

robots

  • Full Member
  • ***
  • Posts: 185
  • Karma: +9/-0
    • View Profile
    • My Blog
Re: First port of OpenOCD firmware to Bus Pirate
« Reply #11 on: January 19, 2010, 05:24:27 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]
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]
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 Edit: January 20, 2010, 01:58:54 AM by robots »

ian

  • Crew
  • Hero Member
  • *****
  • Posts: 2861
  • Karma: +61/-0
    • View Profile
Re: First port of OpenOCD firmware to Bus Pirate
« Reply #12 on: January 20, 2010, 05:32:03 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/source/browse/trunk/firmware/v4-nightly/BPv3%26v2go/BPv3-OpenOCD-v0c-1.hex

Updates...

Main():
Code: [Select]
    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]
    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]
    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]
    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.



robots

  • Full Member
  • ***
  • Posts: 185
  • Karma: +9/-0
    • View Profile
    • My Blog
Re: First port of OpenOCD firmware to Bus Pirate
« Reply #13 on: January 20, 2010, 06:34:42 AM »
I messed up: (lines 121, 148 and 205 of main.c)
Code: [Select]
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]
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]
#define BIT5        0b01//jp2right(?)
could be
Code: [Select]
#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 !


robots

  • Full Member
  • ***
  • Posts: 185
  • Karma: +9/-0
    • View Profile
    • My Blog
Re: First port of OpenOCD firmware to Bus Pirate
« Reply #14 on: January 20, 2010, 07:30:05 AM »
Make the AUx BIT4 instead of BIT5...

According to the wiggler schematic http://www.frozeneskimo.com/electronics/wp-content/uploads/Schematics/jtagwigglersch.png the tsrt it not that needed :)