Commit c8065834 authored by Al Williams's avatar Al Williams

Allows for PICs to have two config words

This is currently only set for the PIC16F886
but should be set for all double config PICs.

The trigger for this is to add 0x10000 to the PIC's
protocol_id in devices.h. This is stripped off in
main.c after setting the correct PIC fuse structure.

For compatibility, the original config word (0x2007) is
still conf_word in the input/output text file.

The second config word (0x2008) is tagged conf_word1

Both read and write will respect the extra configuration word.

Note the Makefile doesn't pick up changes to devices.h so if
you change more PICs to handle dual config words, you need to
do a make clean before running make to be sure the changes are picked
up.
parent a30e1111
......@@ -174636,7 +174636,7 @@
},
{
.name = "PIC16F886",
.protocol_id = 0x63,
.protocol_id = 0x10063,
.variant = 0x91,
.read_buffer_size = 0x80,
.write_buffer_size = 0x20,
......@@ -17,3 +17,13 @@ fuse_decl_t pic_fuses[] = {
{ .name = "conf_word", .minipro_cmd = 0x12, .length = 2, .offset = 0 },
{ .name = NULL },
};
fuse_decl_t pic2_fuses[] = {
{ .name = "user_id0", .minipro_cmd = 0x10, .length = 2, .offset = 0 },
{ .name = "user_id1", .minipro_cmd = 0x10, .length = 2, .offset = 2 },
{ .name = "user_id2", .minipro_cmd = 0x10, .length = 2, .offset = 4 },
{ .name = "user_id3", .minipro_cmd = 0x10, .length = 2, .offset = 6 },
{ .name = "conf_word", .minipro_cmd = 0x12, .length = 2, .offset = 0 },
{ .name = "conf_word1", .minipro_cmd = 0x12, .length = 2, .offset = 2 },
{ .name = NULL },
};
......@@ -10,5 +10,6 @@ typedef struct fuse_decl {
extern fuse_decl_t avr_fuses[];
extern fuse_decl_t pic_fuses[];
extern fuse_decl_t pic2_fuses[];
#endif
......@@ -416,6 +416,11 @@ int main(int argc, char **argv) {
case 0x71:
device->fuses = avr_fuses;
break;
case 0x10063: // select 2 fuses
device->fuses=pic2_fuses;
device->protocol_id&=0xFF;
break;
case 0x63:
case 0x65:
device->fuses = pic_fuses;
......
......@@ -118,10 +118,10 @@ int minipro_get_chip_id(minipro_handle_t *handle) {
void minipro_read_fuses(minipro_handle_t *handle, unsigned int type, unsigned int length, char *buf) {
msg_init(msg, type, handle->device);
msg[2] = 0x01;
msg[5] = 0x10;
msg[2]=(type==18 && length==4)?2:1; // note that PICs with 1 config word will show length==2
msg[5]=0x10;
msg_send(handle, msg, 18);
msg_recv(handle, msg, 7 + length);
msg_recv(handle, msg, 7 + length );
memcpy(buf, &(msg[7]), length);
}
......@@ -130,24 +130,27 @@ void minipro_write_fuses(minipro_handle_t *handle, unsigned int type, unsigned i
switch(type & 0xf0) {
case 0x10:
msg_init(msg, type + 1, handle->device);
msg[2] = 0x01;
msg[2] = (length==4)?0x02:0x01; // 2 fuse PICs have len=8
msg[4] = 0xc8;
msg[5] = 0x0f;
msg[6] = 0x00;
memcpy(&(msg[7]), buf, length);
msg_send(handle, msg, 64);
break;
case 0x40:
msg_init(msg, type - 1, handle->device);
memcpy(&(msg[7]), buf, length);
msg_send(handle, msg, 10);
break;
}
// The device waits us to get the status now
msg_init(msg, type, handle->device);
msg[2] = 0x01;
msg[2]=(type==18 && length==4)?2:1; // note that PICs with 1 config word will show length==2
memcpy(&(msg[7]), buf, length);
msg_send(handle, msg, 18);
msg_recv(handle, msg, 7 + length);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment