Dangerous Prototypes

Dangerous Prototypes => Bus Pirate Support => Topic started by: W1N9Zr0 on February 21, 2010, 01:15:56 am

Title: Another Bus Pirate case and PIC programmer
Post by: W1N9Zr0 on February 21, 2010, 01:15:56 am
Here is my take on a Bus Pirate case.
(http://http://www.flickr.com/photos/w1n9zr0/4374222182/)
It's made of a PS2 game case and integrates two breadboards, the bus pirate and an A23 12v battery for PIC programming.
More images (http://http://www.flickr.com/photos/w1n9zr0/sets/72157623350603649/detail/)

What do you think?
Title: Re: Another Bus Pirate case
Post by: ian on February 21, 2010, 09:39:23 am
Fantastic build, I'll post it up. Thanks for sharing.

It's cool that you've got the 12volt battery so you'll be ready to program PICs right way.
Title: Re: Another Bus Pirate case
Post by: W1N9Zr0 on February 21, 2010, 04:46:23 pm
I can program a couple PICs I have already! I wrote a quick C# app to use the raw 2 wire mode that does it, but it needs configuration for different chips because microchip decided to use slightly different programming cycles for almost every chip model.

I looked at usbpicprog, but it has half its programming logic in the firmware and half in xml files on the pc. The firmware is the one that deals with all the different programming cycles (it's all hard coded, 1,300 line, C case/if) which is the more difficult part, the xml files only define memory ranges.
Guess one could take the prog.c from the firmware code and write all the write_pic_blah() externals it uses to use the bus pirate and see if it compiles under normal C.

Right now though, I'm thinking of using my C# app though and making config files that define the whole programming cycle along with memory ranges. That way you don't need a compiler to add a chip definition, just search up the microchip PDF for it, type up a config file and you're set.
Title: Re: Another Bus Pirate case
Post by: ian on February 21, 2010, 05:02:16 pm
Fantastic idea. Let me know how I can help, or if it would help to have a custom binmode or raw2wire extensions to improve speed or do 'tricks'.

If you're willing to put the code in SVN, I bet there are other people (like me) who would like to review or contribute to the code. I'd like to add support for the PCI24Fj64GA002, for obvious reasons.

I've worked on porting the USBPICPROG firmware, but there are some foibles because of the difference in data transfer on the two devices. Your method of just using the Bus Pirate as a flexable 2wire IO dongle is great. Are there some chips/operations that might have a problem without precise delays? We might be able to write some extensions for that stuff.

Also, would you like a PIC programming adapter with a boost converter, or maybe just to see the circuit I used for switching VPP and MCLR?
Title: Re: Another Bus Pirate case
Post by: Sjaak on February 21, 2010, 08:10:04 pm
I though all the pic12, 16 and 18 had the same way of programming. Since they use a synchronious communication timing isn't very critical or am I way off? I think I really need to look deeper into this :D But good to hear it is possible with the standard libraries ;)

BTW nice the fiberoptics!
Title: Re: Another Bus Pirate case
Post by: W1N9Zr0 on February 22, 2010, 05:22:29 am
[quote author="ian"]
Are there some chips/operations that might have a problem without precise delays? We might be able to write some extensions for that stuff.
[/quote]
[quote author="Sjaak"]
I though all the pic12, 16 and 18 had the same way of programming. Since they use a synchronious communication timing isn't very critical or am I way off?
[/quote]
Yup, the 10-16s I looked at use synchronious communication, and 18 and up probably too but I haven't looked at the higher end chips too much yet.

[quote author="ian"]
Also, would you like a PIC programming adapter with a boost converter, or maybe just to see the circuit I used for switching VPP and MCLR?
[/quote]
Sure, that'd be great!

I can put it under SVN once I figure out the format for the config files and clean up my bus pirate raw mode wrapper.
The main problem is that there are so many different programming sequences. I've seen at least 5 different ones in the microchip programming spec pdfs (http://http://search.microchip.com/searchapp/searchhome.aspx?q=Programming%20Specifications&resperpage=10&id=35) for the 8 bit chips. There are at least 3 "begin programming" commands, at least 3 combinations of begin-write-(optional)end cycles, and sometimes different chips do different things with the same command!
I'm wondering if it's easier to work with the pdfs or with the usbpicprog firmware source to figure out what config options the files need to have.

Also, if anyone uses Mono, does Mono implement System.IO.Ports.SerialPort?
Title: Re: Another Bus Pirate case and PIC programmer
Post by: ian on February 23, 2010, 10:21:19 am
The ds30 Loader GUI is serial port and works on Mono, you might be able to find some code examples there for universal serial port calls. I was going to give you a link, but I realized we're just using Mackey's current version now.

I gave you access to the google SVN. You'll need to check your google code profile to get your google code password. Feel free to put your work where you like, we can always move it later.

The usbpicprog source seems to reflect a lot of real-world experience. I'd tap that as much as possible to avoid reworking the same issues Frans encountered.

I just read through the 24fjxxxga0xx programming spec for fun. Looks like nothing too critical timing wise:
http://ww1.microchip.com/downloads/en/D ... 39768d.pdf (http://ww1.microchip.com/downloads/en/DeviceDoc/39768d.pdf)

The 24fj and 33F don't need a high VPP, I'm unsure about the 30F and 24hj.

I'm posting the case up now, thanks for the picture.
Title: Re: Another Bus Pirate case and PIC programmer
Post by: Nibble on February 28, 2010, 02:59:11 am
Hello all,

I am wondering...

What about using the idea (and source code) from the Universal OS PIC Programmer: "This programmer requires only a basic terminal program capable of uploading an ascii PIC HEX file. It does not matter what operating system or computer (MAC, Win98, XP, Vista, DOS, Linux, etc.) is used to talk to it."

The source code is available and perhaps can be easly adapted as a BusPirate script...

Please see: http://mondo-technology.com/upp.html (http://mondo-technology.com/upp.html)
Title: Re: Another Bus Pirate case and PIC programmer
Post by: Sjaak on February 28, 2010, 09:30:23 am
Looks great. It looks like it can be converted to a new protocol. I really like the idea.

Too bad it is written in asm :) Perhaps it is easier to read the datasheet and implement from scratch. However my asm skill are getting rusty ;)
Title: Re: Another Bus Pirate case and PIC programmer
Post by: honken on February 28, 2010, 07:10:59 pm
I got inspired by this, and made a case of my own.
I used a mints tin can, very similar i size to the ubiquitous Altoids variant.
I've got a v2go and it's fastened with some adhesive tack, so it's removable.
I could also fit one of those mini breadboard from Seeedstudio/SparkFun (can't rememder where I got it from) as well as some jumper cables.


Title: Re: Another Bus Pirate case and PIC programmer
Post by: ian on February 28, 2010, 07:14:43 pm
I like the guide in the lid. I'll post these up. Fantastic, really great job.
Title: Re: Another Bus Pirate case and PIC programmer
Post by: AZRobbo on March 01, 2010, 03:08:11 am
I LOVE the guide in the lid - can you share the file with us?
Title: Re: Another Bus Pirate case and PIC programmer
Post by: honken on March 01, 2010, 06:46:31 pm
Sure, in part.
I made a little logo for myself and therein lies perhaps a problem.
The skull and bones are taken from wikipedia and GPL'd - so no problem,
but the USB-trident is a registered trademark (again according to wikipedia, where I stole it from).
I'm not sure if this use constitutes any violations.
So I think Ian should decide wether he wants possible infringements on his site.

The rest is stolen from Ian's blog, with some small modifications (removed version 2+ texts).

But here's a safe version without the logo.
Title: Re: Another Bus Pirate case and PIC programmer
Post by: ian on March 01, 2010, 07:03:38 pm
Without the logo if fine for me. Could you give us a link to the GPL'd image license page, just for good measure.
Title: Re: Another Bus Pirate case and PIC programmer
Post by: honken on March 01, 2010, 07:38:41 pm
The image of the skull and bones is found here http://en.wikipedia.org/wiki/File:Flag_of_Edward_England.svg (http://http://en.wikipedia.org/wiki/File:Flag_of_Edward_England.svg)
With the license http://commons.wikimedia.org/wiki/Commons:GNU_Free_Documentation_License (http://http://commons.wikimedia.org/wiki/Commons:GNU_Free_Documentation_License)

The Trident is found here http://en.wikipedia.org/wiki/File:USB_Icon.svg (http://http://en.wikipedia.org/wiki/File:USB_Icon.svg)
Title: Re: Another Bus Pirate case and PIC programmer
Post by: W1N9Zr0 on April 19, 2010, 03:50:16 am
It's been a busy time at work so I haven't had much time to work on this, but I've committed some stuff to SVN just now.
http://the-bus-pirate.googlecode.com/sv ... rateRawCS/ (http://the-bus-pirate.googlecode.com/svn/trunk/scripts/BusPirateRawCS/BusPirateRawCS/)
AnkhSVN gave me some problems exporting it from visual studio, so it ended up one directory deeper than it should be.

I started on a C# library to use the raw modes and handle the SerialPort asynchronously since the .net SerialPort isn't very fast synchronously.
Then there is a PIC programmer library which implements dsPIC30 (as BusPiratePICProgrammer.DsPICProgrammer) and PIC10/12/16 programming (as BusPiratePICProgrammer.PIC16Programmer) based on the Usbpicprog firmware code.
I didn't have time to convert the PIC18 code and a very specific case of one 16 chip yet, but it should almost be a direct copy-paste from Usbpicprog firmware.
From what I've read, PIC24 should be very close the dsPIC, so that should be pretty easy to tack on too.
The PIC16Programmer class also needs an options loader to configure it for other 10/12/16 pics, right now it defaults to PIC16F6x8A.
The code also includes a .hex file reader.

All of these in combination write my 16F628A perfectly using the example app!
I'm still using my programming circuit, haven't played with Ian's voltage booster board yet. My circuit just uses an opto isolator on the AUX pin to connect the 12v battery to the MCLR pin on the pic.
Title: Re: Another Bus Pirate case and PIC programmer
Post by: ian on April 20, 2010, 10:14:06 am
Thanks, this is fantastic. I'm going to post it on the blog. Is there a compiled version I can archive an put up for download?

The voltage booster is back to the drawing board... I've noticed that many PICs need VPP applied before VDD, and the booster can't do that. I've redesigned it with a FET to switch the power supply too.
Title: Re: Another Bus Pirate case and PIC programmer
Post by: W1N9Zr0 on April 20, 2010, 01:36:06 pm
It's not ready for end users yet, I still have some random bugs ( for example it can't figure out if it entered the raw mode properly once in a while). And it only programs the 16f628a now since there's no configuration, or a "browse for hex file" dialog even :P

If anyone wants to try it on their pic and knows their way around C#, you can edit the PIC configuration variables in PIC16ProgrammerHelper.cs, and then try the Read Program, Read Data and Program Test buttons in Form1
Program Test will ERASE the pic! Then write some random numbers into code and data memory, and as of right now reads the 628a user id, chip id, and the configuration word.
The Read Hex button can also program a hex file into the pic, but you have to edit the path to it, and change the hex/pic address offsets to your own (again, it's set up for 16f628a now)
The circuit itself is just AUX switching a 12v supply to MCLR, the pic is powered by the Bus Pirate's 5v, and the BP pullups are also connected to the 5v. The pic PGC is BP's CLK, and PGD is BP's MOSI.
(http://http://www.flickr.com/photos/w1n9zr0/4537178657/sizes/l/) (http://http://www.flickr.com/photos/w1n9zr0/4537177903/sizes/l/)


The VPP before VDD requirement is probably not a very strict thing, the spec for 628a also says you need VPP first, but I can kick it in and out of program mode with VDD on all the time just fine.
Title: Re: Another Bus Pirate case and PIC programmer
Post by: Sjaak on April 20, 2010, 02:04:37 pm
Some pics are stricter then others. I have the same experience as Ian.. Perhaps because we tried to program it by hand (see the pic programmingtopics in the development section). Could also be a sillicon revision issue though..

BTW nice way of switching Vpp!
Title: Re: Another Bus Pirate case and PIC programmer
Post by: znanev on May 11, 2010, 06:40:20 pm
Nice work, W1N9Zr0!

I downloaded your source code with the intention to add support for 18F2XXX / 18F4XXX. While I am comfortable enough with C# programming, I lack deep knowledge of C and therefore I have some difficulties trying to understand how to port the usbpicprog firmware code for this MCU. When you have some spare time, would you please give me some help on this subject. I see you have used different approaches in coding [tt:]DsPICProgrammer[/tt:] and
[tt:]PIC16Programmer[/tt:] classes. While the first is almost exact copy-paste from the usbpicprog, the latter looks more C#-friendly with a lot of sophisticated private methods :) Can you please explain how can I use them effectively - i.e. [tt:]set_vdd_vpp(pictype, picfamily,1)[/tt:] I think corresponds to [tt:]Program = true[/tt:] and [tt:]set_vdd_vpp(pictype, picfamily,0)[/tt:] to [tt:]Program = false[/tt:] respectively - is this correct? And what about [tt:]PGC=1[/tt:] and [tt:]PGC=0[/tt:] in the C code - is this also equivalent to [tt:]Program = true[/tt:] and [tt:]Program = false[/tt:]?

Many thanks,
Zdravko
Title: Re: Another Bus Pirate case and PIC programmer
Post by: honken on August 20, 2010, 10:08:31 am
So it seems.
I probably made some error posting it.
This one is made with 7z 4.57.
It will probably need an update to conform with more recent firmwares.
I'm still running 4.1 in my BP.

( ! ) Fatal error: Uncaught exception 'Elk_Exception' with message 'Please try again. If you come back to this error screen, report the error to an administrator.' in /var/www/dangerousprototypes/forum/sources/database/Db-mysql.class.php on line 696
( ! ) Elk_Exception: Please try again. If you come back to this error screen, report the error to an administrator. in /var/www/dangerousprototypes/forum/sources/database/Db-mysql.class.php on line 696
Call Stack
#TimeMemoryFunctionLocation
10.01362147888session_write_close ( )...(null):0
20.01392279480ElkArte\sources\subs\SessionHandler\DatabaseHandler->write( )...(null):0
30.01392280256Database_MySQL->query( ).../DatabaseHandler.php:119
40.05762418984Database_MySQL->error( ).../Db-mysql.class.php:273