Giter Club home page Giter Club logo

picberry's Introduction

picberry

PIC Programmer using GPIO connector

Copyright 2017 Francesco Valla

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Overview

picberry is a PIC programmer using GPIOs that doesn't require additional programming hardware.

It theorically supports dsPIC33E/PIC24E, dsPIC33F/PIC24H, PIC24FJ, PIC18FxxJxx, PIC32MX, PIC32MZ and PIC32MK families, but only some PICs have been tested.

Supported hosts

Currently picberry has support for the following host boards/processors:

Support for additional boards and processors can be easily added, providing the following macro in a header file inside the hosts folder:

/* GPIO registers address */
#define GPIO_BASE		// base address for the GPIO controller
#define BLOCK_SIZE		// size of the GPIO bank
#define PORTOFFSET		// port offset for letter-defined gpios

/* GPIO setup macros */
#define GPIO_IN(g)		// set gpio g as input
#define GPIO_OUT(g)		// set gpio g as output
#define GPIO_SET(g)		// set gpio g as high
#define GPIO_CLR(g)		// set gpio g as low
#define GPIO_LEV(g)		// read level of gpio g

/* default GPIO <-> PIC connections */
#define DEFAULT_PIC_CLK		// default gpio for PGC line
#define DEFAULT_PIC_DATA	// default gpio for PGD line
#define DEFAULT_PIC_MCLR	// default gpio for MCLR line

A build rule inside the Makefile for the specific platform has to be added too.

Building and Installing picberry

picberry is written using C++11 features, so it requires at least g++ version 4.7.

To build picberry launch make TARGET, where TARGET can be one of the following:

TARGET Processor/Board
raspberrypi Raspberry Pi v1 or Zero
raspberrypi2 Raspberry Pi v2 or v3
raspberrypi4 Raspberry Pi 4A or 4B or CM4
am335x Boards based on TI AM335x (BeagleBone)
a10 Boards based on Allwinner A10 (Cubieboard)

Then launch sudo make install to install it to /usr/bin.

To change destination prefix use PREFIX=, e.g. sudo make install PREFIX=/usr/local.

For cross-compilation, given that you have the required cross toolchain in you PATH, simply export the CROSS_COMPILE variable before launching make, e.g. CROSS_COMPILE=arm-linux-gnueabihf- make raspberrypi2.

Using picberry

picberry [options]

Programming Options

--help,             -h                print help
--server=port,      -S port           server mode, listening on given port
--log=[file],       -l [file]         redirect the output to log file(s)
--gpio=PGC,PGD,MCLR -g PGC,PGD,MCLR   GPIO selection in form [PORT:]NUM (optional)
--family=[family],  -f [family]       PIC family [default: dspic33f]
--read=[file.hex],  -r [file.hex]     read chip to file [defaults to ofile.hex]
--write=file.hex,   -w file.hex       bulk erase and write chip
--erase,            -e                bulk erase chip
--blankcheck,       -b                blank check of the chip
--regdump,          -d                read configuration registers
--noverify                            skip memory verification after writing
--debug                               turn ON debug
--fulldump                            don't detect empty sections, make complete dump (PIC32)
--program-only                        read/write only program section (PIC32)
--boot-only                           read/write only boot section (PIC32)

Runtime Options

-reset, -R                           reset

For Example, to connect the PIC to RPi GPIOs 11 (PGC), 9 (PGD), 22 (MCLR) and write on a dsPIC33FJ128GP802 the file fw.hex:

picberry -w fw.hex -g 11,9,22 -f dspic33f

To connect the PIC to A10 GPIOs B15 (PGC), B17 (PGD), I15 (MCLR):

picberry -w fw.hex -g B:15,B:17,I:15 -f dspic33f

Programming Hardware

To use picberry you will need only the "recommended minimum connections" outlined in each PIC datasheet.

Between PIC and the SoC you must have the four basic ICSP lines: PGC (clock), PGD (data), MCLR (Reset), GND. You can also connect PIC VDD line to target board 3v3 line, but be careful: such pins normally have low current capabilities, so consider your circuit current drawn!

If not specified in the command line, the default GPIOs <-> PIC connections are the following:

for the Raspberry Pi:

PGC  <-> GPIO23
PGD  <-> GPIO24
MCLR <-> GPIO18

for the Allwinner A10:

PGC  <-> PB15
PGD  <-> PB17
MCLR <-> PB12

for BeagleBone Black (AM335x):

PGC  <-> GPIO60 (P9.12)
PGD  <-> GPIO49 (P9.23)
MCLR <-> GPIO48 (P9.15)

Remote GUI

Remote GUI is written in Qt5 and allows to control a picberry session running in server mode (that is, launched with the -S <port> command line argument).

To compile it, just launch qmake and then make in the remote_gui folder.

References

Licensing

picberry is released under the GPLv3 license; for full license see the LICENSE file.

The Microchip name and logo, PIC, In-Circuit Serial Programming, ICSP are registered trademarks of Microchip Technology Incorporated in the U.S.A. and other countries.

Raspberry Pi is a trademark of The Raspberry Pi Foundation.

picberry's People

Contributors

akimasa avatar andreysv avatar matthewlh avatar mikedk avatar wallaceit avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

picberry's Issues

Regarding programming PIC from raspberry pi using picberry software tool

I found the Device Libraries(.h and .cpp) which supports "PIC24FJ256GB206" in Available PIC Families "pic24fjxxxga3xx"
I had followed the installation steps of picberry using the link: https://github.com/WallaceIT/picberry
And I tried to flash the PIC board of controller "PIC24FJ256GB206" using below command and It is giving me ERROR.

