Difference between revisions of "Compiling PIC projects"
Line 5: | Line 5: | ||
Microchip's tools are all Windows-only, but there are beta version available for Linux and Mac. | Microchip's tools are all Windows-only, but there are beta version available for Linux and Mac. | ||
+ | |||
+ | |||
+ | |||
+ | ==IDE== | ||
+ | Download and install Microchip's [http://en.wikipedia.org/wiki/Integrated_development_environment IDE] called [http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en019469&part=SW007002 MPLAB]. | ||
+ | |||
+ | [http://devupdates.microchip.com/mplab/Files/installer.html MPLABX] is Microchip's new cross-platform IDE and compilers for Windows, Linux, and Mac. | ||
+ | |||
+ | ==C compiler== | ||
+ | Some projects require a C compiler. We use Microchip's free demonstration compilers with MPLAB. The demo compilers have certain optimizations that expire after 60 days, but we don't use those anyway. | ||
+ | |||
+ | * [http://www.microchip.com/C18 C18 Compiler for PIC 18F] | ||
+ | * [http://www.microchip.com/C30 C30 Compiler for PIC 24F/33F] | ||
+ | |||
+ | {|class="wikitable" border="1" | ||
+ | | '''Project''' | ||
+ | | '''PIC''' | ||
+ | | '''Compiler''' | ||
+ | |- | ||
+ | | #twatch | ||
+ | | 18F67J60 | ||
+ | | C18 | ||
+ | |- | ||
+ | | USB IR Toy | ||
+ | | 18F2550 | ||
+ | | C18 | ||
+ | |- | ||
+ | | Flash Destroyer | ||
+ | | 18F2550 | ||
+ | | C18 | ||
+ | |- | ||
+ | | Logic Sniffer | ||
+ | | 18F24J50 | ||
+ | | C18 | ||
+ | |- | ||
+ | | Bus Pirate | ||
+ | | 24FJ64GA002 | ||
+ | | C30 | ||
+ | |- | ||
+ | | Web Platform | ||
+ | | 33FJ128GP204 | ||
+ | | C30 | ||
+ | |} | ||
+ | |||
+ | ==Non-distributables== | ||
+ | A problem we're still working around is Microchip's source code license. The source is freely available from the Microchip website, but they don't allow us to distribute it. | ||
+ | |||
+ | You need to download and install the Microchip source yourself. Drag the Dangerous Prototypes source folder into the install location (usually Microchip Solutions). We're working on alternatives, as listed below. | ||
+ | |||
+ | {|class="wikitable" border="1" | ||
+ | | '''Source''' | ||
+ | | '''Used in''' | ||
+ | | '''Open Alternatives''' | ||
+ | |- | ||
+ | | [http://www.microchip.com/tcpip "free" TCP/IP stack] ([http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=2896 old versions] now available) | ||
+ | | #twatch, Web Platform | ||
+ | | [http://dangerousprototypes.com/category/uip/ uIP stack port] | ||
+ | |- | ||
+ | | [http://www.microchip.com/mdd "free" FAT32 file system] | ||
+ | | Web Platform | ||
+ | | [http://www.roland-riegel.de/sd-reader/index.html 1] [http://www.larwe.com/zws/products/dosfs/index.html DosFS] [http://elm-chan.org/fsw/ff/00index_e.html FatFs] | ||
+ | |- | ||
+ | | [http://www.microchip.com/usb "free" USB stack] | ||
+ | | <s>USB IR Toy</s>, Logic Sniffer | ||
+ | | The JTR-Honken USB stack is now running on the USB IR Toy firmware v20+ | ||
+ | |} | ||
+ | |||
+ | ==Compiling== | ||
+ | #Open the project in MPLAB | ||
+ | #Compile the project (down arrow stack of papers icon) | ||
+ | You may need to modify the compiler location when prompted, but MPLAB is getting better about making these changes automatically. | ||
+ | |||
+ | ==Export for bootloader== | ||
+ | |||
+ | Some compiled firmware must be exported in order to work with the bootloader. | ||
+ | ===Exporting in MPLAB X=== | ||
+ | |||
+ | If you need to configure the program memory area end address (see table below), this needs to be done in the project's settings before compiling and exporting: | ||
+ | |||
+ | # To configure the end address in MPLAB X, go to ''File -> Project Properties'' and select the configuration (usually ''Conf: default'') from the list on the left. | ||
+ | # Select a PIC programmer device from the list on the right; if you don't actually have any of the devices, select ''PICKit3''. | ||
+ | # Click ''Apply''. | ||
+ | # Select the PIC programming device (e.g., ''PICKit3'') from list on the ''left''. | ||
+ | # Select ''Memories to Program'' from the menu on the right. | ||
+ | # Set the option ''Auto select memories and ranges'' to ''Manually select memories and ranges''. | ||
+ | # Tick the box for ''Program Memory'' and below that enter the end value (from the table below) | ||
+ | # Click OK to close the settings. | ||
+ | |||
+ | After configuring the end address (if required), build the project by selecting ''Run -> Clean and build main project'' (or select ''Clean and build'' from the project's context menu). This creates a ''.hex'' file in the build directory (the last few lines of the build output should mention its name and path). | ||
+ | |||
+ | You can also export the ''.hex'' file by selecting ''Export hex'' from the project's context menu (right-click the project's name in the project list to bring up the menu). | ||
+ | |||
+ | ===Exporting in MPLAB 8=== | ||
+ | |||
+ | [[Image:Mplab-export_001.png ]] | ||
+ | |||
+ | |||
+ | #In MPLAB 8, go to ''File->Export...'' | ||
+ | #Make sure that ''Program Memory'' is checked and the ''Configuration Bits'' box matches the required setting | ||
+ | #Change the export end address if needed (see table below) | ||
+ | #Make sure INHX32 (Intel 32bit HEX) is selected on the ''File Format'' tab | ||
+ | #Click OK to export the firmware. | ||
+ | |||
+ | ===Project-specific export settings=== | ||
+ | |||
+ | {|class="wikitable" border="1" | ||
+ | | '''Project''' | ||
+ | | '''Required?''' | ||
+ | | '''End address''' | ||
+ | | '''Config bits?''' | ||
+ | | '''EEPROM?''' | ||
+ | |- | ||
+ | | #twatch | ||
+ | | yes | ||
+ | | 0x1dbbf | ||
+ | | yes | ||
+ | | - | ||
+ | |- | ||
+ | | Bus Pirate v3 (bootloader v4.x) | ||
+ | | yes | ||
+ | | 0xa7fa | ||
+ | | no | ||
+ | | - | ||
+ | |- | ||
+ | | Logic Sniffer | ||
+ | | yes | ||
+ | | (default) | ||
+ | | no | ||
+ | | - | ||
+ | |- | ||
+ | | USB Infrared Toy | ||
+ | | no | ||
+ | | (default) | ||
+ | | yes | ||
+ | | optional | ||
+ | |- | ||
+ | | Web Platform | ||
+ | | no | ||
+ | | 0×153fe | ||
+ | | yes | ||
+ | | - | ||
+ | |- | ||
+ | | Flash Destroyer | ||
+ | | no | ||
+ | | (default) | ||
+ | | yes | ||
+ | | optional | ||
+ | |- | ||
+ | | Bus Pirate v4 | ||
+ | | no | ||
+ | | (default) | ||
+ | | yes or no | ||
+ | |} | ||
+ | |||
+ | Note: If an end address is required but the value in the table above is not accepted, it may be that the value is required to be of the form (0x100 * ''n'' – 1). This means a hexadecimal value with the last two digits ''ff''. You can try either the next smallest or next largest such value (next smallest is safer but costs up to about 250 bytes of program space). For example, for the Bus Pirate v3 the suggested end address is ''0xa7fa'', but MPLAB X wants to have ''0xa6ff'' (preferred) or ''0xa7ff'' instead. |
Revision as of 05:51, 8 December 2012
You don't need a Microchip programmer to develop firmware for most of our PIC microcontroller-based projects. You can use Microchip's free development tools and upload code with the bootloader.
Microchip's tools are all Windows-only, but there are beta version available for Linux and Mac.
Contents
IDE
Download and install Microchip's IDE called MPLAB.
MPLABX is Microchip's new cross-platform IDE and compilers for Windows, Linux, and Mac.
C compiler
Some projects require a C compiler. We use Microchip's free demonstration compilers with MPLAB. The demo compilers have certain optimizations that expire after 60 days, but we don't use those anyway.
Project | PIC | Compiler |
#twatch | 18F67J60 | C18 |
USB IR Toy | 18F2550 | C18 |
Flash Destroyer | 18F2550 | C18 |
Logic Sniffer | 18F24J50 | C18 |
Bus Pirate | 24FJ64GA002 | C30 |
Web Platform | 33FJ128GP204 | C30 |
Non-distributables
A problem we're still working around is Microchip's source code license. The source is freely available from the Microchip website, but they don't allow us to distribute it.
You need to download and install the Microchip source yourself. Drag the Dangerous Prototypes source folder into the install location (usually Microchip Solutions). We're working on alternatives, as listed below.
Source | Used in | Open Alternatives |
"free" TCP/IP stack (old versions now available) | #twatch, Web Platform | uIP stack port |
"free" FAT32 file system | Web Platform | 1 DosFS FatFs |
"free" USB stack | The JTR-Honken USB stack is now running on the USB IR Toy firmware v20+ |
Compiling
- Open the project in MPLAB
- Compile the project (down arrow stack of papers icon)
You may need to modify the compiler location when prompted, but MPLAB is getting better about making these changes automatically.
Export for bootloader
Some compiled firmware must be exported in order to work with the bootloader.
Exporting in MPLAB X
If you need to configure the program memory area end address (see table below), this needs to be done in the project's settings before compiling and exporting:
- To configure the end address in MPLAB X, go to File -> Project Properties and select the configuration (usually Conf: default) from the list on the left.
- Select a PIC programmer device from the list on the right; if you don't actually have any of the devices, select PICKit3.
- Click Apply.
- Select the PIC programming device (e.g., PICKit3) from list on the left.
- Select Memories to Program from the menu on the right.
- Set the option Auto select memories and ranges to Manually select memories and ranges.
- Tick the box for Program Memory and below that enter the end value (from the table below)
- Click OK to close the settings.
After configuring the end address (if required), build the project by selecting Run -> Clean and build main project (or select Clean and build from the project's context menu). This creates a .hex file in the build directory (the last few lines of the build output should mention its name and path).
You can also export the .hex file by selecting Export hex from the project's context menu (right-click the project's name in the project list to bring up the menu).
Exporting in MPLAB 8
- In MPLAB 8, go to File->Export...
- Make sure that Program Memory is checked and the Configuration Bits box matches the required setting
- Change the export end address if needed (see table below)
- Make sure INHX32 (Intel 32bit HEX) is selected on the File Format tab
- Click OK to export the firmware.
Project-specific export settings
Project | Required? | End address | Config bits? | EEPROM? |
#twatch | yes | 0x1dbbf | yes | - |
Bus Pirate v3 (bootloader v4.x) | yes | 0xa7fa | no | - |
Logic Sniffer | yes | (default) | no | - |
USB Infrared Toy | no | (default) | yes | optional |
Web Platform | no | 0×153fe | yes | - |
Flash Destroyer | no | (default) | yes | optional |
Bus Pirate v4 | no | (default) | yes or no |
Note: If an end address is required but the value in the table above is not accepted, it may be that the value is required to be of the form (0x100 * n – 1). This means a hexadecimal value with the last two digits ff. You can try either the next smallest or next largest such value (next smallest is safer but costs up to about 250 bytes of program space). For example, for the Bus Pirate v3 the suggested end address is 0xa7fa, but MPLAB X wants to have 0xa6ff (preferred) or 0xa7ff instead.