![Pololu P-Star 25K50 Micro User Manual Download Page 37](http://html1.mh-extra.com/html/pololu/p-star-25k50-micro/p-star-25k50-micro_user-manual_1574946037.webp)
9. Compiling a USB application with M-Stack
The examples in
show how to use the Microchip USB stack on the P-Star. M-
Stack is an alternative USB stack for PICs that we have modified to work on the P-Star.
This section explains how to compile a USB application using
[https://github.com/signal11/m-
, a USB device stack that is an alternative to the Microchip USB stack.
This tutorial will explain how to use MPLAB X and XC8 to compile the demo apps that come with M-
Stack and run them on the P-Star 25K50 Micro. These apps can be used as a starting point for your
own app. You can see what demo apps are available by looking in the
[https://github.com/pololu/m-stack/tree/master/apps]
.
1. First, install
[http://www.microchip.com/mplabx]
, and
[http://www.microchip.com/compilers]
. We will use MPLAB X and XC8 to
compile the example code. We will not use XC16, but the MPLAB X projects we will open
have configurations that use XC16 and installing it will avoid some issues when opening
those projects.
2. Next, download the
[https://github.com/pololu/m-stack]
. If you download
it as a ZIP archive, be sure to extract the files from the ZIP archive before continuing.
3. Run the MPLAB X IDE.
4. In the “File” menu, select “Open Project…”, and navigate to
apps\hid_mouse\MPLAB.X
. Select
the
MPLAB.X
folder and click “Open Project”.
5. In the “Production” menu, set the Main Project to be the project you just opened.
6. In the “Production” menu, set the project configuration to “P-Star_25K50_Micro”. This
configures the project so that it will be built for the PIC18F25K50 and use the
--codeoffset
0x2000
option so that it can be loaded with the P-Star’s bootloader.
7. If your P-Star is based on the PIC18F45K50, you should reconfigure MPLAB X to compile for
the correct microcontroller. To do this, open the “File” menu and select “Project properties”.
On the left-hand side of the Project Properties window, select the “P-Star_25K50_Micro”
configuration. Set the Device for this configuration to the model of the PIC on your P-Star
(e.g. “PIC18F45K50”). You can also rename the configuration to avoid confusion. Click OK.
8. In the “Production” menu, select “Build Main Project”.
9. The “Output” pane should now show the build output from MPLAB X. One of the last lines of
the output should say “Loading code from” and have the full path to the HEX file produced
during compilation.
Pololu P-Star User’s Guide
© 2001–2019 Pololu Corporation
9. Compiling a USB application with M-Stack
Page 37 of 46