Hot!HOW TO: PIC32MZ USB without Harmony

Page: 123 > Showing page 1 of 3
Author
MisterHemi
Junior Member
  • Total Posts : 100
  • Reward points : 0
  • Joined: 2017/11/02 12:24:21
  • Location: 0
  • Status: offline
2019/01/22 17:03:12 (permalink)
5 (3)

HOW TO: PIC32MZ USB without Harmony

See the updates below
First, i'd like to thank those who have helped me and others in the past.

I'll try to make it short.... i'm no expert on USB and may not be able to answer your questions, however, I managed to get the PIC32MZ EF to enumerate without using Harmony.
 
Some things may possibly be specific to my setup, i'm using a MacBook Pro (mid 2015) and the Curiosity PIC32MZ EF development board. In the attached project settings it configured to run at 200MHz using the 24MHz clock on the development board, so if your board is different make the appropriate changes.

Some important things to note: I added a lot of comments and you'll need to read them especially in the usb.h file.

While there may be other more flexible USB stacks out there this one is simple and many things are hard coded but useful for understanding how the PIC's USB works. I found the data sheet to be incomplete and sometimes inaccurate.


It's probably not perfect and i'm sure others could probably do a better job however it works.

I haven't tested the functions for Endpoints 1 and 2, but do think they'll work, but it does enumerate and at least it may be a useable reference for anyone working on USB on the PIC32MZ family. This is just the basics needed to get you going. It took a very long time to get to this point due to the lack of documentation, etc.
 
CORRECTIONS:
In the USB ISR (lines 287-291) should read:

 
 
 
if(ep0data[0] & 0x80){ /* A "1" indicates IN to the host or "0" indicates OUT from the host */
controlTrans(); // Process Control Transfers and OUT Packets.
} else {
inPacket(); // Process OUT packets.
}
 
 
 

 
UPDATE - 20 March 2019:
I'm attaching a USB MIDI example below. This might be a better example especially if you have more than a short, basic Configuration Descriptor. 
 
I put all of the Configuration Descriptors in one array and wrote a function to transmit the bulk/block of array data in several transfers, if the array data is more than the buffer size of the Endpoint. That function could be modified for use with other endpoints to send data stored in an array, etc.
 
Also in two places you will see references to LEDs which only pertain to the Curiosity PIC32MZ EF development board. Here:

 
// The following LEDs only apply to the Curiosity PIC32MZ EF development board
// They can be edited or deleted when using a different board.
/* LEDs defined */
#define led_1 LATEbits.LATE3
#define led_2 LATEbits.LATE4
#define led_3 LATEbits.LATE6
#define led_4b LATBbits.LATB0
#define led_4g LATBbits.LATB1
#define led_4r LATBbits.LATB5
 

 
and in the function void initBoard() here:

 
// The following LEDs only apply to the Curiosity PIC32MZ EF development board
// They can be edited or deleted when using a different board.
led_4b = 1; // Turn off the LED4 Blue (active low)
led_4g = 1; // Turn off the LED4 Green (active low)
led_4r = 1; // Turn off the LED4 Red (active low)
 

 
You might need or want to delete those if you're using a different board.
 
When I feel up to it I may look into USB AUDIO (something I need to do eventually anyway). If you happen to have the correct descriptors for an audio input device that would be helpful and save me time. Then I could include them in an example.
Hopefully you'll find this helpful.
 
Also one other thing.... I believe to conform to the USB standards you'll need to enable USB, e.g. - initUSB(), AFTER detecting VUSB.
post edited by MisterHemi - 2019/03/20 16:55:12

My configuration:
MacBook Pro (Retina, 15-inch, Mid 2015) with MacOS High Sierra (10.13.3) and MPLAB X IDE v4.15
 
Curiosity PIC MZ EF, PIC24F Curiosity, and XPRESS EVAL BOARD (PIC16F18855).
#1

