https://hades.mech.northwestern.edu//index.php?title=NU32:_A_Detailed_Look_at_Programming_the_PIC32_on_the_NU32&feed=atom&action=historyNU32: A Detailed Look at Programming the PIC32 on the NU32 - Revision history2024-03-29T04:52:15ZRevision history for this page on the wikiMediaWiki 1.35.9https://hades.mech.northwestern.edu//index.php?title=NU32:_A_Detailed_Look_at_Programming_the_PIC32_on_the_NU32&diff=23730&oldid=prevLynch at 11:33, 16 January 20162016-01-16T11:33:55Z<p></p>
<table class="diff diff-contentalign-left diff-editfont-monospace" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 11:33, 16 January 2016</td>
</tr><tr>
<td colspan="2" class="diff-lineno">Line 1:</td>
<td colspan="2" class="diff-lineno">Line 1:</td>
</tr>
<tr>
<td colspan="2" class="diff-empty diff-side-deleted"></td>
<td class="diff-marker" data-marker="+"></td>
<td class="diff-addedline diff-side-added"><div>'''THIS PAGE REFERS TO A PRE-RELEASE VERSION OF THE NU32 PIC32 DEVELOPMENT BOARD. FOR INFORMATION, SAMPLE CODE, AND VIDEOS RELATED TO THE PRODUCTION VERSION (2016 AND LATER), AND TO THE CORRESPONDING BOOK "EMBEDDED COMPUTING AND MECHATRONICS WITH THE PIC32 MICROCONTROLLER," VISIT [[NU32|THE NU32 PAGE]].'''</div></td>
</tr>
<tr>
<td colspan="2" class="diff-empty diff-side-deleted"></td>
<td class="diff-marker" data-marker="+"></td>
<td class="diff-addedline diff-side-added"><br /></td>
</tr>
<tr>
<td colspan="2" class="diff-empty diff-side-deleted"></td>
<td class="diff-marker" data-marker="+"></td>
<td class="diff-addedline diff-side-added"><br /></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td class="diff-context diff-side-deleted"><div>After you have [[NU32: Starting a New Project and Putting it on the NU32|programmed your NU32 for the first time]] and verified that you can create a new project, compile it, and run it on your NU32, it is useful to take a step back and understand the basics of the programming process, beginning with a PIC32 fresh from the factory. We will do that on this page. We will begin by discussing the virtual memory map of the PIC32. To discuss the virtual memory map, it is useful to know ''hexadecimal'' (hex, or base 16) notation, where each digit of a hex number takes one of 16 values, 0...9, A...F. Since 16 = 2^4, a single hex digit represents four digits of a number written in binary (base 2). The table below gives examples.</div></td>
<td class="diff-marker"></td>
<td class="diff-context diff-side-added"><div>After you have [[NU32: Starting a New Project and Putting it on the NU32|programmed your NU32 for the first time]] and verified that you can create a new project, compile it, and run it on your NU32, it is useful to take a step back and understand the basics of the programming process, beginning with a PIC32 fresh from the factory. We will do that on this page. We will begin by discussing the virtual memory map of the PIC32. To discuss the virtual memory map, it is useful to know ''hexadecimal'' (hex, or base 16) notation, where each digit of a hex number takes one of 16 values, 0...9, A...F. Since 16 = 2^4, a single hex digit represents four digits of a number written in binary (base 2). The table below gives examples.</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td class="diff-context diff-side-deleted"><br /></td>
<td class="diff-marker"></td>
<td class="diff-context diff-side-added"><br /></td>
</tr>
</table>Lynchhttps://hades.mech.northwestern.edu//index.php?title=NU32:_A_Detailed_Look_at_Programming_the_PIC32_on_the_NU32&diff=21749&oldid=prevNickMarchuk: /* Creating a .hex File Using MPLAB */2013-01-04T22:41:13Z<p><span dir="auto"><span class="autocomment">Creating a .hex File Using MPLAB</span></span></p>
<table class="diff diff-contentalign-left diff-editfont-monospace" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 22:41, 4 January 2013</td>
</tr><tr>
<td colspan="2" class="diff-lineno">Line 195:</td>
<td colspan="2" class="diff-lineno">Line 195:</td>
</tr>
<tr>
<td class="diff-marker"></td>
<td class="diff-context diff-side-deleted"><div>OK, everything is in place. You've got a bootloader on the PIC and a bootloader app on your computer. Now we just need to create a program to put on the PIC!</div></td>
<td class="diff-marker"></td>
<td class="diff-context diff-side-added"><div>OK, everything is in place. You've got a bootloader on the PIC and a bootloader app on your computer. Now we just need to create a program to put on the PIC!</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td class="diff-context diff-side-deleted"><br /></td>
<td class="diff-marker"></td>
<td class="diff-context diff-side-added"><br /></td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td class="diff-deletedline diff-side-deleted"><div>Let's use the digital I/O code sample on [[NU32: Digital Input and Output|this page]] as an example. Following the basic procedure on [[NU32: Starting a New Project and Putting it on the NU32|this page]], you create a new project and add the code sample to Source Files. Let's call this file digio.c. You add the [[Media:<del class="diffchange diffchange-inline">Procdefs_for_NU32</del>.zip | <del class="diffchange diffchange-inline">procdefs</del>.ld file]] to the project folder. You choose the <del class="diffchange diffchange-inline">C32</del> Compiler and the device PIC32MX795F512L. Then you choose "Build," and if all has gone well, you should get the message BUILD SUCCEEDED and a .hex file ready to be loaded on to your PIC.</div></td>
<td class="diff-marker" data-marker="+"></td>
<td class="diff-addedline diff-side-added"><div>Let's use the digital I/O code sample on [[NU32: Digital Input and Output|this page]] as an example. Following the basic procedure on [[NU32: Starting a New Project and Putting it on the NU32|this page]], you create a new project and add the code sample to Source Files. Let's call this file digio.c. You add the [[Media:<ins class="diffchange diffchange-inline">NU32_BasicTemplate</ins>.zip | <ins class="diffchange diffchange-inline">app</ins>.ld file<ins class="diffchange diffchange-inline"> from NU32_BasicTemplate.zip</ins>]] to the project folder. You choose the <ins class="diffchange diffchange-inline">XC32</ins> Compiler and the device PIC32MX795F512L. Then you choose "Build," and if all has gone well, you should get the message BUILD SUCCEEDED and a .hex file ready to be loaded on to your PIC.</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td class="diff-context diff-side-deleted"><br /></td>
<td class="diff-marker"></td>
<td class="diff-context diff-side-added"><br /></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td class="diff-context diff-side-deleted"><div>So what was the process, really? Three things happened: </div></td>
<td class="diff-marker"></td>
<td class="diff-context diff-side-added"><div>So what was the process, really? Three things happened: </div></td>
</tr>
<tr>
<td colspan="2" class="diff-lineno">Line 219:</td>
<td colspan="2" class="diff-lineno">Line 219:</td>
</tr>
<tr>
<td class="diff-marker"></td>
<td class="diff-context diff-side-deleted"><div>Like Alice in Wonderland, we're about to go down a rabbit hole...</div></td>
<td class="diff-marker"></td>
<td class="diff-context diff-side-added"><div>Like Alice in Wonderland, we're about to go down a rabbit hole...</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td class="diff-context diff-side-deleted"><br /></td>
<td class="diff-marker"></td>
<td class="diff-context diff-side-added"><br /></td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td class="diff-deletedline diff-side-deleted"><div>When you installed MPLAB X and the <del class="diffchange diffchange-inline">C32</del> compiler, it installed a large tree of directories under mplabc32/v.11a. To give you an idea of the directory structure, we highlight some of the important directories and files below:</div></td>
<td class="diff-marker" data-marker="+"></td>
<td class="diff-addedline diff-side-added"><div>When you installed MPLAB X and the <ins class="diffchange diffchange-inline">XC32</ins> compiler, it installed a large tree of directories under mplabc32/v.11a. To give you an idea of the directory structure, we highlight some of the important directories and files below:</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td class="diff-context diff-side-deleted"><br /></td>
<td class="diff-marker"></td>
<td class="diff-context diff-side-added"><br /></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td class="diff-context diff-side-deleted"><br /></td>
<td class="diff-marker"></td>
<td class="diff-context diff-side-added"><br /></td>
</tr>
</table>NickMarchukhttps://hades.mech.northwestern.edu//index.php?title=NU32:_A_Detailed_Look_at_Programming_the_PIC32_on_the_NU32&diff=21732&oldid=prevNickMarchuk: /* The PIC32 Bootloader and Bootloader App */2012-12-26T18:36:37Z<p><span dir="auto"><span class="autocomment">The PIC32 Bootloader and Bootloader App</span></span></p>
<table class="diff diff-contentalign-left diff-editfont-monospace" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 18:36, 26 December 2012</td>
</tr><tr>
<td colspan="2" class="diff-lineno">Line 166:</td>
<td colspan="2" class="diff-lineno">Line 166:</td>
</tr>
<tr>
<td class="diff-marker"></td>
<td class="diff-context diff-side-deleted"><div>* If the digital input is low (the button is being pressed), the PIC attempts to establish communication with the NU32 Utility "bootloader app" on you computer. The bootloader app will send over your new .hex program, and the PIC will write the program into KSEG0 program flash beginning at 0x9D001000. The next time the PIC is reset (and not asked to stay in bootloader mode), it will begin executing the program you loaded.</div></td>
<td class="diff-marker"></td>
<td class="diff-context diff-side-added"><div>* If the digital input is low (the button is being pressed), the PIC attempts to establish communication with the NU32 Utility "bootloader app" on you computer. The bootloader app will send over your new .hex program, and the PIC will write the program into KSEG0 program flash beginning at 0x9D001000. The next time the PIC is reset (and not asked to stay in bootloader mode), it will begin executing the program you loaded.</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td class="diff-context diff-side-deleted"><br /></td>
<td class="diff-marker"></td>
<td class="diff-context diff-side-added"><br /></td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td class="diff-deletedline diff-side-deleted"><div>The bootloader on the NU32 is based on [[Media:<del class="diffchange diffchange-inline">AN1388</del>.pdf|Microchip's application note AN1388]]. Microchip provides [http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1824&appnote=en554836 source code] for this application note, which has been modified for the NU32. The NU32 bootloader project is [[Media:<del class="diffchange diffchange-inline">NU32_boot</del>.zip|here]]<del class="diffchange diffchange-inline"> (use the PIC32_UART_Bootloader_BootFlash_Explorer16.X Project)</del>.</div></td>
<td class="diff-marker" data-marker="+"></td>
<td class="diff-addedline diff-side-added"><div>The bootloader on the NU32 is based on [[Media:<ins class="diffchange diffchange-inline">AN1388B</ins>.pdf|Microchip's application note AN1388]]. Microchip provides [http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1824&appnote=en554836 source code] for this application note, which has been modified for the NU32. The NU32 bootloader project is [[Media:<ins class="diffchange diffchange-inline">NU32_boot_2013</ins>.zip|here]].</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td class="diff-context diff-side-deleted"><br /></td>
<td class="diff-marker"></td>
<td class="diff-context diff-side-added"><br /></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td class="diff-context diff-side-deleted"><div>'''Important:''' The bootloader does one other important thing: it sets ''configuration bits'' for the PIC. Configuration bits are SFRs that are set on startup and control some basic behavior of the PIC. For example, the configuration bits are used to configure phase-locked loops on the PIC to turn our 8 MHz external oscillator into an 80 MHz system clock, 80 MHz peripheral bus clock, 48 MHz USB clock, etc. </div></td>
<td class="diff-marker"></td>
<td class="diff-context diff-side-added"><div>'''Important:''' The bootloader does one other important thing: it sets ''configuration bits'' for the PIC. Configuration bits are SFRs that are set on startup and control some basic behavior of the PIC. For example, the configuration bits are used to configure phase-locked loops on the PIC to turn our 8 MHz external oscillator into an 80 MHz system clock, 80 MHz peripheral bus clock, 48 MHz USB clock, etc. </div></td>
</tr>
</table>NickMarchukhttps://hades.mech.northwestern.edu//index.php?title=NU32:_A_Detailed_Look_at_Programming_the_PIC32_on_the_NU32&diff=20952&oldid=prevLynch: /* The PIC32 Bootloader and Bootloader App */2012-01-29T14:34:33Z<p><span dir="auto"><span class="autocomment">The PIC32 Bootloader and Bootloader App</span></span></p>
<table class="diff diff-contentalign-left diff-editfont-monospace" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 14:34, 29 January 2012</td>
</tr><tr>
<td colspan="2" class="diff-lineno">Line 168:</td>
<td colspan="2" class="diff-lineno">Line 168:</td>
</tr>
<tr>
<td class="diff-marker"></td>
<td class="diff-context diff-side-deleted"><div>The bootloader on the NU32 is based on [[Media:AN1388.pdf|Microchip's application note AN1388]]. Microchip provides [http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1824&appnote=en554836 source code] for this application note, which has been modified for the NU32. The NU32 bootloader project is [[Media:NU32_boot.zip|here]] (use the PIC32_UART_Bootloader_BootFlash_Explorer16.X Project).</div></td>
<td class="diff-marker"></td>
<td class="diff-context diff-side-added"><div>The bootloader on the NU32 is based on [[Media:AN1388.pdf|Microchip's application note AN1388]]. Microchip provides [http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1824&appnote=en554836 source code] for this application note, which has been modified for the NU32. The NU32 bootloader project is [[Media:NU32_boot.zip|here]] (use the PIC32_UART_Bootloader_BootFlash_Explorer16.X Project).</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td class="diff-context diff-side-deleted"><br /></td>
<td class="diff-marker"></td>
<td class="diff-context diff-side-added"><br /></td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td class="diff-deletedline diff-side-deleted"><div>'''Important:''' The bootloader does one other important thing: it sets ''configuration bits'' for the PIC. Configuration bits are SFRs that are set on startup and control some basic behavior of the PIC. For example, the configuration bits are used to configure phase-locked loops on the PIC to turn our 8 MHz external oscillator into an 80 MHz system clock, 80 MHz peripheral bus clock, 48 MHz USB clock, etc. <del class="diffchange diffchange-inline">'''Unfortunately, you cannot see what the configuration bits are set to after the PIC has been programmed with the bootloader.'''</del></div></td>
<td class="diff-marker" data-marker="+"></td>
<td class="diff-addedline diff-side-added"><div>'''Important:''' The bootloader does one other important thing: it sets ''configuration bits'' for the PIC. Configuration bits are SFRs that are set on startup and control some basic behavior of the PIC. For example, the configuration bits are used to configure phase-locked loops on the PIC to turn our 8 MHz external oscillator into an 80 MHz system clock, 80 MHz peripheral bus clock, 48 MHz USB clock, etc. </div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td class="diff-context diff-side-deleted"><br /></td>
<td class="diff-marker"></td>
<td class="diff-context diff-side-added"><br /></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td class="diff-context diff-side-deleted"><div>If you are programming an NU32 without the bootloader (i.e. with a PICkit3) and want to use the same configuration bits, they are:</div></td>
<td class="diff-marker"></td>
<td class="diff-context diff-side-added"><div>If you are programming an NU32 without the bootloader (i.e. with a PICkit3) and want to use the same configuration bits, they are:</div></td>
</tr>
</table>Lynchhttps://hades.mech.northwestern.edu//index.php?title=NU32:_A_Detailed_Look_at_Programming_the_PIC32_on_the_NU32&diff=20817&oldid=prevNickMarchuk: /* The PIC32 Bootloader and Bootloader App */2012-01-13T22:43:24Z<p><span dir="auto"><span class="autocomment">The PIC32 Bootloader and Bootloader App</span></span></p>
<table class="diff diff-contentalign-left diff-editfont-monospace" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 22:43, 13 January 2012</td>
</tr><tr>
<td colspan="2" class="diff-lineno">Line 179:</td>
<td colspan="2" class="diff-lineno">Line 179:</td>
</tr>
<tr>
<td class="diff-marker"></td>
<td class="diff-context diff-side-deleted"><div>#pragma config POSCMOD = HS, FNOSC = PRIPLL, FPBDIV = DIV_1</div></td>
<td class="diff-marker"></td>
<td class="diff-context diff-side-added"><div>#pragma config POSCMOD = HS, FNOSC = PRIPLL, FPBDIV = DIV_1</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td class="diff-context diff-side-deleted"><div>#pragma config ICESEL = ICS_PGx2, BWP = OFF</div></td>
<td class="diff-marker"></td>
<td class="diff-context diff-side-added"><div>#pragma config ICESEL = ICS_PGx2, BWP = OFF</div></td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td class="diff-deletedline diff-side-deleted"><div>#pragma config FSOSCEN = OFF</div></td>
<td class="diff-marker" data-marker="+"></td>
<td class="diff-addedline diff-side-added"><div>#pragma config FSOSCEN = OFF<ins class="diffchange diffchange-inline"> // to make C13 an IO pin, for the USER switch</ins></div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td class="diff-context diff-side-deleted"><div></pre></div></td>
<td class="diff-marker"></td>
<td class="diff-context diff-side-added"><div></pre></div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td class="diff-context diff-side-deleted"><br /></td>
<td class="diff-marker"></td>
<td class="diff-context diff-side-added"><br /></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td class="diff-context diff-side-deleted"><div>More information about configuration registers can be found in Section 32 of the Reference Manual.</div></td>
<td class="diff-marker"></td>
<td class="diff-context diff-side-added"><div>More information about configuration registers can be found in Section 32 of the Reference Manual.</div></td>
</tr>
<tr>
<td colspan="2" class="diff-empty diff-side-deleted"></td>
<td class="diff-marker" data-marker="+"></td>
<td class="diff-addedline diff-side-added"><br /></td>
</tr>
<tr>
<td colspan="2" class="diff-empty diff-side-deleted"></td>
<td class="diff-marker" data-marker="+"></td>
<td class="diff-addedline diff-side-added"><div>Also note that pins A4 and A5, LEDs L1 and L2, are by default used for JTAG, so you must disable JTAG to make them digital IO:</div></td>
</tr>
<tr>
<td colspan="2" class="diff-empty diff-side-deleted"></td>
<td class="diff-marker" data-marker="+"></td>
<td class="diff-addedline diff-side-added"><br /></td>
</tr>
<tr>
<td colspan="2" class="diff-empty diff-side-deleted"></td>
<td class="diff-marker" data-marker="+"></td>
<td class="diff-addedline diff-side-added"><div><pre></div></td>
</tr>
<tr>
<td colspan="2" class="diff-empty diff-side-deleted"></td>
<td class="diff-marker" data-marker="+"></td>
<td class="diff-addedline diff-side-added"><div>// disable JTAG to get A4 and A5 back</div></td>
</tr>
<tr>
<td colspan="2" class="diff-empty diff-side-deleted"></td>
<td class="diff-marker" data-marker="+"></td>
<td class="diff-addedline diff-side-added"><div>DDPCONbits.JTAGEN = 0;</div></td>
</tr>
<tr>
<td colspan="2" class="diff-empty diff-side-deleted"></td>
<td class="diff-marker" data-marker="+"></td>
<td class="diff-addedline diff-side-added"><div></pre></div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td class="diff-context diff-side-deleted"><br /></td>
<td class="diff-marker"></td>
<td class="diff-context diff-side-added"><br /></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td class="diff-context diff-side-deleted"><div>= Creating a .hex File Using MPLAB =</div></td>
<td class="diff-marker"></td>
<td class="diff-context diff-side-added"><div>= Creating a .hex File Using MPLAB =</div></td>
</tr>
</table>NickMarchukhttps://hades.mech.northwestern.edu//index.php?title=NU32:_A_Detailed_Look_at_Programming_the_PIC32_on_the_NU32&diff=20751&oldid=prevNickMarchuk: /* Creating a .hex File Using MPLAB */2011-12-28T22:28:40Z<p><span dir="auto"><span class="autocomment">Creating a .hex File Using MPLAB</span></span></p>
<table class="diff diff-contentalign-left diff-editfont-monospace" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 22:28, 28 December 2011</td>
</tr><tr>
<td colspan="2" class="diff-lineno">Line 188:</td>
<td colspan="2" class="diff-lineno">Line 188:</td>
</tr>
<tr>
<td class="diff-marker"></td>
<td class="diff-context diff-side-deleted"><div>OK, everything is in place. You've got a bootloader on the PIC and a bootloader app on your computer. Now we just need to create a program to put on the PIC!</div></td>
<td class="diff-marker"></td>
<td class="diff-context diff-side-added"><div>OK, everything is in place. You've got a bootloader on the PIC and a bootloader app on your computer. Now we just need to create a program to put on the PIC!</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td class="diff-context diff-side-deleted"><br /></td>
<td class="diff-marker"></td>
<td class="diff-context diff-side-added"><br /></td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td class="diff-deletedline diff-side-deleted"><div>Let's use the digital I/O code sample on [[<del class="diffchange diffchange-inline">NU32v2</del>: Digital Input and Output|this page]] as an example. Following the basic procedure on [[<del class="diffchange diffchange-inline">NU32v2</del>: Starting a New Project and Putting it on the <del class="diffchange diffchange-inline">NU32v2</del>|this page]], you create a new project and add the code sample to Source Files. Let's call this file digio.c. You add the [[Media:<del class="diffchange diffchange-inline">procdefs_for_NU32v2</del>.zip | procdefs.ld file]] to <del class="diffchange diffchange-inline">Other</del> <del class="diffchange diffchange-inline">or</del> <del class="diffchange diffchange-inline">Important Files</del>. You choose the C32 Compiler and the device PIC32MX795F512L. Then you choose "Build," and if all has gone well, you should get the message BUILD SUCCEEDED and a .hex file ready to be loaded on to your PIC.</div></td>
<td class="diff-marker" data-marker="+"></td>
<td class="diff-addedline diff-side-added"><div>Let's use the digital I/O code sample on [[<ins class="diffchange diffchange-inline">NU32</ins>: Digital Input and Output|this page]] as an example. Following the basic procedure on [[<ins class="diffchange diffchange-inline">NU32</ins>: Starting a New Project and Putting it on the <ins class="diffchange diffchange-inline">NU32</ins>|this page]], you create a new project and add the code sample to Source Files. Let's call this file digio.c. You add the [[Media:<ins class="diffchange diffchange-inline">Procdefs_for_NU32</ins>.zip | procdefs.ld file]] to <ins class="diffchange diffchange-inline">the</ins> <ins class="diffchange diffchange-inline">project</ins> <ins class="diffchange diffchange-inline">folder</ins>. You choose the C32 Compiler and the device PIC32MX795F512L. Then you choose "Build," and if all has gone well, you should get the message BUILD SUCCEEDED and a .hex file ready to be loaded on to your PIC.</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td class="diff-context diff-side-deleted"><br /></td>
<td class="diff-marker"></td>
<td class="diff-context diff-side-added"><br /></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td class="diff-context diff-side-deleted"><div>So what was the process, really? Three things happened: </div></td>
<td class="diff-marker"></td>
<td class="diff-context diff-side-added"><div>So what was the process, really? Three things happened: </div></td>
</tr>
<tr>
<td colspan="2" class="diff-lineno">Line 198:</td>
<td colspan="2" class="diff-lineno">Line 198:</td>
</tr>
<tr>
<td class="diff-marker"></td>
<td class="diff-context diff-side-deleted"><div>Now let's dig a little deeper. In our C code, we used statements like </div></td>
<td class="diff-marker"></td>
<td class="diff-context diff-side-added"><div>Now let's dig a little deeper. In our C code, we used statements like </div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td class="diff-context diff-side-deleted"><div><pre></div></td>
<td class="diff-marker"></td>
<td class="diff-context diff-side-added"><div><pre></div></td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td class="diff-deletedline diff-side-deleted"><div>#define <del class="diffchange diffchange-inline">LED0</del> <del class="diffchange diffchange-inline">LATGbits</del>.<del class="diffchange diffchange-inline">LATG12</del></div></td>
<td class="diff-marker" data-marker="+"></td>
<td class="diff-addedline diff-side-added"><div>#define <ins class="diffchange diffchange-inline">L1</ins> <ins class="diffchange diffchange-inline">LATAbits</ins>.<ins class="diffchange diffchange-inline">LATA4</ins></div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td class="diff-context diff-side-deleted"><div></pre></div></td>
<td class="diff-marker"></td>
<td class="diff-context diff-side-added"><div></pre></div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td class="diff-context diff-side-deleted"><div>and</div></td>
<td class="diff-marker"></td>
<td class="diff-context diff-side-added"><div>and</div></td>
</tr>
<tr>
<td colspan="2" class="diff-lineno">Line 204:</td>
<td colspan="2" class="diff-lineno">Line 204:</td>
</tr>
<tr>
<td class="diff-marker"></td>
<td class="diff-context diff-side-deleted"><div>SYSTEMConfig(SYS_FREQ, SYS_CFG_ALL);</div></td>
<td class="diff-marker"></td>
<td class="diff-context diff-side-added"><div>SYSTEMConfig(SYS_FREQ, SYS_CFG_ALL);</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td class="diff-context diff-side-deleted"><div></pre></div></td>
<td class="diff-marker"></td>
<td class="diff-context diff-side-added"><div></pre></div></td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td class="diff-deletedline diff-side-deleted"><div>So it looks like we defined one constant (<del class="diffchange diffchange-inline">LED0</del>) to be equal to a variable, the field "<del class="diffchange diffchange-inline">LATG12</del>" of a struct "<del class="diffchange diffchange-inline">LATGbits</del>." But where was that struct defined? And where was the function SYSTEMConfig() defined?</div></td>
<td class="diff-marker" data-marker="+"></td>
<td class="diff-addedline diff-side-added"><div>So it looks like we defined one constant (<ins class="diffchange diffchange-inline">L1</ins>) to be equal to a variable, the field "<ins class="diffchange diffchange-inline">LATA4</ins>" of a struct "<ins class="diffchange diffchange-inline">LATAbits</ins>." But where was that struct defined? And where was the function SYSTEMConfig() defined?</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td class="diff-context diff-side-deleted"><br /></td>
<td class="diff-marker"></td>
<td class="diff-context diff-side-added"><br /></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td class="diff-context diff-side-deleted"><div>The key is the first line of our code:</div></td>
<td class="diff-marker"></td>
<td class="diff-context diff-side-added"><div>The key is the first line of our code:</div></td>
</tr>
<tr>
<td colspan="2" class="diff-lineno">Line 212:</td>
<td colspan="2" class="diff-lineno">Line 212:</td>
</tr>
<tr>
<td class="diff-marker"></td>
<td class="diff-context diff-side-deleted"><div>Like Alice in Wonderland, we're about to go down a rabbit hole...</div></td>
<td class="diff-marker"></td>
<td class="diff-context diff-side-added"><div>Like Alice in Wonderland, we're about to go down a rabbit hole...</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td class="diff-context diff-side-deleted"><br /></td>
<td class="diff-marker"></td>
<td class="diff-context diff-side-added"><br /></td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td class="diff-deletedline diff-side-deleted"><div>When you installed MPLAB and the C32 compiler, it installed a large tree of directories under<del class="diffchange diffchange-inline"> Program Files\Microchip\MPLAB C32 for MPLAB 8.xx, or </del> mplabc32/v.11a<del class="diffchange diffchange-inline"> (or similar) for MPLAB X</del>. To give you an idea of the directory structure, we highlight some of the important directories and files below:</div></td>
<td class="diff-marker" data-marker="+"></td>
<td class="diff-addedline diff-side-added"><div>When you installed MPLAB<ins class="diffchange diffchange-inline"> X</ins> and the C32 compiler, it installed a large tree of directories under mplabc32/v.11a. To give you an idea of the directory structure, we highlight some of the important directories and files below:</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td class="diff-context diff-side-deleted"><br /></td>
<td class="diff-marker"></td>
<td class="diff-context diff-side-added"><br /></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td class="diff-context diff-side-deleted"><br /></td>
<td class="diff-marker"></td>
<td class="diff-context diff-side-added"><br /></td>
</tr>
</table>NickMarchukhttps://hades.mech.northwestern.edu//index.php?title=NU32:_A_Detailed_Look_at_Programming_the_PIC32_on_the_NU32&diff=20750&oldid=prevNickMarchuk: /* The PIC32 Bootloader and Bootloader App */2011-12-28T22:24:16Z<p><span dir="auto"><span class="autocomment">The PIC32 Bootloader and Bootloader App</span></span></p>
<table class="diff diff-contentalign-left diff-editfont-monospace" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 22:24, 28 December 2011</td>
</tr><tr>
<td colspan="2" class="diff-lineno">Line 166:</td>
<td colspan="2" class="diff-lineno">Line 166:</td>
</tr>
<tr>
<td class="diff-marker"></td>
<td class="diff-context diff-side-deleted"><div>* If the digital input is low (the button is being pressed), the PIC attempts to establish communication with the NU32 Utility "bootloader app" on you computer. The bootloader app will send over your new .hex program, and the PIC will write the program into KSEG0 program flash beginning at 0x9D001000. The next time the PIC is reset (and not asked to stay in bootloader mode), it will begin executing the program you loaded.</div></td>
<td class="diff-marker"></td>
<td class="diff-context diff-side-added"><div>* If the digital input is low (the button is being pressed), the PIC attempts to establish communication with the NU32 Utility "bootloader app" on you computer. The bootloader app will send over your new .hex program, and the PIC will write the program into KSEG0 program flash beginning at 0x9D001000. The next time the PIC is reset (and not asked to stay in bootloader mode), it will begin executing the program you loaded.</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td class="diff-context diff-side-deleted"><br /></td>
<td class="diff-marker"></td>
<td class="diff-context diff-side-added"><br /></td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td class="diff-deletedline diff-side-deleted"><div>The bootloader on the NU32 is based on [[Media:AN1388.pdf|Microchip's application note AN1388]]. Microchip provides [http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1824&appnote=en554836 source code] for this application note, which has been modified for the NU32. The NU32 bootloader project is [[Media:NU32_boot.zip|here]].</div></td>
<td class="diff-marker" data-marker="+"></td>
<td class="diff-addedline diff-side-added"><div>The bootloader on the NU32 is based on [[Media:AN1388.pdf|Microchip's application note AN1388]]. Microchip provides [http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1824&appnote=en554836 source code] for this application note, which has been modified for the NU32. The NU32 bootloader project is [[Media:NU32_boot.zip|here]]<ins class="diffchange diffchange-inline"> (use the PIC32_UART_Bootloader_BootFlash_Explorer16.X Project)</ins>.</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td class="diff-context diff-side-deleted"><br /></td>
<td class="diff-marker"></td>
<td class="diff-context diff-side-added"><br /></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td class="diff-context diff-side-deleted"><div>'''Important:''' The bootloader does one other important thing: it sets ''configuration bits'' for the PIC. Configuration bits are SFRs that are set on startup and control some basic behavior of the PIC. For example, the configuration bits are used to configure phase-locked loops on the PIC to turn our 8 MHz external oscillator into an 80 MHz system clock, 80 MHz peripheral bus clock, 48 MHz USB clock, etc. '''Unfortunately, you cannot see what the configuration bits are set to after the PIC has been programmed with the bootloader.'''</div></td>
<td class="diff-marker"></td>
<td class="diff-context diff-side-added"><div>'''Important:''' The bootloader does one other important thing: it sets ''configuration bits'' for the PIC. Configuration bits are SFRs that are set on startup and control some basic behavior of the PIC. For example, the configuration bits are used to configure phase-locked loops on the PIC to turn our 8 MHz external oscillator into an 80 MHz system clock, 80 MHz peripheral bus clock, 48 MHz USB clock, etc. '''Unfortunately, you cannot see what the configuration bits are set to after the PIC has been programmed with the bootloader.'''</div></td>
</tr>
</table>NickMarchukhttps://hades.mech.northwestern.edu//index.php?title=NU32:_A_Detailed_Look_at_Programming_the_PIC32_on_the_NU32&diff=20747&oldid=prevNickMarchuk: /* The PIC32 Bootloader and Bootloader App */2011-12-28T22:19:16Z<p><span dir="auto"><span class="autocomment">The PIC32 Bootloader and Bootloader App</span></span></p>
<table class="diff diff-contentalign-left diff-editfont-monospace" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 22:19, 28 December 2011</td>
</tr><tr>
<td colspan="2" class="diff-lineno">Line 172:</td>
<td colspan="2" class="diff-lineno">Line 172:</td>
</tr>
<tr>
<td class="diff-marker"></td>
<td class="diff-context diff-side-deleted"><div>If you are programming an NU32 without the bootloader (i.e. with a PICkit3) and want to use the same configuration bits, they are:</div></td>
<td class="diff-marker"></td>
<td class="diff-context diff-side-added"><div>If you are programming an NU32 without the bootloader (i.e. with a PICkit3) and want to use the same configuration bits, they are:</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td class="diff-context diff-side-deleted"><div><pre></div></td>
<td class="diff-marker"></td>
<td class="diff-context diff-side-added"><div><pre></div></td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td class="diff-deletedline diff-side-deleted"><div><code></div></td>
<td colspan="2" class="diff-empty diff-side-added"></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td class="diff-context diff-side-deleted"><div>// Configuring the Device Configuration Registers</div></td>
<td class="diff-marker"></td>
<td class="diff-context diff-side-added"><div>// Configuring the Device Configuration Registers</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td class="diff-context diff-side-deleted"><div>// 80Mhz Core/Periph, Pri Osc w/PLL, Write protect Boot Flash</div></td>
<td class="diff-marker"></td>
<td class="diff-context diff-side-added"><div>// 80Mhz Core/Periph, Pri Osc w/PLL, Write protect Boot Flash</div></td>
</tr>
<tr>
<td colspan="2" class="diff-lineno">Line 181:</td>
<td colspan="2" class="diff-lineno">Line 180:</td>
</tr>
<tr>
<td class="diff-marker"></td>
<td class="diff-context diff-side-deleted"><div>#pragma config ICESEL = ICS_PGx2, BWP = OFF</div></td>
<td class="diff-marker"></td>
<td class="diff-context diff-side-added"><div>#pragma config ICESEL = ICS_PGx2, BWP = OFF</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td class="diff-context diff-side-deleted"><div>#pragma config FSOSCEN = OFF</div></td>
<td class="diff-marker"></td>
<td class="diff-context diff-side-added"><div>#pragma config FSOSCEN = OFF</div></td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td class="diff-deletedline diff-side-deleted"><div></code></div></td>
<td colspan="2" class="diff-empty diff-side-added"></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td class="diff-context diff-side-deleted"><div></pre></div></td>
<td class="diff-marker"></td>
<td class="diff-context diff-side-added"><div></pre></div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td class="diff-context diff-side-deleted"><br /></td>
<td class="diff-marker"></td>
<td class="diff-context diff-side-added"><br /></td>
</tr>
</table>NickMarchukhttps://hades.mech.northwestern.edu//index.php?title=NU32:_A_Detailed_Look_at_Programming_the_PIC32_on_the_NU32&diff=20746&oldid=prevNickMarchuk: /* The PIC32 Bootloader and Bootloader App */2011-12-28T22:18:59Z<p><span dir="auto"><span class="autocomment">The PIC32 Bootloader and Bootloader App</span></span></p>
<table class="diff diff-contentalign-left diff-editfont-monospace" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 22:18, 28 December 2011</td>
</tr><tr>
<td colspan="2" class="diff-lineno">Line 159:</td>
<td colspan="2" class="diff-lineno">Line 159:</td>
</tr>
<tr>
<td class="diff-marker"></td>
<td class="diff-context diff-side-deleted"><div>= The PIC32 Bootloader and Bootloader App =</div></td>
<td class="diff-marker"></td>
<td class="diff-context diff-side-added"><div>= The PIC32 Bootloader and Bootloader App =</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td class="diff-context diff-side-deleted"><br /></td>
<td class="diff-marker"></td>
<td class="diff-context diff-side-added"><br /></td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td class="diff-deletedline diff-side-deleted"><div>To avoid the expense of providing a PICkit 3 programmer with every <del class="diffchange diffchange-inline">NU32v2</del> kit, we opted to use our PICkit 3 programmer to install a bootloading program on your <del class="diffchange diffchange-inline">NU32v2</del>. This allows you to program your PIC using only a USB cable and the free MPLAB IDE and compiler. By not using a programmer, you have lost the ability to do "in-circuit debugging," such as adding breakpoints and watches to your code as was done in the simulator. We will discuss alternative ways of debugging your code as the course progresses.</div></td>
<td class="diff-marker" data-marker="+"></td>
<td class="diff-addedline diff-side-added"><div>To avoid the expense of providing a PICkit 3 programmer with every <ins class="diffchange diffchange-inline">NU32</ins> kit, we opted to use our PICkit 3 programmer to install a bootloading program on your <ins class="diffchange diffchange-inline">NU32</ins>. This allows you to program your PIC using only a USB cable and the free MPLAB<ins class="diffchange diffchange-inline"> X</ins> IDE and compiler. By not using a programmer, you have lost the ability to do "in-circuit debugging," such as adding breakpoints and watches to your code as was done in the simulator. We will discuss alternative ways of debugging your code as the course progresses.</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td class="diff-context diff-side-deleted"><br /></td>
<td class="diff-marker"></td>
<td class="diff-context diff-side-added"><br /></td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td class="diff-deletedline diff-side-deleted"><div>The bootloader code executes upon reset of the PIC. This code tests whether a digital input is low (i.e., whether the user is pressing a button) when the PIC is reset<del class="diffchange diffchange-inline">.</del> <del class="diffchange diffchange-inline">(Aside:</del> <del class="diffchange diffchange-inline">the</del> <del class="diffchange diffchange-inline">bootloader code sets pin G6 as</del> a <del class="diffchange diffchange-inline">digital input and configures an internal pull-up resistor to 3</del>.<del class="diffchange diffchange-inline">3 V, which is why a simple external normally open switch, connecting G6 to ground when it is pressed, suffices for the digital input.)</del></div></td>
<td class="diff-marker" data-marker="+"></td>
<td class="diff-addedline diff-side-added"><div>The bootloader code executes upon reset of the PIC. This code tests whether a digital input<ins class="diffchange diffchange-inline"> (C13)</ins> is low (i.e., whether the user is pressing a button) when the PIC is reset<ins class="diffchange diffchange-inline">,</ins> <ins class="diffchange diffchange-inline">or</ins> <ins class="diffchange diffchange-inline">if</ins> <ins class="diffchange diffchange-inline">UART4</ins> <ins class="diffchange diffchange-inline">has</ins> <ins class="diffchange diffchange-inline">received</ins> a <ins class="diffchange diffchange-inline">'B'</ins>.</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td class="diff-context diff-side-deleted"><br /></td>
<td class="diff-marker"></td>
<td class="diff-context diff-side-added"><br /></td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td class="diff-deletedline diff-side-deleted"><div>* If the digital input is high (no button press), the bootloader jumps to a hard-coded virtual memory address to begin executing code there. In the case of our bootloader, that memory address is 0x9D001000 (i.e., in KSEG0 program memory).</div></td>
<td class="diff-marker" data-marker="+"></td>
<td class="diff-addedline diff-side-added"><div>* If the digital input is high (no button press)<ins class="diffchange diffchange-inline"> or has not received a 'B'</ins>, the bootloader jumps to a hard-coded virtual memory address to begin executing code there. In the case of our bootloader, that memory address is 0x9D001000 (i.e., in KSEG0 program memory).</div></td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td class="diff-deletedline diff-side-deleted"><div>* If the digital input is low (the button is being pressed), the PIC attempts to establish communication with <del class="diffchange diffchange-inline">a</del> "bootloader app" on you computer. The bootloader app will send over your new .hex program, and the PIC will write the program into KSEG0 program flash beginning at 0x9D001000. The next time the PIC is reset (and <del class="diffchange diffchange-inline">the</del> <del class="diffchange diffchange-inline">button</del> <del class="diffchange diffchange-inline">is</del> <del class="diffchange diffchange-inline">not</del> <del class="diffchange diffchange-inline">being</del> <del class="diffchange diffchange-inline">pressed</del>), it will begin executing the program you loaded.</div></td>
<td class="diff-marker" data-marker="+"></td>
<td class="diff-addedline diff-side-added"><div>* If the digital input is low (the button is being pressed), the PIC attempts to establish communication with <ins class="diffchange diffchange-inline">the NU32 Utility</ins> "bootloader app" on you computer. The bootloader app will send over your new .hex program, and the PIC will write the program into KSEG0 program flash beginning at 0x9D001000. The next time the PIC is reset (and <ins class="diffchange diffchange-inline">not</ins> <ins class="diffchange diffchange-inline">asked</ins> <ins class="diffchange diffchange-inline">to</ins> <ins class="diffchange diffchange-inline">stay</ins> <ins class="diffchange diffchange-inline">in bootloader</ins> <ins class="diffchange diffchange-inline">mode</ins>), it will begin executing the program you loaded.</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td class="diff-context diff-side-deleted"><br /></td>
<td class="diff-marker"></td>
<td class="diff-context diff-side-added"><br /></td>
</tr>
<tr>
<td colspan="2" class="diff-empty diff-side-deleted"></td>
<td class="diff-marker" data-marker="+"></td>
<td class="diff-addedline diff-side-added"><div>The bootloader on the NU32 is based on [[Media:AN1388.pdf|Microchip's application note AN1388]]. Microchip provides [http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1824&appnote=en554836 source code] for this application note, which has been modified for the NU32. The NU32 bootloader project is [[Media:NU32_boot.zip|here]].</div></td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td class="diff-deletedline diff-side-deleted"><div>In more detail, if the PIC enters "bootloader mode," (button is pressed at reset) the PIC's bootloader sends the string 'v1.1' over a serial port to your computer to indicate that it is ready to receive data from the bootloader app. An 'E' commands the bootloader to erase the program memory. This must be performed before any program is loaded. A 'B' command checks to see if the program memory is blank. If it is, an 'S' is returned, otherwise an 'F' is returned. A 'P' command lets the bootloader know that packets of 512 bytes are about to be sent to the PIC32. After the arrival of every packet, the PIC32 writes the bytes, in the order that they were received, to program memory. After not receiving a packet for ~1 second, the PIC32 considers the programming process complete and returns an 'S.' (A 'V' character lets the bootloader know that the user would like to see if a hex file matches the current content of the PIC32. This process is standard in most bootloaders, but is not implemented on the NU32v2.) An 'R' command resets the NU32v2 without needing to reset power. This effectively gets the NU32v2 out of bootloader mode.</div></td>
<td colspan="2" class="diff-empty diff-side-added"></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td class="diff-context diff-side-deleted"><br /></td>
<td class="diff-marker"></td>
<td class="diff-context diff-side-added"><br /></td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td class="diff-deletedline diff-side-deleted"><div>'''Important:''' The bootloader does one other important thing: it sets ''configuration bits'' for the PIC. Configuration bits are SFRs that are set on startup and control some basic behavior of the PIC. For example, the configuration bits are used to configure phase-locked loops on the PIC to turn our 8 MHz external oscillator into an 80 MHz system clock, 80 MHz peripheral bus clock, 48 MHz USB clock, etc. '''Unfortunately, you cannot see the configuration bits <del class="diffchange diffchange-inline">being</del> set <del class="diffchange diffchange-inline">in</del> <del class="diffchange diffchange-inline">the bootloader .S assembly code (below), because</del> the <del class="diffchange diffchange-inline">bit</del> <del class="diffchange diffchange-inline">settings</del> <del class="diffchange diffchange-inline">were</del> <del class="diffchange diffchange-inline">chosen</del> <del class="diffchange diffchange-inline">in the IDE that compiled</del> the bootloader<del class="diffchange diffchange-inline">. In future, we will set these configuration bits in the code itself, for portability and so you can see what's going on. This is also the standard for the MPLAB X IDE</del>.'''</div></td>
<td class="diff-marker" data-marker="+"></td>
<td class="diff-addedline diff-side-added"><div>'''Important:''' The bootloader does one other important thing: it sets ''configuration bits'' for the PIC. Configuration bits are SFRs that are set on startup and control some basic behavior of the PIC. For example, the configuration bits are used to configure phase-locked loops on the PIC to turn our 8 MHz external oscillator into an 80 MHz system clock, 80 MHz peripheral bus clock, 48 MHz USB clock, etc. '''Unfortunately, you cannot see<ins class="diffchange diffchange-inline"> what</ins> the configuration bits <ins class="diffchange diffchange-inline">are</ins> set <ins class="diffchange diffchange-inline">to</ins> <ins class="diffchange diffchange-inline">after</ins> the <ins class="diffchange diffchange-inline">PIC</ins> <ins class="diffchange diffchange-inline">has</ins> <ins class="diffchange diffchange-inline">been</ins> <ins class="diffchange diffchange-inline">programmed</ins> <ins class="diffchange diffchange-inline">with</ins> the bootloader.'''</div></td>
</tr>
<tr>
<td colspan="2" class="diff-empty diff-side-deleted"></td>
<td class="diff-marker" data-marker="+"></td>
<td class="diff-addedline diff-side-added"><br /></td>
</tr>
<tr>
<td colspan="2" class="diff-empty diff-side-deleted"></td>
<td class="diff-marker" data-marker="+"></td>
<td class="diff-addedline diff-side-added"><div>If you are programming an NU32 without the bootloader (i.e. with a PICkit3) and want to use the same configuration bits, they are:</div></td>
</tr>
<tr>
<td colspan="2" class="diff-empty diff-side-deleted"></td>
<td class="diff-marker" data-marker="+"></td>
<td class="diff-addedline diff-side-added"><div><pre></div></td>
</tr>
<tr>
<td colspan="2" class="diff-empty diff-side-deleted"></td>
<td class="diff-marker" data-marker="+"></td>
<td class="diff-addedline diff-side-added"><div><code></div></td>
</tr>
<tr>
<td colspan="2" class="diff-empty diff-side-deleted"></td>
<td class="diff-marker" data-marker="+"></td>
<td class="diff-addedline diff-side-added"><div>// Configuring the Device Configuration Registers</div></td>
</tr>
<tr>
<td colspan="2" class="diff-empty diff-side-deleted"></td>
<td class="diff-marker" data-marker="+"></td>
<td class="diff-addedline diff-side-added"><div>// 80Mhz Core/Periph, Pri Osc w/PLL, Write protect Boot Flash</div></td>
</tr>
<tr>
<td colspan="2" class="diff-empty diff-side-deleted"></td>
<td class="diff-marker" data-marker="+"></td>
<td class="diff-addedline diff-side-added"><div>#pragma config UPLLEN = ON // USB PLL Enabled</div></td>
</tr>
<tr>
<td colspan="2" class="diff-empty diff-side-deleted"></td>
<td class="diff-marker" data-marker="+"></td>
<td class="diff-addedline diff-side-added"><div>#pragma config UPLLIDIV = DIV_2 // USB PLL Input Divider</div></td>
</tr>
<tr>
<td colspan="2" class="diff-empty diff-side-deleted"></td>
<td class="diff-marker" data-marker="+"></td>
<td class="diff-addedline diff-side-added"><div>#pragma config FPLLMUL = MUL_20, FPLLIDIV = DIV_2, FPLLODIV = DIV_1, FWDTEN = OFF</div></td>
</tr>
<tr>
<td colspan="2" class="diff-empty diff-side-deleted"></td>
<td class="diff-marker" data-marker="+"></td>
<td class="diff-addedline diff-side-added"><div>#pragma config POSCMOD = HS, FNOSC = PRIPLL, FPBDIV = DIV_1</div></td>
</tr>
<tr>
<td colspan="2" class="diff-empty diff-side-deleted"></td>
<td class="diff-marker" data-marker="+"></td>
<td class="diff-addedline diff-side-added"><div>#pragma config ICESEL = ICS_PGx2, BWP = OFF</div></td>
</tr>
<tr>
<td colspan="2" class="diff-empty diff-side-deleted"></td>
<td class="diff-marker" data-marker="+"></td>
<td class="diff-addedline diff-side-added"><div>#pragma config FSOSCEN = OFF</div></td>
</tr>
<tr>
<td colspan="2" class="diff-empty diff-side-deleted"></td>
<td class="diff-marker" data-marker="+"></td>
<td class="diff-addedline diff-side-added"><div></code></div></td>
</tr>
<tr>
<td colspan="2" class="diff-empty diff-side-deleted"></td>
<td class="diff-marker" data-marker="+"></td>
<td class="diff-addedline diff-side-added"><div></pre></div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td class="diff-context diff-side-deleted"><br /></td>
<td class="diff-marker"></td>
<td class="diff-context diff-side-added"><br /></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td class="diff-context diff-side-deleted"><div>More information about configuration registers can be found in Section 32 of the Reference Manual.</div></td>
<td class="diff-marker"></td>
<td class="diff-context diff-side-added"><div>More information about configuration registers can be found in Section 32 of the Reference Manual.</div></td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td class="diff-deletedline diff-side-deleted"><br /></td>
<td colspan="2" class="diff-empty diff-side-added"></td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td class="diff-deletedline diff-side-deleted"><br /></td>
<td colspan="2" class="diff-empty diff-side-added"></td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td class="diff-deletedline diff-side-deleted"><div>'''CODE'''</div></td>
<td colspan="2" class="diff-empty diff-side-added"></td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td class="diff-deletedline diff-side-deleted"><br /></td>
<td colspan="2" class="diff-empty diff-side-added"></td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td class="diff-deletedline diff-side-deleted"><div>* The NU32v2 bootloader project, written in MPLAB Assembly, with a "hello_world" type blinking LED example tacked on, is provided here: [[Media:NU32v2_pic32bootloader_source.zip|PIC32 code]].</div></td>
<td colspan="2" class="diff-empty diff-side-added"></td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td class="diff-deletedline diff-side-deleted"><br /></td>
<td colspan="2" class="diff-empty diff-side-added"></td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td class="diff-deletedline diff-side-deleted"><div>* The NU32v2_serial_bootloader app source code, written in Processing, is provided here: [[Media:NU32v2_serial_bootloader_source.zip|PIC32 code]]. '''New for Feb 14 2011- Should crash less. Email Nick if you repeatedly get Error # in the message area.'''</div></td>
<td colspan="2" class="diff-empty diff-side-added"></td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td class="diff-deletedline diff-side-deleted"><br /></td>
<td colspan="2" class="diff-empty diff-side-added"></td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td class="diff-deletedline diff-side-deleted"><div>* The Mac OSX executable version of the bootloader app is here: [[Media:NU32v2_serial_bootloader_osx.zip|NU32v2 serial bootloader for OSX]]. '''New for Feb 14 2011- Should crash less. Email Nick if you repeatedly get Error # in the message area.'''</div></td>
<td colspan="2" class="diff-empty diff-side-added"></td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td class="diff-deletedline diff-side-deleted"><br /></td>
<td colspan="2" class="diff-empty diff-side-added"></td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td class="diff-deletedline diff-side-deleted"><div>The NU32v2_serial_bootloader app allows the user to navigate to and select a .hex file. No other file type selection is allowed. The app also creates a button for each available serial COM port when the app loads, so the NU32v2 board must be powered up and the USB cable must be plugged in before the app is run.</div></td>
<td colspan="2" class="diff-empty diff-side-added"></td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td class="diff-deletedline diff-side-deleted"><br /></td>
<td colspan="2" class="diff-empty diff-side-added"></td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td class="diff-deletedline diff-side-deleted"><div>'''Note about serial communication:''' The NU32v2 board has an [http://www.ftdichip.com/Products/ICs/FT232R.htm FT232RL] built on to allow for easy communication over USB with your computer. This chip translates between the PIC's UART (RS-232) and your PC's USB protocol. The communication is viewable as a "virtual com port" on your computer using the driver provided by FTDI. This chip provides an easy way for your computer and the NU32v2 to communicate, for bootloading, debugging, and general communication.</div></td>
<td colspan="2" class="diff-empty diff-side-added"></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td class="diff-context diff-side-deleted"><br /></td>
<td class="diff-marker"></td>
<td class="diff-context diff-side-added"><br /></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td class="diff-context diff-side-deleted"><div>= Creating a .hex File Using MPLAB =</div></td>
<td class="diff-marker"></td>
<td class="diff-context diff-side-added"><div>= Creating a .hex File Using MPLAB =</div></td>
</tr>
</table>NickMarchukhttps://hades.mech.northwestern.edu//index.php?title=NU32:_A_Detailed_Look_at_Programming_the_PIC32_on_the_NU32&diff=20745&oldid=prevNickMarchuk: /* Programming a PIC32 with a Programmer */2011-12-28T22:05:24Z<p><span dir="auto"><span class="autocomment">Programming a PIC32 with a Programmer</span></span></p>
<table class="diff diff-contentalign-left diff-editfont-monospace" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 22:05, 28 December 2011</td>
</tr><tr>
<td colspan="2" class="diff-lineno">Line 155:</td>
<td colspan="2" class="diff-lineno">Line 155:</td>
</tr>
<tr>
<td class="diff-marker"></td>
<td class="diff-context diff-side-deleted"><div>No code is installed on the PIC32 when it arrives from the factory. To put a program on the microcontroller, a programmer is used. There are a variety of programmers available, including many from Microchip, the manufacturer of the PIC32, [http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=2519&param=en534451&page=wwwdevMPLABEmulatorDebuggers listed here]. These programmers have many functions, including programming and debugging, with more functionality built into the more expensive programmers. </div></td>
<td class="diff-marker"></td>
<td class="diff-context diff-side-added"><div>No code is installed on the PIC32 when it arrives from the factory. To put a program on the microcontroller, a programmer is used. There are a variety of programmers available, including many from Microchip, the manufacturer of the PIC32, [http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=2519&param=en534451&page=wwwdevMPLABEmulatorDebuggers listed here]. These programmers have many functions, including programming and debugging, with more functionality built into the more expensive programmers. </div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td class="diff-context diff-side-deleted"><br /></td>
<td class="diff-marker"></td>
<td class="diff-context diff-side-added"><br /></td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td class="diff-deletedline diff-side-deleted"><div>The <del class="diffchange diffchange-inline">NU32v2</del> can easily be programmed with any of these programmers, but has been designed to work with the [http://www.microchipdirect.com/productsearch.aspx?Keywords=PG164130 PICkit 3], available for around $45.<del class="diffchange diffchange-inline"> </del></div></td>
<td class="diff-marker" data-marker="+"></td>
<td class="diff-addedline diff-side-added"><div>The <ins class="diffchange diffchange-inline">NU32</ins> can easily be programmed with any of these programmers, but has been designed to work with the [http://www.microchipdirect.com/productsearch.aspx?Keywords=PG164130 PICkit 3], available for around $45.</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td class="diff-context diff-side-deleted"><br /></td>
<td class="diff-marker"></td>
<td class="diff-context diff-side-added"><br /></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td class="diff-context diff-side-deleted"><div>= The PIC32 Bootloader and Bootloader App =</div></td>
<td class="diff-marker"></td>
<td class="diff-context diff-side-added"><div>= The PIC32 Bootloader and Bootloader App =</div></td>
</tr>
</table>NickMarchuk