Sunday, March 22, 2015

Chip programming with Linux 1 - PICkit version2 clone under Linux / Freebsd / Mac OS


Description    : Installing PICkit version2 clone for Linux / Mac.


            











Compatibility : Linux kernel 2.4 or 2.6. ( Tested )
                                   FreeBSD                        ( NOT Tested
                          Mac OSX 10.4                ( NOT Tested
                          Mac OSX 10.5                ( NOT Tested )
                          OS X Mavericks 10.9.2  ( Tested )

Steps :

1. Login as root

Command  : su
                  
2. PICkit version2 clone drivers for Linux / Mac

Commands : yum install gcc-c++
                     yum install libusb1-devel
                     yum install libusb-devel


3. Download PICkit version2 clone software for Linux / Mac

URL : Pickit2 Tool for Linux

4. Change directory to download location

Command : cd /home/developer64/Downloads/

5. Extract source code

Command : tar zxvf pk2cmdv1.20LinuxMacSource.tar.gz

6. Change directory to source code folder

Command : cd pk2cmdv1.20LinuxMacSource

7. Check your Linux kernel vernal version

Command : uname -r  

My Linux kernel version is 2.6.32-504.12.2.el6.x86_64


8. Build the source code

This software comes with source code. So you can view the source code and change according to your Operating System. It is written in C++ and you can improve the source code according your requirement.

 
Command for Linux Kernel version start with 2.6 : make linux  
  
Command for Linux Kernel version start with 2.4 : make linux-old

Command for FreeBSD                                         : make freebsd

Command for Mac OS 10.4                                   : make mac104

Command for Mac OS 10.5                                   : make mac105


9. Copy relevant files to /usr/local/bin


Command : cp pk2cmd /usr/local/bin
                   cp PK2DeviceFile.dat /usr/local/bin/
                   cp PK2V023200.hex /usr/local/bin/


10. Now check your software version

Command : pk2cmd -?V

Executable Version:    1.20.00
Device File Version:   1.55.00
OS Firmware Version:   PICkit 2 not found

 

Cheers we have successfully installed. Yet to configure it. It says  PICkit 2 not found as PICkit2 device not connected with my computer

           
11. Create Driver Manager Empty Rule File

Command : echo "" > /etc/udev/rules.d/99-pickit2.rules

12. Open the file
  
Command : gedit /etc/udev/rules.d/99-pickit2.rules

13. Add bellow rule content to /etc/udev/rules.d/99-pickit2.rules and save the file
  
SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device",SYSFS{idVendor}=="04d8" , SYSFS{idProduct}=="0033", MODE="0666"


14. Now reload Linux Driver Manager Rules
  
Command : udevadm control --reload-rules

15. Now connect your PICkit2 USB device without PIC chipset

16. Check the device connectivity with your computer
  
Command : pk2cmd -?V

Result       :  Executable Version:    1.20.00
                    Device File Version:   1.55.00
                    OS Firmware Version:   2.32.00


                    Operation Succeeded

Cheers. It says Operation Succeeded

16. Mount your PIC Chipset in right direction on your device.

Refer bellow picture.

17. Now connect your PICkit2 USB device 













17. Run Auto detection command. This will identify PIC Chipset

Command : pk2cmd -P


Result       :  Auto-Detect: Found part PIC16F877A.

                    Operation Succeeded


My PIC chip is PIC16F877A



18. Erasing chipset

Command : pk2cmd -P PIC16F877A -X -E
 
Result       :  Erasing Device...

                    Operation Succeeded


19. Installing hexadecimal file in to chipset. 
      Hexadecimal file will include all execution steps of the firmware. 
      We will discuss how to write small program for LED display, Sensor  
      readings, Motor controllers and etc..

      We will be able to write firmware based on Micro C language Micro C IDE.
      Then we will convert it in to HEX file.


For the moment we will use existing HEX file PK2V023200.hex located in same place pk2cmdv1.20LinuxMacSource


Command : pk2cmd -P PIC16F877A -X -M -F PK2V023200.hex
 
Result       :  PICkit 2 Program Report
                    22-3-2015, 23:29:55
                    Device Type: PIC16F877A

                    Program Succeeded.

                    Operation Succeeded

Now it says, it wrote given Hex file in to chipset called PIC16F877A.


19. Verify Hex file against Chipset memory issues


Command : pk2cmd -P PIC16F877A -Y -F PK2V023200.hex
 
Result       :  PICkit 2 Verify Report
              22-3-2015, 23:44:49
              Device Type: PIC16F877A

              EEData Memory Errors

              Address   Good     Bad
              000000    0000EA   000000


It seems everything is OK.


20. Power ON Chipset


Command : pk2cmd -P PIC16F877A -T
 
Result       :  Operation Succeeded
Now you can see power indicator LED is working


21. Power OFF Chipset


Command : pk2cmd -P PIC16F877A
 
Result       :  Operation Succeeded
Now you can see power indicator LED is NOT working




In next post we will install Micro C IDE, C compilers dedicated to Micro C IDE. Then we will develop some hobby circuits such as LED controllers, Motor controllers, sensor readers and many more.

Thank you.