45 Replies Related Threads

    MisterHemi
    Junior Member
    • Total Posts : 100
    • Reward points : 0
    • Joined: 2017/11/02 12:24:21
    • Location: 0
    • Status: offline
    Re: HOW TO: PIC32MZ USB without Harmony 2019/01/22 17:08:46 (permalink)
    0
    Here's how it looks when attached to my MacBook Pro:
     

    Attached Image(s)


    My configuration:
    MacBook Pro (Retina, 15-inch, Mid 2015) with MacOS High Sierra (10.13.3) and MPLAB X IDE v4.15
     
    Curiosity PIC MZ EF, PIC24F Curiosity, and XPRESS EVAL BOARD (PIC16F18855).
    #2
    daveX
    Starting Member
    • Total Posts : 40
    • Reward points : 0
    • Joined: 2013/07/20 15:20:21
    • Location: 0
    • Status: offline
    Re: HOW TO: PIC32MZ USB without Harmony 2019/01/22 17:30:46 (permalink)
    0
    That looks pretty good!
    Do you have header files for any of the rest of the MZ?
    #3
    MisterHemi
    Junior Member
    • Total Posts : 100
    • Reward points : 0
    • Joined: 2017/11/02 12:24:21
    • Location: 0
    • Status: offline
    Re: HOW TO: PIC32MZ USB without Harmony 2019/01/22 17:40:32 (permalink)
    0
    Sorry no other header files but it's rather simple and should work with little or no modifications.

    My configuration:
    MacBook Pro (Retina, 15-inch, Mid 2015) with MacOS High Sierra (10.13.3) and MPLAB X IDE v4.15
     
    Curiosity PIC MZ EF, PIC24F Curiosity, and XPRESS EVAL BOARD (PIC16F18855).
    #4
    MisterHemi
    Junior Member
    • Total Posts : 100
    • Reward points : 0
    • Joined: 2017/11/02 12:24:21
    • Location: 0
    • Status: offline
    Re: HOW TO: PIC32MZ USB without Harmony 2019/01/22 17:52:05 (permalink)
    0
    There are some things i'll probably need to explain. When you look in usb.h you'll see the string descriptors.

    It may seem odd that it's formatted like this:
    unsigned char string2[] = {
     /* Descriptor Length */ 46, /* 46 or 0x2E */
    /* DescriptorType: STRING */ 0x03,
     /* Product Name */ 'Y',0,'o',0,'u',0,'r',0,
    ' ',0,'P',0,'r',0,'o',0,'d',0,'u',0,'c',0,'t',0,' ',0,'N',0,'a',0,'m',0,
    'e',0,' ',0,'H',0,'e',0,'r',0,'e',0
     };

     
    It's because the text is supposed to be Unicode 16 (UTF-16) however the LSB is the same as ASCII while the MSB remains zero (0) and since USB is "little endian" the 0 after each character is the MSB. It may differ with languages/character sets other than English.

    My configuration:
    MacBook Pro (Retina, 15-inch, Mid 2015) with MacOS High Sierra (10.13.3) and MPLAB X IDE v4.15
     
    Curiosity PIC MZ EF, PIC24F Curiosity, and XPRESS EVAL BOARD (PIC16F18855).
    #5
    MisterHemi
    Junior Member
    • Total Posts : 100
    • Reward points : 0
    • Joined: 2017/11/02 12:24:21
    • Location: 0
    • Status: offline
    Re: HOW TO: PIC32MZ USB without Harmony 2019/01/23 08:24:30 (permalink)
    0
    Grrr!!!
     
    I just wrote a long post and the forum software dumped it saying "you don't have permission to post"

    My configuration:
    MacBook Pro (Retina, 15-inch, Mid 2015) with MacOS High Sierra (10.13.3) and MPLAB X IDE v4.15
     
    Curiosity PIC MZ EF, PIC24F Curiosity, and XPRESS EVAL BOARD (PIC16F18855).
    #6
    JPortici
    Super Member
    • Total Posts : 623
    • Reward points : 0
    • Joined: 2012/11/17 06:27:45
    • Location: Grappaland
    • Status: offline
    Re: HOW TO: PIC32MZ USB without Harmony 2019/01/23 08:34:59 (permalink)
    0
    And now you learned the hard way to write your post on a text editor first :D
     
    (VERY interested. What is the performance hit? the damn harmony driver takes up about 24k of flash and because the whole thing, also intterrupts, is done via pointers and function pointers, it's really hard for me to keep track of what's happening)
    post edited by JPortici - 2019/01/23 08:38:27
    #7
    Howard Long
    Super Member
    • Total Posts : 651
    • Reward points : 0
    • Joined: 2005/04/04 08:50:32
    • Status: offline
    Re: HOW TO: PIC32MZ USB without Harmony 2019/01/23 09:14:30 (permalink)
    0
    OP: You win the entire forum for a good week+ for this!
     
    When I unzipped it, I was expecting at least a dozen source files, there's only two, one .c and one .h!
     
    Really great work.
     
     
    #8
    Howard Long
    Super Member
    • Total Posts : 651
    • Reward points : 0
    • Joined: 2005/04/04 08:50:32
    • Status: offline
    Re: HOW TO: PIC32MZ USB without Harmony 2019/01/23 09:16:53 (permalink)
    0
    Jack_M
    And now you learned the hard way to write your post on a text editor first :D
     
    (VERY interested. What is the performance hit? the damn harmony driver takes up about 24k of flash and because the whole thing, also intterrupts, is done via pointers and function pointers, it's really hard for me to keep track of what's happening)




    I agree, the Harmony USB stack wasn't built for either comfort of reading, or speed of running.
    post edited by Howard Long - 2019/01/25 01:09:48
    #9
    JPortici
    Super Member
    • Total Posts : 623
    • Reward points : 0
    • Joined: 2012/11/17 06:27:45
    • Location: Grappaland
    • Status: offline
    Re: HOW TO: PIC32MZ USB without Harmony 2019/01/23 09:17:04 (permalink)
    0
    Howard Long
    When I unzipped it, I was expecting at least a dozen source files, there's only two, one .c and one .h!



    This +1000!!!!
    I can't wait to try it, hope i can find some time later.
    post edited by JPortici - 2019/01/23 09:18:38
    #10
    MisterHemi
    Junior Member
    • Total Posts : 100
    • Reward points : 0
    • Joined: 2017/11/02 12:24:21
    • Location: 0
    • Status: offline
    Re: HOW TO: PIC32MZ USB without Harmony 2019/01/23 09:44:23 (permalink)
    0
    Jack_M
    And now you learned the hard way to write your post on a text editor first :D
     
    (VERY interested. What is the performance hit? the damn harmony driver takes up about 24k of flash and because the whole thing, also intterrupts, is done via pointers and function pointers, it's really hard for me to keep track of what's happening)




    MPLAB reports this: Program Used: 25,012 (0x61B4) Free: 2,072,140 (0x1F9E4C)
     
    It's very small as you see. I haven't tested the speed yet but it does show as a high speed device.
     
    EDITED TO ADD: I think what it's showing is my code including my display library, etc. I think the actual USB code is much smaller. See the attached photo.
    post edited by MisterHemi - 2019/01/27 16:00:37

    Attached Image(s)


    My configuration:
    MacBook Pro (Retina, 15-inch, Mid 2015) with MacOS High Sierra (10.13.3) and MPLAB X IDE v4.15
     
    Curiosity PIC MZ EF, PIC24F Curiosity, and XPRESS EVAL BOARD (PIC16F18855).
    #11
    MisterHemi
    Junior Member
    • Total Posts : 100
    • Reward points : 0
    • Joined: 2017/11/02 12:24:21
    • Location: 0
    • Status: offline
    Re: HOW TO: PIC32MZ USB without Harmony 2019/01/23 09:46:14 (permalink)
    0
    Howard Long
    OP: You win the entire forum for a good week+ for this!
     
    When I unzipped it, I was expecting at least a dozen source files, there's only two, one .c and one .h!
     
    Really great work.
     
     




    Thank you! :-)
     
    In the post I attempted a little while ago I included the source code. I was going to explain a few little details so others could customize it for their needs. I'll try again... hold on, lol

    My configuration:
    MacBook Pro (Retina, 15-inch, Mid 2015) with MacOS High Sierra (10.13.3) and MPLAB X IDE v4.15
     
    Curiosity PIC MZ EF, PIC24F Curiosity, and XPRESS EVAL BOARD (PIC16F18855).
    #12
    MisterHemi
    Junior Member
    • Total Posts : 100
    • Reward points : 0
    • Joined: 2017/11/02 12:24:21
    • Location: 0
    • Status: offline
    Re: HOW TO: PIC32MZ USB without Harmony 2019/01/23 10:23:28 (permalink)
    0
    Ok, second attempt....
     
    I was going to explain a few things and post the source code (see below).
     
    In the beginning there are some defined values:

     
     
     
    /* USB related values */
    #define EP0TXBUFFSIZE 8 // In multiples of 8, e.g.- 8 (x8) equals a size of 64
    #define EP1RXBUFFSIZE 8 // Also in multiples of 8, e.g.- 8 (x8) equals a size of 64
    #define EP2TXBUFFSIZE 8 // Also in multiples of 8, e.g.- 8 (x8) equals a size of 64
     
     
     
     
    The buffer values , as seen in the USB initialization, for RXMAXP and TXMAXP are multiples of 8.
    So if you define EPxTXBUFFSIZE/EPxRXBUFFSIZE (with "x" being the endpoint number) as 1 then the buffer size would be 8 bytes (1 x 8), if it's defined as 8 then it would be 64 bytes (8 x 8), etc.
     
    As you will see some of the register names don't match what it says in the data sheet. I was able to find some of the registers and the associated bits in the file p32mz2048efm100.h which on my MacBook Pro is located in:
    Applications/microchip/xc32/v2.15/pic32mx/lib/proc/32MZ2048EFM100/p32mz2048efm100.h

    I would assume the register structs and bit name definitions are the same for all of the MZ series.
     
    The registers for and operation of endpoint 0 (zero) is different than for the other endpoints (1-7).
    You can directly access the registers for each endpoint, as i'll explain as follows.

    Here is an example from p32mz2048efm100.h:

     
     
     
    #define USBIENCSR0 USBIENCSR0
    extern volatile unsigned int USBIENCSR0 __attribute__((section("sfrs"), address(0xBF8E3010)));
    typedef union {
    struct {
    unsigned TXMAXP:11;
    unsigned MULT:5;
    unsigned TXPKTRDY:1;
    unsigned FIFONE:1;
    unsigned ERROR:1;
    unsigned FLUSH:1;
    unsigned SETUPPKT:1;
    unsigned RXSTALL:1;
    unsigned CLRDT:1;
    unsigned NAKTMOUT:1;
    unsigned DATATGGL:1;
    unsigned DTWREN:1;
    unsigned DMAREQMD:1;
    unsigned FRCDATTG:1;
    unsigned DMAREQEN:1;
    unsigned MODE:1;
    unsigned :1;
    unsigned AUTOSET:1;
    };
    struct {
    unsigned :18;
    unsigned UNDERRUN:1;
    unsigned :1;
    unsigned SENDSTALL:1;
    unsigned SENTSTALL:1;
    unsigned :1;
    unsigned INCOMPTX:1;
    unsigned :6;
    unsigned ISO:1;
    };
    } __USBIENCSR0bits_t;
     
     
     

     
    The endpoint protocol is set using registers USBExCSR3 for RX (receive) protocol (with "x" being the endpoint number) and USBExCSR2 for TX (transmit )protocol (with "x" being the endpoint number), as follows:

     
     
     
    USBE1CSR3bits.PROTOCOL = 1; // Endpoint 1 - RX Endpoint Protocol Control bits
    USBE2CSR2bits.PROTOCOL = 1; // Endpoint 2 - TX Endpoint Protocol Control bits
    //PROTOCOL<1:0>: RX/TX Endpoint Protocol Control bits
    //11 = Interrupt
    //10 = Bulk
    //01 = Isochronous
    //00 = Control
     
     
     

     
    Another way of selecting the endpoint registers is by using

     
     
     
    USBCSR3bits.ENDPOINT = x;
     
     
     

    but whenever possible I prefer to address the endpoint's register directly.
     
    In the code below I select the register for the endpoint and set the address for the endpoint's FIFO. Since I made the buffers 64 bytes (see above) I spaced them 64 bytes (0x0040) apart. I'm not certain but I assume this is correct but the PIC32MZ also has an option for dynamic FIFOs but I haven't used them and don't fully understand how they work.

     
     
     
    USBCSR3bits.ENDPOINT = 1;
    USBFIFOAbits.RXFIFOAD = 0x0000; // Receive Endpoint FIFO Address bits

    USBCSR3bits.ENDPOINT = 2;
    USBFIFOAbits.TXFIFOAD = 0x0040; // Transmit Endpoint FIFO Address bits
     
     
     

     
    I think the comments in the code and references to the data sheet should help to explain and clarify things.
    Let me know what you think or of any corrections, etc.
     
     
    post edited by MisterHemi - 2019/01/23 14:58:39

    My configuration:
    MacBook Pro (Retina, 15-inch, Mid 2015) with MacOS High Sierra (10.13.3) and MPLAB X IDE v4.15
     
    Curiosity PIC MZ EF, PIC24F Curiosity, and XPRESS EVAL BOARD (PIC16F18855).
    #13
    MisterHemi
    Junior Member
    • Total Posts : 100
    • Reward points : 0
    • Joined: 2017/11/02 12:24:21
    • Location: 0
    • Status: offline
    Re: HOW TO: PIC32MZ USB without Harmony 2019/01/23 10:27:07 (permalink)
    0
    Here's the source code:
    main.c

    /* 
    * PIC32MZ Basic USB

    * Released under FreeBSD License 

    * (C)2019 - Mark Serran Lewis 
    * mark@lewistechnogroup.com
    * All rights reserved.

    * Redistribution and use in source and binary forms, with or without 
    * modification, are permitted provided that the following conditions are 
    * met: 

    * 1. Redistributions of source code must retain the above copyright 
    * notice, this list of conditions and the following disclaimer. 
    * 2. Redistributions in binary form must reproduce the above copyright 
    * notice, this list of conditions and the following disclaimer in the 
    * documentation and/or other materials provided with the distribution. 

    * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
    * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
    * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
    * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
    * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
    * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
    * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
    * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
    * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
    * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
    * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 

    * The views and conclusions contained in the software and documentation 
    * are those of the authors and should not be interpreted as representing 
    * official policies, either expressed or implied, of the FreeBSD Project. 
    *
    */
    // Setup for PIC32MZ EF device for 200 MHz operation - Device Configuration Bits.
    /*** DEVCFG0 ***/
    #pragma config DEBUG = OFF
    #pragma config JTAGEN = OFF
    #pragma config ICESEL = ICS_PGx1
    #pragma config TRCEN = OFF
    #pragma config BOOTISA = MIPS32
    #pragma config FECCCON = OFF_UNLOCKED
    #pragma config FSLEEP = OFF
    #pragma config DBGPER = PG_ALL
    #pragma config SMCLR = MCLR_NORM
    #pragma config SOSCGAIN = GAIN_LEVEL_3
    #pragma config SOSCBOOST = ON
    #pragma config POSCGAIN = GAIN_LEVEL_3
    #pragma config POSCBOOST = ON
    #pragma config EJTAGBEN = NORMAL
    #pragma config CP = OFF
    /*** DEVCFG1 ***/
    #pragma config FNOSC = SPLL
    #pragma config DMTINTV = WIN_127_128
    #pragma config FSOSCEN = ON
    #pragma config IESO = ON
    #pragma config POSCMOD = EC
    #pragma config OSCIOFNC = ON
    #pragma config FCKSM = CSECME
    #pragma config WDTPS = PS1048576
    #pragma config WDTSPGM = STOP
    #pragma config FWDTEN = OFF
    #pragma config WINDIS = NORMAL
    #pragma config FWDTWINSZ = WINSZ_25
    #pragma config DMTCNT = DMT31
    #pragma config FDMTEN = OFF
    /*** DEVCFG2 ***/
    #pragma config FPLLIDIV = DIV_3
    #pragma config FPLLRNG = RANGE_5_10_MHZ
    #pragma config FPLLICLK = PLL_POSC
    #pragma config FPLLMULT = MUL_50
    #pragma config FPLLODIV = DIV_2
    #pragma config UPLLFSEL = FREQ_24MHZ
    /*** DEVCFG3 ***/
    #pragma config USERID = 0xFFFF
    #pragma config FMIIEN = ON
    #pragma config FETHIO = ON
    #pragma config PGL1WAY = OFF
    #pragma config PMDL1WAY = ON
    #pragma config IOL1WAY = ON
    #pragma config FUSBIDIO = ON
    /*** BF1SEQ0 ***/
    #pragma config TSEQ = 0x0000
    #pragma config CSEQ = 0xFFFF

    #define SYS_FREQ (200000000L)
    #define GetSystemClock() (200000000ul) // PIC32MZ System Clock in Hertz.
    /* USB related values */
    #define EP0TXBUFFSIZE 8 // In multiples of 8, e.g.- 8 (x8) equals a size of 64 bytes.
    #define EP1RXBUFFSIZE 8 // Also in multiples of 8, e.g.- 8 (x8) equals a size of 64
    #define EP2TXBUFFSIZE 8 // Also in multiples of 8, e.g.- 8 (x8) equals a size of 64
    #include <xc.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <sys/attribs.h>
    #include <sys/kmem.h>
    #include <proc/p32mz2048efm100.h>
    #include "usb.h"
    /*********** Variables ***********/
    volatile int ep0rbc; // Endpoint 0 - Received Bytes Count (USB).
    volatile int ep1rbc; // Endpoint 1 - Received Bytes Count (USB).
    int epBufSize[8]; // Endpoint Buffers Size.
    volatile uint32_t i;
    uint8_t *ep0usbData;
    uint8_t *ep2usbData;
    uint8_t endpoint;
    volatile int usbReset;
    volatile uint8_t ep0data[EP0TXBUFFSIZE * 8]; // USB end point 0 data - Array should be the same length as the largest USB FIFO size
    volatile uint8_t ep1data[EP1RXBUFFSIZE * 8]; // USB end point 1 data - Array should be the same length as the largest USB FIFO size
    volatile uint8_t ep2data[EP2TXBUFFSIZE * 8]; // USB end point 2 data - Array should be the same length as the largest USB FIFO size
    volatile uint8_t *tempData;
    volatile uint16_t bmbRequest; // bmRequestType, bRequest
    volatile uint16_t wValue;
    volatile uint16_t wIndex;
    volatile uint16_t wLength;
    volatile uint8_t usbAddress;
    volatile uint8_t setDevAddr;
    volatile uint32_t ep0ArrPos;
    volatile uint32_t ep2ArrPos;
    enum {FALSE,TRUE};
    /******* End of Variables ********/
    /************* Functions *************/
    void initBoard();
    void initUSB();
    void setAddress(uint8_t address);
    void controlTrans();
    void inPacket();
    void txUSB_ep0(uint32_t ep0TXLen);
    void rxUSB_ep1();
    void txUSB_ep2(uint32_t ep2TXLen);
    /******** End of Functions **********/
    void __ISR(_USB_VECTOR, ipl7AUTO) _USB_Handler(void){
    //led_1 = 1; // Verify the ISR was called. 

    if(USBCSR2bits.RESETIF){ // In Device mode, indicates reset signaling is detected on the bus.
    usbReset = TRUE; // Indicate the bus was reset and should be IDLE now.

    // Note that USB reset will reset a lot of the registers and you should 
    // do most initialization in the USB reset interrupt handler.
    USBE0CSR0bits.TXMAXP = 8;
    USBCSR1bits.EP0IE = 1;
    USBE0CSR2bits.SPEED = 1; // Endpoint 0 Operating Speed Control bits

    USBCSR2bits.RESETIF = 0;
    }

    /* Endpoint 0 Interrupt Handler */
    if(USBCSR0bits.EP0IF){
    usbReset = FALSE;

    if(setDevAddr == TRUE){ // Set Address, upon first IN transaction
    setAddress(usbAddress);
    setDevAddr = FALSE;
    }

    if(USBE0CSR0bits.RXRDY){
    ep0rbc = USBE0CSR2bits.RXCNT; // Endpoint 0 - Received Bytes Count
    tempData = (uint8_t *)&USBFIFO0;

    for(i = 0; i < ep0rbc; i++){
    ep0data[i] = *(tempData + (i & 3));
    }
    USBE0CSR0bits.RXRDYC = 1;

    // The packet length of control transfers in low speed devices must be 
    // 8 bytes, high speed devices allow a packet size of 8, 16, 32 or 64 bytes 
    // and full speed devices must have a packet size of 64 bytes.
    bmbRequest = (ep0data[0] << 8) | ep0data[1]; // bmRequestType, bRequest
    wValue = (ep0data[3] << 8) | ep0data[2];
    wIndex = (ep0data[5] << 8) | ep0data[4];
    wLength = (ep0data[7] << 8) | ep0data[6];

    if(ep0data[0] & 0x80){ /* A "1" indicates OUT from the host or "0" indicates IN to the host */
    controlTrans(); // Process Control Transfers and OUT Packets.
    } else {
    inPacket(); // Process IN packets.
    }
    }


    if(USBE0CSR0bits.SETEND){
    USBE0CSR0bits.SETENDC = 1;
    }

    USBCSR0bits.EP0IF = 0; // Clear the USB EndPoint 0 Interrupt Flag.
    }

    /* Endpoint 1 RX Interrupt Handler */
    if(USBCSR1bits.EP1RXIF){ // Endpoint 1 Received A Packet.
    rxUSB_ep1();
    // Insert your function here to process received packets
    USBCSR1bits.EP1RXIF = 0; // Supposedly Cleared By Hardware (Clear Just In Case).
    }

    /* Endpoint 2 TX Interrupt Handler */
    if(USBCSR0bits.EP2TXIF){ // Endpoint 2 Transmit A Packet.
    // To send packets via EP2 call function txUSB_ep2()
    // see how packets are sent in function controlTrans() as an example
    // otherwise this interrupt handler may have limited use depending
    // upon your implementation.
    USBCSR0bits.EP2TXIF = 0; // Supposedly Cleared By Hardware (Clear Just In Case). 
    }


    IFS4bits.USBIF = 0; // Reset the USB Interrupt flag
    }
    void main(){
    initBoard();
    initUSB();

    while(1){
    // Do nothing, loop endlessly.
    }
    }
    void initBoard(){
    ANSELA = 0x00000000; // Disable analog functions
    ANSELB = 0x00000000; // Disable analog functions
    ANSELC = 0x00000000; // Disable analog functions
    ANSELD = 0x00000000; // Disable analog functions
    ANSELE = 0x00000000; // Disable analog functions
    ANSELF = 0x00000000; // Disable analog functions
    ANSELG = 0x00000000; // Disable analog functions
    TRISA = 0x0000; // Set all port A bits as outputs
    TRISB = 0x0000; // Set all port B bits as outputs 
    TRISC = 0x0000; // Set all port C bits as outputs 
    TRISD = 0x0000; // Set all port D bits as outputs 
    TRISE = 0x0000; // Set all port E bits as outputs 
    TRISF = 0x0008; // Set all port F bits as outputs except F3 (USBID)
    TRISG = 0x0000; // Set all port G bits as outputs

    /* Configure interrupts */
    asm volatile("ei"); // Globally enable interrupts (in Assembly).
    INTCONbits.MVEC = 1; // Enable system wide multi-vectored interrupts.
    return;
    }
    void initUSB(){
    // Configure the USB hardware and registers.
    USBCSR0bits.SOFTCONN = 0; // 1 = The USB D+/D- lines are enabled and active, 
    // 0 = The USB D+/D- lines are disabled and are tri-stated.

    USBCSR2bits.RESETIE = 0; // Disabled. When enabled IN packets/Set Address 
    // aren't received (unknown reason).

    /* Clear the Endpoint interrupt flags */
    USBCSR0bits.EP0IF = 0;
    USBCSR1bits.EP1RXIF = 0;
    USBCSR0bits.EP2TXIF = 0;

    IPC33bits.USBIP = 7; // USB Interrupt Priority.
    IPC33bits.USBIS = 1; // USB Interrupt Sub-Priority.

    usbAddress = 0;
    USBCSR0bits.FUNC = 0; // Initially set the USB address to 0 until
    // later when the host assigns an address

    // Configure endpoint 0 first.
    USBE0CSR0bits.TXMAXP = EP0TXBUFFSIZE; // Set endpoint 0 buffer to 64 bytes (multiples of 8).

    USBE1CSR0bits.MODE = 0; // 0 = Endpoint is RX.
    USBE2CSR0bits.MODE = 1; // 1 = Endpoint is TX

    /* These are multiples of 8, e.g.- "1" is 8 bytes, "8" is 64 bytes */
    USBE1CSR1bits.RXMAXP = EP1RXBUFFSIZE; // Endpoint 1 - Maximum RX Payload Per Transaction Control bits
    USBE2CSR0bits.TXMAXP = EP2TXBUFFSIZE; // Endpoint 2 - Maximum TX Payload per transaction Control bits

    USBE1CSR3bits.PROTOCOL = 1; // Endpoint 1 - RX Endpoint Protocol Control bits 
    USBE2CSR2bits.PROTOCOL = 1; // Endpoint 2 - TX Endpoint Protocol Control bits 
    //PROTOCOL<1:0>: RX/TX Endpoint Protocol Control bits 
    //11 = Interrupt
    //10 = Bulk
    //01 = Isochronous
    //00 = Control

    USBCSR3bits.ENDPOINT = 1;
    USBFIFOAbits.RXFIFOAD = 0x0000; // Receive Endpoint FIFO Address bits

    USBCSR3bits.ENDPOINT = 2;
    USBFIFOAbits.TXFIFOAD = 0x0040; // Transmit Endpoint FIFO Address bits

    USBE1CSR3bits.RXFIFOSZ = 0x6; // Receive FIFO Size bits - 64 bytes
    USBE2CSR3bits.TXFIFOSZ = 0x6; // Transmit FIFO Size bits - 64 bytes

    USBE0CSR2bits.SPEED = 1; // Endpoint 0 Operating Speed Control bits
    USBE1CSR3bits.SPEED = 1; // Endpoint 1: RX Endpoint Operating Speed Control bits - High speed
    USBE2CSR2bits.SPEED = 1; // Endpoint 2: TX Endpoint Operating Speed Control bits - High speed

    // NOTE: We don't set the TX speed in device mode, as noted below from the 
    // data sheet (DS60001320D-page 223):
    // TX Endpoint Operating Speed Control bits (Host mode)
    // In HOST mode it would use CSR2 to set the TX speed, for example:
    // USBExCSR2bits.SPEED = z; 
    // Where x is the endpoint number and z is the speed.

    USBE1CSR1bits.ISO = 1; // Isochronous RX Endpoint Enable bit (Device mode).
    USBE2CSR0bits.ISO = 1; // Isochronous TX Endpoint Enable bit (Device mode).

    /* Enable Endpoint interrupts */
    USBCSR1bits.EP0IE = 1; // Endpoint 0 interrupt enable
    USBCSR2bits.EP1RXIE = 1; // Endpoint 1 RX interrupt enable
    USBCSR1bits.EP2TXIE = 1; // Endpoint 2 TX interrupt enable

    IFS4bits.USBIF = 0; // Clear the USB interrupt flag.
    IEC4bits.USBIE = 1; // Enable the USB interrupt.
    USBCRCONbits.USBIE = 1; // 1 = Enables general interrupt from USB module

    USBCSR0bits.HSEN = 1; // 1 = Enable High Speed (480Mbps) USB mode.
    USBCSR0bits.SOFTCONN = 1; // 1 = The USB D+/D- lines are enabled and active, 0 = The USB D+/D- lines are disabled and are tri-stated.
    }
    void setAddress(volatile uint8_t usbAddress){
    // The Set_Address request changes the address after the status stage. 
    // You must update the FUNC field only after you get the status interrupt.
    USBCSR0bits.FUNC = usbAddress & 0x7F;
    }
    void controlTrans(){

    switch (bmbRequest) {
    case 0x8000: // Get Status (Device)

    break;

    case 0x8100: // Get Status (Interface)

    break;

    case 0x8200: // Get Status (Endpoint)

    break;

    case 0x8006: { // Get Descriptor(s)

    switch (ep0data[3]) {
    case 0x00: { // Undefined
    USBE0CSR0bits.STALL = 1;
    }
    break;

    case 0x01: { // Device Descriptor
    ep0usbData = dev_desc;
    txUSB_ep0(sizeof(dev_desc));
    }
    break;
    case 0x02: { // Configuration Descriptor
    ep0usbData = config_desc1;
    txUSB_ep0(sizeof(config_desc1)); 
    }
    break;
    case 0x03: { // String Descriptors
    switch (ep0data[2]) { 
    case 0x00: { // Language ID
    ep0usbData = string0;
    txUSB_ep0(sizeof(string0));
    }
    break;
    case 0x01: { // Manufacturer
    ep0usbData = string1;
    txUSB_ep0(sizeof(string1));
    }
    break;
    case 0x02: { // Product
    ep0usbData = string2;
    txUSB_ep0(sizeof(string2)); 
    }
    break;
    case 0x03: { // Serial
    ep0usbData = string3;
    txUSB_ep0(sizeof(string3));
    }
    break;

    case 0x04: { // Configuration
    ep0usbData = string4;
    txUSB_ep0(sizeof(string4));
    }
    break;

    case 0x05: { // Interface
    ep0usbData = string5;
    txUSB_ep0(sizeof(string5));
    }
    break;

    } // End of case ep0data[2] switch
    break;

    } // End of case 0x03 switch - String Descriptors
    break;
    default:
    USBE0CSR0bits.STALL = 1;
    break;
    } // End of switch ep0data[3].

    } // End of case 0x8006 switch - Get Descriptor(s).
    break;

    case 0x8008: // Get Configuration

    break;

    case 0x810A: // Get Interface

    break;
    default:
    USBE0CSR0bits.STALL = 1;
    break;
    } // End of switch bmbRequest.

    return; 
    }
    void inPacket(){
    switch (bmbRequest) {

    case 0x0000: // Get Status
    break;

    case 0x0001: // Clear Feature
    break;

    case 0x0003: // Set Feature
    break; 

    case 0x0005: // Save Address
    USBE0CSR0bits.RXRDYC = 1;
    USBE0CSR0bits.DATAEND = 1;
    usbAddress = ep0data[2];
    setDevAddr = TRUE;
    break;

    case 0x0006: // Get Descriptor
    break;

    case 0x0007: // Set Descriptor
    break;

    case 0x0008: // Get Configuration
    break;

    case 0x0009: // Set Configuration
    break;

    case 0x000A: // Get Interface
    break;

    case 0x000B: // Set Interface
    break;

    case 0x000C: // Synchronize Frame
    break;

    default:
    USBE0CSR0bits.STALL = 1;
    break;
    }
    return;
    }
    void txUSB_ep0(uint32_t ep0TXLen){
    volatile uint8_t *ep0fifo = NULL;
    ep0fifo = (uint8_t *)&USBFIFO0;

    for(ep0ArrPos = 0; ep0ArrPos < ep0TXLen; ep0ArrPos++){
    *ep0fifo = ep0usbData[ep0ArrPos];
    }

    USBE0CSR0bits.TXRDY = 1;
    }
    void rxUSB_ep1(){
    ep1rbc = USBE1CSR2bits.RXCNT; // Endpoint 1 - Received Bytes Count
    tempData = (uint8_t *)&USBFIFO1; // The FIFO is 32 bits wide, we only want 8 bits at a time.
    for(i = 0; i < ep1rbc; i++){
    ep1data[i] = *(tempData + (i & 3)); // Store the received bytes in array ep1data[].
    }
    USBE1CSR1bits.RXPKTRDY = 0; // 0 = Written by software to clear this bit 
    // when the packet has been unloaded from the RX FIFO.
    }
    void txUSB_ep2(uint32_t ep2TXLen){
    volatile uint8_t *ep2fifo = NULL;
    ep2fifo = (uint8_t *)&USBFIFO2;

    for(ep2ArrPos = 0; ep2ArrPos < ep2TXLen; ep2ArrPos++){
    *ep2fifo = ep2usbData[ep2ArrPos];
    }
    USBE2CSR0bits.TXPKTRDY = 1;
    }

     
    usb.h

    /* 
    * usb.h for PIC32MZ Basic USB

    * Released under FreeBSD License 

    * (C)2019 - Mark Serran Lewis
    * All rights reserved.

    * Redistribution and use in source and binary forms, with or without 
    * modification, are permitted provided that the following conditions are 
    * met: 

    * 1. Redistributions of source code must retain the above copyright 
    * notice, this list of conditions and the following disclaimer. 
    * 2. Redistributions in binary form must reproduce the above copyright 
    * notice, this list of conditions and the following disclaimer in the 
    * documentation and/or other materials provided with the distribution. 

    * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
    * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
    * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
    * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
    * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
    * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
    * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
    * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
    * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
    * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
    * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 

    * The views and conclusions contained in the software and documentation 
    * are those of the authors and should not be interpreted as representing 
    * official policies, either expressed or implied, of the FreeBSD Project. 
    *
    */
    #ifndef _USB_H /* Guard against multiple inclusion */
    #define _USB_H
    /*********************************************************************
    Device Descriptors
    *********************************************************************/
    unsigned char dev_desc[] = {
    /* Descriptor Length */ 18, /* Always 18 or 0x12 */
    /* DescriptorType: DEVICE */ 0x01,
    /* bcdUSB (ver 2.0) */ 0x00,0x02,
    /* bDeviceClass */ 0x02, /* 0x01 = Audio, 0x02 = Comm */
    /* bDeviceSubClass */ 0x02, /* 0x03 for MIDI, 0x02 = acm */
    /* bDeviceProtocol */ 0x01, /* unused for MIDI, 0x01 = at */
    /* bMaxPacketSize0 */ 64,
    /* idVendor */ 0x34,0x12, /* e.g. - 0x1234 */
    /* idProduct */ 0x01,0x00, /* e.g. - 0x0001 */
    /* bcdDevice */ 0x00,0x01, /* e.g. - 01.00 */
    /* iManufacturer */ 0x01,
    /* iProduct */ 0x02,
    /* iSerialNumber */ 0x03,
    /* bNumConfigurations */ 0x01
    };
    /*********************************************************************
    Config Descriptor
    *********************************************************************/
    unsigned char config_desc1[] = {
    /*Config Descriptor Length */ 9, /* 9 or 0x09 */
    /* DescriptorType: CONFIG */ 0x02,
    /* wTotalLength */ 0x24,0x00,
    /* bNumInterfaces */ 1,
    /* bConfigurationValue */ 2,
    /* iConfiguration */ 4, /* Index of string descriptor describing this configuration. */
    /* bmAttributes */ 0xC0, /* bit 6 set = self powered */
    /* bMaxPower */ 0 /* Value x 2mA */
    };/* NOTE: wTotalLength = Combined length of all descriptors, including this one */
    /*********************************************************************
    Interface Descriptor
    *********************************************************************/
    unsigned char intrface1[] = { 
    /*Interface Descriptor Length */ 9, /* 9 or 0x09 */
    /* DescriptorType: INTERFACE */ 0x04,
    /* bInterfaceNumber */ 0x00,
    /* bAlternateSetting */ 0,
    /* bNumEndpoints */ 3,
    /* bInterfaceClass */ 0x01, /* 0x01 = Audio, 0x02 = Comm */
    /* bInterfaceSubClass */ 0x03, /* 0x03 for MIDI, 0x02 = acm */
    /* bInterfaceProtocol */ 0x00, /* unused for MIDI, 0x01 = at */
    /* iInterface */ 0
    };
    /*********************************************************************
    Endpoint-0 Descriptor
    *********************************************************************/
    unsigned char ep0desc[] = {
    /*Endpoint Descriptor Length */ 6, /* 6 or 0x06 */ 
    /* DescriptorType: ENDPOINT */ 0,
    /* bEndpointAddress */ 0,
    /* bmAttributes */ 0x00,
    /* wMaxPacketSize */ 64,
    /* bInterval */ 32
    };
    /*********************************************************************
    Endpoint-1 Descriptor
    *********************************************************************/
    unsigned char ep1desc[] = {
    /*Endpoint Descriptor Length */ 6, /* 6 or 0x06 */ 
    /* DescriptorType: ENDPOINT */ 0,
    /* bEndpointAddress */ 1,
    /* bmAttributes */ 0x00,
    /* wMaxPacketSize */ 64,
    /* bInterval */ 32
    };
    /*********************************************************************
    Endpoint-2 Descriptor
    *********************************************************************/
    unsigned char ep2desc[] = {
    /*Endpoint Descriptor Length */ 6, /* 6 or 0x06 */
    /* DescriptorType: ENDPOINT */ 0,
    /* bEndpointAddress */ 2,
    /* bmAttributes */ 0x00,
    /* wMaxPacketSize */ 64,
    /* bInterval */ 32
    };

    /*********************************************************************
    String Descriptor Table (below) - These must be Unicode 16 (UTF-16)
    *********************************************************************/
    /*********************************************************************
    Language ID Descriptor
    *********************************************************************/
    unsigned char string0[] = { 
    /* Descriptor Length */ 4, /* 4 or 0x04 */
    /* DescriptorType: STRING */ 0x03,
    /* Language ID: English */ 0x09,0x04
    }; 
    /* *******************************************************************
    String Descriptor: "Lewis Technologies Group"
    *********************************************************************/
    unsigned char string1[] = { 
    /* Descriptor Length */ 44, /* 44 or 0x2C */
    /* DescriptorType: STRING */ 0x03,
    /* Vendor Name */ 'A',0,' ',0,'P',0,'s',0,'e',0,
    'u',0,'d',0,'o',0,' ',0,'M',0,'a',0,'n',0,'u',0,'f',0,'a',0,'c',0,'t',0,'u',0,
    'r',0,'e',0,'r',0
    }; 
    /*********************************************************************
    String Descriptor (Product Name): "USB Example"
    *********************************************************************/
    unsigned char string2[] = {
    /* Descriptor Length */ 46, /* 46 or 0x2E */
    /* DescriptorType: STRING */ 0x03,
    /* Product Name */ 'Y',0,'o',0,'u',0,'r',0,
    ' ',0,'P',0,'r',0,'o',0,'d',0,'u',0,'c',0,'t',0,' ',0,'N',0,'a',0,'m',0,
    'e',0,' ',0,'H',0,'e',0,'r',0,'e',0
    }; 
    /*********************************************************************
    String Descriptor (Serial Number): "xxx-xxxx"
    *********************************************************************/
    unsigned char string3[] = {
    /* Descriptor Length */ 18, /* 18 or 0x12 */
    /* DescriptorType: STRING */ 0x03,
    /* Serial Number */ '1',0,'2',0,'3',0,'-',0,
    '4',0,'5',0,'6',0,'7',0
    };
    unsigned char string4[] = {
    /* Descriptor Length */ 4, /* 4 or 0x04 */
    /* DescriptorType: STRING */ 0x03,
    /* Configuration */ 0x01, 0x00
    };

    unsigned char string5[] = {
    /* Descriptor Length */ 8, /* 8 or 0x08 */
    /* DescriptorType: STRING */ 0x03,
    /* Interface */ 'C',0,'D',0,'C',0
    };
    /* Provide C++ Compatibility */
    #ifdef __cplusplus
    }
    #endif
    #endif /* _USB_H */
    /* *****************************************************************************
    End of File
    */


    My configuration:
    MacBook Pro (Retina, 15-inch, Mid 2015) with MacOS High Sierra (10.13.3) and MPLAB X IDE v4.15
     
    Curiosity PIC MZ EF, PIC24F Curiosity, and XPRESS EVAL BOARD (PIC16F18855).
    #14
    MisterHemi
    Junior Member
    • Total Posts : 100
    • Reward points : 0
    • Joined: 2017/11/02 12:24:21
    • Location: 0
    • Status: offline
    Re: HOW TO: PIC32MZ USB without Harmony 2019/01/25 00:21:18 (permalink)
    0
    I'm curious if anyone has tried it yet and what feedback you have.
    Hopefully it's something usable for you.

    My configuration:
    MacBook Pro (Retina, 15-inch, Mid 2015) with MacOS High Sierra (10.13.3) and MPLAB X IDE v4.15
     
    Curiosity PIC MZ EF, PIC24F Curiosity, and XPRESS EVAL BOARD (PIC16F18855).
    #15
    MisterHemi
    Junior Member
    • Total Posts : 100
    • Reward points : 0
    • Joined: 2017/11/02 12:24:21
    • Location: 0
    • Status: offline
    Re: HOW TO: PIC32MZ USB without Harmony 2019/01/25 19:22:18 (permalink)
    0
    daveX
    That looks pretty good!
    Do you have header files for any of the rest of the MZ?




    I just realized.... I think this is what you're looking for but I don't know where they'd be located if you're using Windows or Linux:

    I was able to find some of the registers and the associated bits in the file p32mz2048efm100.h which on my MacBook Pro is located in:
    Applications/microchip/xc32/v2.15/pic32mx/lib/proc/32MZ2048EFM100/p32mz2048efm100.h


    My configuration:
    MacBook Pro (Retina, 15-inch, Mid 2015) with MacOS High Sierra (10.13.3) and MPLAB X IDE v4.15
     
    Curiosity PIC MZ EF, PIC24F Curiosity, and XPRESS EVAL BOARD (PIC16F18855).
    #16
    Timmons
    New Member
    • Total Posts : 18
    • Reward points : 0
    • Joined: 2018/02/07 01:09:23
    • Location: 0
    • Status: offline
    Re: HOW TO: PIC32MZ USB without Harmony 2019/01/28 00:25:09 (permalink)
    0
    Good Day MisterHemi
    Very good Job
    I arrange your code  to my Pic32MZEF2048EFH144
    The enumeration happen very well
     
    which kind of driver i have to associate to device?
    I tried to put microchip vendor ID e product ID, like vendor example in harmony example....
    using the same driver, but the errorcode is  "the device can not start (error code 10)"
    some suggestion about that?
     
    Thank you for your job
     
    Francesco
    #17
    MisterHemi
    Junior Member
    • Total Posts : 100
    • Reward points : 0
    • Joined: 2017/11/02 12:24:21
    • Location: 0
    • Status: offline
    Re: HOW TO: PIC32MZ USB without Harmony 2019/01/28 01:46:19 (permalink)
    0
    Timmons
    Good Day MisterHemi
    Very good Job
    I arrange your code  to my Pic32MZEF2048EFH144
    The enumeration happen very well
     
    which kind of driver i have to associate to device?
    I tried to put microchip vendor ID e product ID, like vendor example in harmony example....
    using the same driver, but the errorcode is  "the device can not start (error code 10)"
    some suggestion about that?
     
    Thank you for your job
     
    Francesco




    Let me see the descriptors in your usb.h file. The format should be the same as in the example.

    My configuration:
    MacBook Pro (Retina, 15-inch, Mid 2015) with MacOS High Sierra (10.13.3) and MPLAB X IDE v4.15
     
    Curiosity PIC MZ EF, PIC24F Curiosity, and XPRESS EVAL BOARD (PIC16F18855).
    #18
    MisterHemi
    Junior Member
    • Total Posts : 100
    • Reward points : 0
    • Joined: 2017/11/02 12:24:21
    • Location: 0
    • Status: offline
    Re: HOW TO: PIC32MZ USB without Harmony 2019/01/28 01:59:06 (permalink)
    0
    Timmons
    Good Day MisterHemi
    Very good Job
    I arrange your code  to my Pic32MZEF2048EFH144
    The enumeration happen very well
     
    which kind of driver i have to associate to device?
    I tried to put microchip vendor ID e product ID, like vendor example in harmony example....
    using the same driver, but the errorcode is  "the device can not start (error code 10)"
    some suggestion about that?
     
    Thank you for your job
     
    Francesco




    One other thought.... when you edited the descriptors did you also edit the FIRST byte(s) which are the length of the particular descriptor or descriptor string?

    For example:
     

    /*********************************************************************
    Config Descriptor
    *********************************************************************/
    unsigned char config_desc1[] = {
    /*Config Descriptor Length */ 9, /* 9 or 0x09 */
    /* DescriptorType: CONFIG */ 0x02,
    /* wTotalLength */ 0x24,0x00,
    /* bNumInterfaces */ 1,
    /* bConfigurationValue */ 2,
    /* iConfiguration */ 4, /* Index of string descriptor describing this configuration. */
    /* bmAttributes */ 0xC0, /* bit 6 set = self powered */
    /* bMaxPower */ 0 /* Value x 2mA */
    };/* NOTE: wTotalLength = Combined length of all descriptors, including this one */

    The line where the comment says "/* Config Descriptor Length */, 9", that number should be the total number of bytes in the descriptor (including the length byte) NOT just the length of the string which follows.

    My configuration:
    MacBook Pro (Retina, 15-inch, Mid 2015) with MacOS High Sierra (10.13.3) and MPLAB X IDE v4.15
     
    Curiosity PIC MZ EF, PIC24F Curiosity, and XPRESS EVAL BOARD (PIC16F18855).
    #19
    Timmons
    New Member
    • Total Posts : 18
    • Reward points : 0
    • Joined: 2018/02/07 01:09:23
    • Location: 0
    • Status: offline
    Re: HOW TO: PIC32MZ USB without Harmony 2019/01/28 03:33:58 (permalink)
    0
    Hi MisterHemi
     
    I Left all unchanged related to  your .h
    exept for Vendor and product ID
    In main.c  I replaced only your device     
    "xxxxx.h"  with mine (pic32mz2048efh144.h)
     
    Francesco
    #20
    Page: 123 > Showing page 1 of 3
    Jump to:
    © 2019 APG vNext Commercial Version 4.5