Skip to main content
Topic: PiratePICprog console application (Read 35452 times) previous topic - next topic

Re: PiratePICprog console application

Reply #30
Thanks robots - I've been studying the code every time you make a commit. The interface abstraction is nice and easy to understand, the whole app is really straight forward and well written. I think we'll be able to expand it to support a few different programmer types. You did way more work than I expected, I had just hoped you would tell us how you think it should be built and I would do it :) I'm going to check out the new code now.
Got a question? Please ask in the forum for the fastest answers.

Re: PiratePICprog console application

Reply #31
Don't worry ;) You still need to implement those various programming protocols.

Re: PiratePICprog console application

Reply #32
I'm excited :) the SURE programming adapter for all the testing just arrived a few minutes ago:
http://dangerousprototypes.com/2010/06/ ... ng-adapter
Got a question? Please ask in the forum for the fastest answers.

Re: PiratePICprog console application

Reply #33
how does it look and feel? I didn't bought one because the order was getting too expensive

My stuff from sure arived around a week ago, but it was packaged very well. (that could explain the shippingcosts ;)

Re: PiratePICprog console application

Reply #34
I'm awaiting one for my PICkit 2.   :)

Re: PiratePICprog console application

Reply #35
It's pretty tough. Two thick pieces of acrylic as a top and bottom plate, an idea I might use for a future Bus Pirate case. Decent ZIF sockets (for $10...). The only thing is I can't really operate the levers from the cut-outs provided. I'll post it up today.
Got a question? Please ask in the forum for the fastest answers.

Re: PiratePICprog console application

Reply #36
Sooo, I have checked in some version of the piratepicprog. I think it contains all of the basic functionality, BUT it has not been tested (not even once). I'm really sorry :( I am leaving for vacation in few hours and I didn't get any more time to spend on this project. I don't even know if there is internet connection, so please don't yell at me ;).

Included is also Makefile.win that should work with mingw (probably needs "-lkernel32" in LIBS variable). I have compiled the project successfully with mingw-gcc 4.5.0, some linking problem due to my sloppy installation and broken paths.

Command line parsing is done using getopt. This way is much cleaner than pump-loader used and easily extended when new parameters are to be implemented. Some sanity checks are missing (combination of correct parameters), but should really be just matter of one "IF".

The whole application should be really easy to understand. All the technical problem have been dealt with and other additions should be done according to the "template". Some warning: Data buffer passed to write/read function is void* and PICxx implementations choose what the size of the element in the array is. This can cause some problems on different endian systems. (The same is for the ICSP key - it should be stored as array of bytes instead of one 4byte value). I see this as a small improvement, and I was aiming for some working application, instead of polishing details on trash.

Re: PiratePICprog console application

Reply #37
Have a nice vacation!!

Re: PiratePICprog console application

Reply #38
Thanks a lot!   I was hoping for some more on topic reply ;)

Re: PiratePICprog console application

Reply #39
Sorry man... It is here too hot to be serious ;)

But you did a good job :)

Re: PiratePICprog console application

Reply #40
I went to look at this, figure I would try it out on my MAC, but I got lost trying to find the current sources.  Any pointers of which repository and tree would be appreciated.

Re: PiratePICprog console application

Reply #41
@rhyde - I believe this is the current source: http://code.google.com/p/dangerous-prot ... /framework

Thanks robots, you did a fantastic job. Have a great trip. I'll clear the remaining things you mention.

I just got the updated, stackable PIC programming adapter PCBs from the post office. That, along with the SURE PIC programming boards, means this week will be full of debugging fun :) I'll start posting progress updates in this thread on Monday.
Got a question? Please ask in the forum for the fastest answers.

Re: PiratePICprog console application

Reply #42
I spent the day working with robots' new framework. I got it compiling and communicating with the bus pirate on windows with MinGW.