root@raspberrypi:/home/pi/vendingserver/picberry# sudo picberry -w Elock2.54.X.test_release.hex
picberry PIC Programmer v0.2
Device ID: 0xffff
ERROR: unknown/unsupported device or programmer not connected.
Press ENTER to exit program mode...

Could you please tell me where i am getting wrong or please let me know how to debug this issue?
If any one tried this with other PIC controller and got the result, Please guide me.

Beaglebone GPIO -g issue

If I use a gpio that is 3 digits then I am unable to launch Picberry. (Ex: -g 76,115,74)...upon execution I just get the picberry PIC Programmer v0.2 response and the program ends.

Support for pic24fj (PIC24FJ64GA002)

Nice work! I was finding a tool like this to program a PIC24FJ64GA002 and by chance I found your project. I saw that in theory PIC24FJ should work but I've problems trying to read the device id of a PIC24FJ64GA002 device.

picberry -e -g 66,67,60 -f pic24fj
picberry PIC Programmer v0.1
Device ID: 0x0
ERROR: unknown/unsupported device or programmer not connected.

I think your code is based on [2] but the programming specs for my chip is slightly different [1]. At the moment I tried to modify the code to adapt to [1] without luck. Any clue is welcome. Which device did you test?

[1] http://ww1.microchip.com/downloads/en/DeviceDoc/39768d.pdf
[2] http://ww1.microchip.com/downloads/en/DeviceDoc/30010057d.pdf

INHX32 is not fully supported

Hi,

when read_inhx() function runs it fails in checksum comparison.

e.g.:

line 2530 (35 bytes): ':0B9D20004A943366CC831D3A74E8CBF4\r\n'
byte_count = 0x0B
address = 0x9D20
record_type = 0x00 (data)
data = 0x944A @0x00004E90
data = 0x6633 @0x00004E91
data = 0x83CC @0x00004E92
data = 0x3A1D @0x00004E93
data = 0xE874 @0x00004E94
checksum = 0xCB
Error: checksum does not match. Calculated = 0xBF, Read = 0xCB

In file, checksum is supposed to be 0xF4.
In read_inhx(), checsum is computed as 0xCB.

When byte_count is odd, the for loop ignore the last char :

for(i = 0; i < byte_count/2; i++) {
nread = sscanf(&line[9+4*i], "%4hx", &data);
if (nread != 1) {
	cerr << "Error: cannot read data." << endl;
	return 0;
}
tmp = data;
data = (data >> 8) | (tmp << 8);
if (flags.debug) fprintf(stderr, "  data        = 0x%04X", data);
checksum_calculated += (data >> 8) & 0xFF;
checksum_calculated += data & 0xFF;

extended_address = ( ((uint32_t)base_address << 16) | address);
if (flags.debug)
	fprintf(stderr, " @0x%08X\n", extended_address/2+i);

mem->location[extended_address/2 + i - offset/2] = data;
mem->filled[extended_address/2 + i - offset/2] = 1;
filled_locations++;
}

A part of my hex file is :

:109D1000D4B37DFAEFC5913972E4D3BD61C29F25FA
:0B9D20004A943366CC831D3A74E8CBF4
:049D2C002BD9E150FE
:109D3000F90F23D9000ED880EE54000EED5425E221

May be I can link the code to fill 16bit location. But it does'nt seem possible with MPLAB C18.

Regards,

Marco

ERROR at address 000000: written 0200 but 0000 read!

picberry PIC Programmer v0.3
Device Name: PIC24FJ256GB106
Device ID: 0x00001019
Revision: 0x00000004
Writing chip...[[ 0%]]

ERROR at address 000000: written 0200 but 0000 read!

DONE!
Exiting program mode...

Hi,

I am facing above issue while programming using picberry, Any idea what might be wrong.

compilation fails

had to mkdir -p build/devices and change g++-4.7 to g++-4.9 in the makefile

even so, compilation fails at

src/gpio_test.cpp:93:93: error: expression cannot be used as a function
cout << "BASE ADDRESS " << hex << GPIO_BASE << " + OFFSET " << hex << OFFSET(tested_gpio) << " = FINAL ADDRESS " << hex << GPIO_BASE + OFFSET(tested_gpio) << endl;

(bold for emphasis mine)

PIC24FJ64GA1/GB0 Support?

HI,

I'm trying to determine whether this utility can work with, or be modified to work with the PIC24FJ64GA1/GB0 family of chips. relevant programming reference

Looking at the source code for the unified PIC24FJ/dspic33e families, it doesn't look like that option is compatible with the programming specification for the GA1/GB0 families...but the PIC24FJXXGA0XX code does look close to compatible, if not completely (haven't had a chance to test it yet).

My question is: in the case that they aren't completely compatible, whether or not you had any suggestions/direction in augmenting the code to make it work?

Thanks!

Program hangs if programmer not connected - PIC32

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!

Beaglebone default gpios

I was looking at your default mclr gpio for beaglebone. I am unable to locate gpio 40. Is this a typo/mistake?

chip PIC18LF46K22 is supported?

Hello, nice code. As I understand your code supports pic18fj but what about the chip PIC18LF46K22? Does it belong to any of the proposed families?
Thanks

Support for pic32

I would like to see support for pic32 chips especially since they aren't supported by pickit2 or any other Free tools I've found.

PIC32MZ2048 issue

After Entering Serial Execution Mode, the PIC hangs on XferInstruction 0x34050800 because the PRACC bit indicates that the processor is busy after adding in SetModes where the documentation specifies. Running without SetModes returns Error Unsupported Device... Device ID is 0x0.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.