WallaceIT / picberry

PIC Programmer using GPIO connector
GNU General Public License v3.0
40 stars 27 forks source link

Program hangs if programmer not connected - PIC32 #19

Open stevenjmaev opened 2 years ago

stevenjmaev commented 2 years ago

When testing picberry's operation for a PIC32MX3 family device, the program hung after printing Timeout occurred checking device status! to the terminal. Since the program never gets to this else block, it must be getting stuck in line 305.

I believe I've tracked down the issue to the pic32::GetPEResponse() function located in pic32.cpp. Specifically, the do-while loop within that function apparently waits for the Processor Access Bit to be set. If the device is not connected, however, this loop never breaks.

// Check if Processor Access bit (bit 18) is set
do {
    response = XferData(32, 0x0004c000);
} while(!( (response >> 18) & 0x01 ));

One solution to this would be to implement a timeout flag that would allow the do-while loop to break and/or return 0x00000000. Then, the function which called it could continue (with a device_id of 0x00000000) which would then return false, ultimately triggering the "ERROR: unknown/unsupported device or programmer not connected." message to be printed.


SBC used: Raspberry Pi Zero W picberry Version: v0.2 Shell output (first line is the command used):

picberry -w ./pic.production.hex -f pic32mx3 -g 26,19,13
picberry PIC Programmer v0.2
Timeout occurred checking device status!
WallaceIT commented 2 years ago

Hi,

as you might have imagined, the project is not actively maintained anymore. Feel free, however, to open a merge request with the solution you proposed (which I think is correct).

Thank you