I made some modifications to get it working on my system. These could be the same sloppy paths that robots mentioned for his compile.
*Added windows.h for Sleep()
*Used old windows serial read (unix version didn't read according to portmon)
*Made the BBIO entry a little more robust. In practice it doesn't matter, but during development it's helpful to be able to enter correctly after a single 0x00 command. The old function would be fine if I know how to flush the serial buffer.

My goal has been to test erase and then add a general 'id the chip' function. So far it enters BBIO and sets up fine.

There is a problem with a pointer (I think) that causes a segfault. It happens the first time the iface struct is used here in pic18.c:

Code: [Select]
static void PIC18_settblptr(struct picprog_t *p, uint32_t tblptr)
{
struct iface_t *iface = p->iface;
void *opts = p->iface_data;

// set TBLPTR
iface->PIC416Write(opts, 0x00, 0x0E00 | ((tblptr >> 16) & 0xff));
printf("n here!!! n");
iface->PIC416Write(opts, 0x00, 0x6EF8);
iface->PIC416Write(opts, 0x00, 0x0E00 | ((tblptr >> 8) & 0xff));
iface->PIC416Write(opts, 0x00, 0x6EF7);
iface->PIC416Write(opts, 0x00, 0x0E00 | ((tblptr) & 0xff));
iface->PIC416Write(opts, 0x00, 0x6EF6);
}

The printf (here) is never reached.

To get a closer look I've installed the codeblocks IDE and debugger. Codeblocks doesn't seem to recognize that this is a .c project and not c++, so I had to change the g++ executable to gcc...

That's where I'm at now. I've traced through and found the fault, now I've got to get familiar enough with the structs to see what's going on. Thought I'd post an update in case the problem is readily apparent to anyone else.

My code is checked in here:
http://code.google.com/p/dangerous-prot ... /framework
Got a question? Please ask in the forum for the fastest answers.

Re: PiratePICprog console application

Reply #43
Code: [Select]
	picprog.iface = Iface_GetByName(param_prog);
picprog.chip_idx = PIC_GetChipIdx(param_chip);


picops = PIC_GetProtoOps(picprog.chip_idx);
picchip = PIC_GetChip(picprog.chip_idx);
picfamily = PIC_GetFamily(picchip->family);

if (cmd & CMD_ERASE) {
picops->Erase(&picprog);
}


//erase 18F, sleep delay should be adjustable
uint32_t PIC18_Erase(struct picprog_t *p) {
struct pic_chip_t *pic = PIC_GetChip(p->chip_idx);
struct pic_family_t *f = PIC_GetFamily(pic->family);
struct iface_t *iface = p->iface;
void *opts = p->iface_data;

//error starts here
PIC18_settblptr(p, 0x3C0005); //set pinter to erase register
printf("n here!!! n");
iface->PIC416Write(opts, 0x0C, f->erase_key[0]);//write special erase token
PIC18_settblptr(p, 0x3C0004); //set pointer to second erase register
iface->PIC416Write(opts, 0x0C, f->erase_key[1]);//write erase command
iface->PIC416Write(opts, 0, 0);
iface->PIC416Write(opts, 0, 0);
usleep(1000 * f->erase_delay);

return 0;
}

static void PIC18_settblptr(struct picprog_t *p, uint32_t tblptr)
{
struct iface_t *iface = p->iface;
void *opts = p->iface_data;

// set TBLPTR
iface->PIC416Write(opts, 0x00, 0x0E00 | ((tblptr >> 16) & 0xff));
printf("n here!!! n");
iface->PIC416Write(opts, 0x00, 0x6EF8);
iface->PIC416Write(opts, 0x00, 0x0E00 | ((tblptr >> 8) & 0xff));
iface->PIC416Write(opts, 0x00, 0x6EF7);
iface->PIC416Write(opts, 0x00, 0x0E00 | ((tblptr) & 0xff));
iface->PIC416Write(opts, 0x00, 0x6EF6);
}

uint32_t BP_PIC416Write(void *pBP, uint8_t cmd, uint16_t data) {
int fd = ((struct BP_t *)pBP)->fd;
enum BP_picmode_t mode = ((struct BP_t*)pBP)->picmode;
uint8_t buffer[4] = {0};
int res = -1;

if (mode != BP_PIC416)
BP_SetPicMode(fd, BP_PIC416);

buffer[0] = 'xA4';
buffer[1] = cmd;
buffer[2] = (uint8_t)(data);
buffer[3] = data >> 8;

serial_write(fd, buffer, 4);
res = serial_read(fd, buffer, 1);
if (buffer[0] != 'x01') {
puts("ERROR");
return -1;
}
return 0;
}


Complete chain.
Got a question? Please ask in the forum for the fastest answers.

Re: PiratePICprog console application

Reply #44
I don't think I'll get it today.

Code: [Select]
	printf("Initializing interface n");
picprog.iface->Init(&picprog, param_port, param_speed);

picprog.chip_idx = PIC_GetChipIdx(param_chip);
if (picprog.chip_idx == -1) {
printf("Unknown chip '%s' !n", param_chip);
return -1;
}
printf("Found chip ! index = %dn", picprog.chip_idx);

picops = PIC_GetProtoOps(picprog.chip_idx);
picchip = PIC_GetChip(picprog.chip_idx);
picfamily = PIC_GetFamily(picchip->family);

    picprog.iface->MCLRLow(&picprog); //new line to trigger segfault

buf_read = (uint8_t*)malloc(picchip->flash);

Made this change to main.c and can trigger the segfault from main.c now. The hint is that Init works above, so I think it's a problem with the serial port that's dealt with at in MCLRLow and not Init:

Code: [Select]
uint32_t BP_MCLRLow(void *pBP) {
int fd = ((struct BP_t *)pBP)->fd;
return BP_WriteToPirate(fd, "x04");
}

Anything that does int fd = ((struct BP_t *)pBP)->fd; in buspirate.c crashes.
Got a question? Please ask in the forum for the fastest answers.