Mini-howto for PICKit 2 under Linux with pk2.

276 views
Skip to first unread message

Xiaofan Chen

unread,
Jun 10, 2007, 11:00:07 AM6/10/07
to pickit-devel
As part of my Blog experiment, I wrote a mini-howto on PICKit 2 under
Linux with pk2.
Comments are welcome so that I can improve it.

http://mcuee.blogspot.com/
I know it is not formatted very well ;-(

Darrell

unread,
Jul 27, 2007, 7:40:24 PM7/27/07
to pickit-devel
Xiaofan, I was real excited to see this post. But, alas, I think my
issues are more fundamental.

Is there a particular location to put the pk2 source code? The reason
is that I have tried both FC6 and FC7 and keeping running into issues
of not finding certain .h files in the search path. Probably
incorrectly, I add another -I option which fixes one "no such .h file"
only to create another. So, I add another -I for that one, and so on.
This surely is incorrect. It would seem that most folks just type
"make" and things progress.

For example, the first one I encounter is not finding usb.h. However,
I find it at /usr/src/kernels/2.6.20-1.2962.fc6-i686/include/linux so
add a -I for this path. Next compile attempt it seems that it can't
find compiler.h which is in the directory above where I found usb.h.
So, I add a -I option for that. And on and on. Clearly, this is nuts.
What am I missing that is so fundamental here?

Is the an easy way to check if libusb is installed correctly? Is usb.h
part of this or is it separate? Why would Fedora be so different from
Ubuntu when it comes to compiling the source?

So, this is where I can use some help. Seems that "make" is a pretty
big leap! It's probably obvious stuff to you experts but not for all
of us ... some hints would be greatly appreciated in the Mini How-To.

By the way, I tried Piklab too but got as far as the error "usb.h not
found, use ./configure LIBUSB_CFLAGS=..." which isn't helping me much
other than maybe confirming that my directories are not quite right.
Typing locate usb.h does indeed find the file.

I've tried on different computers, one on a fresh install and always
have this same problem. I should get points for consistency.

While I've got some experience with C for scientific computing,
building code within an environment such as Linux is a new experience.
The documentation available is overwhelming to the point of overload
when you don't know what you're doing. That seems to be the root of my
problems.

Jeff

unread,
Jul 27, 2007, 10:17:45 PM7/27/07
to pickit...@googlegroups.com
On Fri July 27 2007 16:40, Darrell wrote:
>
> Is there a particular location to put the pk2 source code?

Nope. Put it anywhere you want.


>
> For example, the first one I encounter is not finding usb.h.

Xiaofan is the USB expert, so hopefully he has some ideas on this. I wonder
though, is usb.h really so different on various Linux installations? Could we
not include usb.h in the pk2 distribution and expect it to work on all or
most systems? Xiaofan, what do you think?

BTW, work on pk2 version 3 has once again been delayed due to unforeseen
obligations on my part. I apologize for the excessive delays, but I am trying
to get at least a beta version available as soon as I can. Part of the
problem is trying to hit the moving target of features in releases of
Microchip's application code. I've decided to lock onto version 2.30 and
ignore any further enhancements in their code until after the first release
of pk2 v3.

Jeff

Xiaofan Chen

unread,
Jul 27, 2007, 10:50:19 PM7/27/07
to pickit...@googlegroups.com
On 7/27/07, Jeff <j_p...@pacbell.net> wrote:
>
> On Fri July 27 2007 16:40, Darrell wrote:
> >
> > Is there a particular location to put the pk2 source code?
>
> Nope. Put it anywhere you want.
> >
> > For example, the first one I encounter is not finding usb.h.
>
> Xiaofan is the USB expert, so hopefully he has some ideas on this. I wonder
> though, is usb.h really so different on various Linux installations? Could we
> not include usb.h in the pk2 distribution and expect it to work on all or
> most systems? Xiaofan, what do you think?

I am not an USB expert and actually I just restart my real
USB learning using PICkit 2.
http://forum.microchip.com/tm.aspx?m=267849

I think he did not install libusb and libusb-devel. The two is needed
to compile and run pk2. pk2 should not include usb.h since it is
changing.

> BTW, work on pk2 version 3 has once again been delayed due to unforeseen
> obligations on my part. I apologize for the excessive delays, but I am trying
> to get at least a beta version available as soon as I can. Part of the
> problem is trying to hit the moving target of features in releases of
> Microchip's application code. I've decided to lock onto version 2.30 and
> ignore any further enhancements in their code until after the first release
> of pk2 v3.
>

Yeah I agree. Microchip is fast in improving the functionality of PICKit 2.

Xiaofan

Xiaofan Chen

unread,
Jul 27, 2007, 11:02:21 PM7/27/07
to pickit...@googlegroups.com
On 7/27/07, Darrell <dus...@barabashtx.us> wrote:
>
> For example, the first one I encounter is not finding usb.h. However,
> I find it at /usr/src/kernels/2.6.20-1.2962.fc6-i686/include/linux so
> add a -I for this path. Next compile attempt it seems that it can't
> find compiler.h which is in the directory above where I found usb.h.
> So, I add a -I option for that. And on and on. Clearly, this is nuts.
> What am I missing that is so fundamental here?

That is not libusb.

> Is the an easy way to check if libusb is installed correctly? Is usb.h
> part of this or is it separate? Why would Fedora be so different from
> Ubuntu when it comes to compiling the source?

You need to install libusb and libusb-devel. There are no big differences
even though the package installation method is different (rpm vs deb,
yum vs apt).

Ubuntu: apt-get install libusb libusb-devel
Fedora core: yum install libusb libusb-devel

Read some Faqs for Linux distributions will help.
http://www.fedorafaq.org/
http://ubuntuguide.org/

For Piklab, you need to install more packages.
http://piklab.sourceforge.net/wiki/index.php/Compilation_for_Linux

Regards,
Xiaofan

Darrell

unread,
Jul 29, 2007, 2:20:06 PM7/29/07
to pickit-devel
Problem solved ... the error was indeed that libusb was not installed
(correctly). It appears to be installed but needs to be reinstalled.
Or, at least, that is what I found on three different PCs using either
FC6 or FC7.

On a PC with a fresh Fedora FC6 installation it looks like libusb is
already there:
[darrell@garage ~]$ rpm -qa | grep usb
libusb-0.1.12-5.1
xorg-x11-drv-sisusb-0.8.1-4.1
usbutils-0.71-2.1

But, I am unable to "make" pk2 or piklib with this installation.
Downloaded a fresh version of libusb from Sourceforge and followed the
provided instructions exactly.
% gzip -cd libusb-0.1.12.tar.gz | tar xvf - # unpack the sources
% cd libusb-0.1.12 # change to the toplevel
directory
% ./configure # run the `configure' script
% make # build libusb
[ Become root if necessary ]
% make install # install libusb

With this done, everything compiles fine. However, when I run pk2 I
get the following error:
[root@pluto darrell]# pk2 --config
PK2 version 2.04 - 2006/12/17
pk2 --config
Locating USB Microchip PICkit2 (vendor 0x04d8/product 0x0033)
Found USB PICkit as device '012' on USB bus 003
sendUSB() PICkit write : Invalid argument
Fatal error> sendUSB() PICkit USB write failed

Not deterred, I was able to build piklab and it works fine and without
any errors as long as I run as root. It communicates properly with
either pickit1 or pickit2 programmers.

I was also able to build usb_pickit_1.5-jeb. It too works fine with
the pickit1 programmer but needs the patch that Xiaofan had posted
last year:
> You can try to patch usb_pickit.c under Linux.
> if (d){
> /* add the following to detach the kernel HID driver under
Linux */
> int retval;
> char dname[32] = {0};
> retval = usb_get_driver_np(d, 0, dname, 31);
> if (!retval)
> usb_detach_kernel_driver_np(d, 0);
> /* End of added code */

Thanks everyone for the hints. They really helped! Maybe these notes
will help someone else too.

Best regards,
Darrell ...

On Jul 27, 10:02 pm, "Xiaofan Chen" <xiaof...@gmail.com> wrote:
>
> You need to install libusb and libusb-devel. There are no big differences
> even though the package installation method is different (rpm vs deb,
> yum vs apt).
>
> Ubuntu: apt-get install libusb libusb-devel
> Fedora core: yum install libusb libusb-devel
>

> Read some Faqs for Linux distributions will help.http://www.fedorafaq.org/http://ubuntuguide.org/


>
> For Piklab, you need to install more packages.http://piklab.sourceforge.net/wiki/index.php/Compilation_for_Linux
>
> Regards,
> Xiaofan


On Jul 27, 10:02 pm, "Xiaofan Chen" <xiaof...@gmail.com> wrote:


> On 7/27/07, Darrell <dust...@barabashtx.us> wrote:
>
>
>
> > For example, the first one I encounter is not finding usb.h. However,
> > I find it at /usr/src/kernels/2.6.20-1.2962.fc6-i686/include/linux so
> > add a -I for this path. Next compile attempt it seems that it can't
> > find compiler.h which is in the directory above where I found usb.h.
> > So, I add a -I option for that. And on and on. Clearly, this is nuts.
> > What am I missing that is so fundamental here?
>
> That is not libusb.
>
> > Is the an easy way to check if libusb is installed correctly? Is usb.h
> > part of this or is it separate? Why would Fedora be so different from
> > Ubuntu when it comes to compiling the source?
>
> You need to install libusb and libusb-devel. There are no big differences
> even though the package installation method is different (rpm vs deb,
> yum vs apt).
>
> Ubuntu: apt-get install libusb libusb-devel
> Fedora core: yum install libusb libusb-devel
>

> Read some Faqs for Linux distributions will help.http://www.fedorafaq.org/http://ubuntuguide.org/

Mark Rages

unread,
Jul 29, 2007, 2:44:39 PM7/29/07
to pickit...@googlegroups.com
On 7/29/07, Darrell <dus...@barabashtx.us> wrote:
>
> Problem solved ... the error was indeed that libusb was not installed
> (correctly). It appears to be installed but needs to be reinstalled.
> Or, at least, that is what I found on three different PCs using either
> FC6 or FC7.
>
> On a PC with a fresh Fedora FC6 installation it looks like libusb is
> already there:
> [darrell@garage ~]$ rpm -qa | grep usb
> libusb-0.1.12-5.1
> xorg-x11-drv-sisusb-0.8.1-4.1
> usbutils-0.71-2.1
>

You need to install the Fedora "libusb-devel" package to get the
headers to be able to compile against libusb.

Installing from source (what you did) works too, but now you have two
packages: the Fedora one and your custom one. Sometimes this causes
problems, but that's not likely in this case, since the versions are
the same.

For future reference, the command to see which package holds a header
file looks like this:

$ yum whatprovides /usr/include/usb.h


Regards,
Mark
markrages@gmail
--
Mark Rages, Engineer
Midwest Telecine LLC
mark...@midwesttelecine.com

Xiaofan Chen

unread,
Jul 29, 2007, 2:55:59 PM7/29/07
to pickit...@googlegroups.com
On 7/29/07, Darrell <dus...@barabashtx.us> wrote:
> With this done, everything compiles fine. However, when I run pk2 I
> get the following error:
> [root@pluto darrell]# pk2 --config
> PK2 version 2.04 - 2006/12/17
> pk2 --config
> Locating USB Microchip PICkit2 (vendor 0x04d8/product 0x0033)
> Found USB PICkit as device '012' on USB bus 003
> sendUSB() PICkit write : Invalid argument
> Fatal error> sendUSB() PICkit USB write failed

Did you try it as root? It should work.
Did you patch the file pk2usb.c as per the mini-howto? You need
to do that under later Linux distributions and Mac.
Eg: http://forum.microchip.com/tm.aspx?m=241692

> Not deterred, I was able to build piklab and it works fine and without
> any errors as long as I run as root. It communicates properly with
> either pickit1 or pickit2 programmers.
>

If you do not want to run pk2/piklab as root, you need to set up
udev rules under FC5/FC6 (hopefully the same rules work
under FC7). Please try it and report back. Thanks.
http://piklab.sourceforge.net/wiki/index.php/Port_connection_problems

Thanks for sharing your experiences. I will add some notes to the
Howto when I get the time.

Xiaofan

Darrell

unread,
Jul 29, 2007, 5:53:09 PM7/29/07
to pickit-devel
On Jul 29, 1:44 pm, "Mark Rages" <markra...@gmail.com> wrote:

> You need to install the Fedora "libusb-devel" package to get the
> headers to be able to compile against libusb.
>
> Installing from source (what you did) works too, but now you have two
> packages: the Fedora one and your custom one. Sometimes this causes
> problems, but that's not likely in this case, since the versions are
> the same.

Darn, I guess I was lucky. I don't suppose there is any easy recovery?

> For future reference, the command to see which package holds a header
> file looks like this:
>
> $ yum whatprovides /usr/include/usb.h

This will be a very handy tip. Thanks Mark!

Best Regards,
Darrell

Darrell

unread,
Jul 29, 2007, 6:19:01 PM7/29/07
to pickit-devel
On Jul 29, 1:55 pm, "Xiaofan Chen" <xiaof...@gmail.com> wrote:

> Did you try it as root? It should work.
> Did you patch the file pk2usb.c as per the mini-howto? You need
> to do that under later Linux distributions and Mac.

Yes, the problem was that I didn't apply the patch. With that it then
pk2 runs fine as root. I will
try setting up the udev rules and report back.

Thanks again everyone!
Darrell ...

Darrell

unread,
Jul 29, 2007, 8:47:53 PM7/29/07
to pickit-devel
On Jul 29, 1:55 pm, "Xiaofan Chen" <xiaof...@gmail.com> wrote:

> If you do not want to run pk2/piklab as root, you need to set up
> udev rules under FC5/FC6 (hopefully the same rules work
> under FC7). Please try it and report back. Thanks. http://piklab.sourceforge.net/wiki/index.php/Port_connection_problems

Yes, this works just as advertised Xiaofan. I tried pk2 and piklab and
both work without being root.

Thanks again all for the help!
Darrell ...

Xiaofan Chen

unread,
Jul 29, 2007, 9:42:52 PM7/29/07
to pickit...@googlegroups.com
On 7/29/07, Darrell <dus...@barabashtx.us> wrote:
> > If you do not want to run pk2/piklab as root, you need to set up
> > udev rules under FC5/FC6 (hopefully the same rules work
> > under FC7). Please try it and report back. Thanks.
> > http://piklab.sourceforge.net/wiki/index.php/Port_connection_problems
>
> Yes, this works just as advertised Xiaofan. I tried pk2 and piklab and
> both work without being root.
>
Glad that it works for you. Thanks for reporting back.

Xiaofan

sullivan.t

unread,
Aug 7, 2007, 9:44:10 AM8/7/07
to pickit-devel
Has anyone been able to successfully get this to work (piklab and
such) with a pickit2 that has firmware > 2.0?

(I don't mind going back, I was just curious.)

Xiaofan Chen

unread,
Aug 7, 2007, 7:32:29 PM8/7/07
to pickit...@googlegroups.com

Not yet. Jeff is working on pk2-3.0 and it will support V2.x firmware.
Nicolas tried to add the support to piklab but he has not the time to
finish the work.


Xiaofan

Kiddjmadd

unread,
Sep 8, 2007, 11:56:32 AM9/8/07
to pickit-devel
I have similar firmware issue but was unable to find the < 2.0 version
firmware. Will older version firmware work with PICkit 2 debug express
programmer (has the red button, I read somewhere that's important). If
so, can anyone point me in right direction for old firmware?

Thanks,
Jesse

On Aug 7, 7:32 pm, "Xiaofan Chen" <xiaof...@gmail.com> wrote:

joseph...@gmail.com

unread,
Sep 9, 2007, 5:44:27 PM9/9/07
to pickit-devel
On Sep 8, 11:56 am, Kiddjmadd <mad...@alum.rpi.edu> wrote:
> I have similar firmware issue but was unable to find the < 2.0 version
> firmware. Will older version firmware work with PICkit 2 debug express
> programmer (has the red button, I read somewhere that's important). If
> so, can anyone point me in right direction for old firmware?

I don't know if it works, but here's a link to old firmware versions

http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en023073

Reply all
Reply to author
Forward
0 new messages