• AVR Freaks

HID samples for dsPIC33E Demo Board

Page: 12 > Showing page 1 of 2
Author
Dale Kramer
Senior Member
  • Total Posts : 174
  • Reward points : 0
  • Joined: 2008/02/01 11:57:58
  • Location: New York
  • Status: offline
2012/12/23 22:17:39 (permalink)
0

HID samples for dsPIC33E Demo Board

Has anyone got any HID sample code to run on this board?
All the sample code I have tried doesn't get the connection past the POWERED_STATE. 
Thanks,
Dale
post edited by KiloOne - 2012/12/24 07:07:14
#1

30 Replies Related Threads

    DarioG
    Allmächtig.
    • Total Posts : 54081
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: Oesterreich
    • Status: offline
    Re:HID samples for dsPIC33E Demo Board 2012/12/24 03:11:44 (permalink)
    0
    related:
    http://www.microchip.com/forums/tm.aspx?m=695318
     
    I'm sorry, I've not used those new dsPICs yet. I'd advice the usual ones for USB, i.e. wrong Clock or hardware issues...

    GENOVA :D :D ! GODO
    #2
    Dale Kramer
    Senior Member
    • Total Posts : 174
    • Reward points : 0
    • Joined: 2008/02/01 11:57:58
    • Location: New York
    • Status: offline
    Re:HID samples for dsPIC33E Demo Board 2012/12/24 06:44:27 (permalink)
    0
    Dario,
    If I had made this board and wrote the code I would certainly suspect such issues.
    But this is Microchip hardware and their code too.
    I can find 2 undocumented projects provided in the current applications library (Microchip Solutions v2012-10-15).
    I say undocumented because they are not mentioned in the MCHPFSUSB Library Help.chm (v2.9g).  
    They are USB Device - HID - Simple Custom Demo - XC16 - dsPIC33E USB Starter Kit.mcp and USB Device - Composite - HID + MSD - XC16 - dsPIC33E USB Starter Kit.mcp
    When either of these codes are compiled and run in Debug mode, they both don't get past POWERED_STATE.   
    The only code documented to run this board was a CDC project which I have no interest in so I skipped trying that to begin with.
    I have since gone back and tried the CDC project, it also remains in POWERED_STATE.
    The only discrepancy I can find is that the CDC project contains a README file that talks about a BuildUSBArchive.bat file which may be the key to this problem.
      However, the BuildUSBArchive.bat file does not appear in the CDC project directories as the README file (Readme.txt ) suggests it should be.  
    I have found very little info on my BuildUSBArchive.bat search.  
    Apparently it is also missing from the PIC24 Starter Kit installs which also don't seem to work.
    Would the bat file be the same for both the dsPIC33E kit and the PIC24 kit? Not likely I think.  
    I am stumped at this point, any ideas?
    Thanks
    Dale

    post edited by KiloOne - 2012/12/24 07:37:45
    #3
    Dale Kramer
    Senior Member
    • Total Posts : 174
    • Reward points : 0
    • Joined: 2008/02/01 11:57:58
    • Location: New York
    • Status: offline
    Re:HID samples for dsPIC33E Demo Board 2012/12/24 07:02:14 (permalink)
    0
    All that said, and it may still be clock or hardware issues.
    As for the clock, it appears that the code sets up the 48 mhz USB needs off the main oscillator even though the board has an external 8 mhz oscillator. 
    Code they use for 48 mhz is:
     
    #if defined(__dsPIC33EP512MU810__)||defined(__PIC24EP512GU810__)

    // Configure the device PLL to obtain 60 MIPS operation. The crystal
    // frequency is 8MHz. Divide 8MHz by 2, multiply by 60 and divide by
    // 2. This results in Fosc of 120MHz. The CPU clock frequency is
    // Fcy = Fosc/2 = 60MHz. Wait for the Primary PLL to lock and then
    // configure the auxilliary PLL to provide 48MHz needed for USB
    // Operation.

    PLLFBD = 38; /* M = 60 */
    CLKDIVbits.PLLPOST = 0; /* N1 = 2 */
    CLKDIVbits.PLLPRE = 0; /* N2 = 2 */
    OSCTUN = 0;

    /* Initiate Clock Switch to Primary
    * Oscillator with PLL (NOSC= 0x3)*/

    __builtin_write_OSCCONH(0x03);
    __builtin_write_OSCCONL(0x01);

    while (OSCCONbits.COSC != 0x3);

    // Configuring the auxiliary PLL, since the primary
    // oscillator provides the source clock to the auxiliary
    // PLL, the auxiliary oscillator is disabled. Note that
    // the AUX PLL is enabled. The input 8MHz clock is divided
    // by 2, multiplied by 24 and then divided by 2. Wait till
    // the AUX PLL locks.

    ACLKCON3 = 0x24C1;
    ACLKDIV3 = 0x7;

    ACLKCON3bits.ENAPLL = 1;
    while(ACLKCON3bits.APLLCK != 1);

    #endif

    Is there a way I can probe this internal 48mhz just to make sure it is being done?
    Thanks,
    Dale
    post edited by KiloOne - 2012/12/25 08:50:28
    #4
    Dale Kramer
    Senior Member
    • Total Posts : 174
    • Reward points : 0
    • Joined: 2008/02/01 11:57:58
    • Location: New York
    • Status: offline
    Re:HID samples for dsPIC33E Demo Board 2012/12/24 07:26:10 (permalink)
    0
    And, I just noticed this file, USBStackFiles.txt .
    So I added the files and my project files now look like this:

    But when I build I get syntax errors, starting in usb_device.c  usb_device.c
    ----------------------------------------------------------------------  
    Debug build of project `F:\!---Dale\CMI Linear encoder\QEI chip\dsPIC33E starter kit INSTALL 2\Firmware\USB Device - CDC - Basic Demo - dsPIC33E USB Starter Kit.mcp' started.
    Language tool versions: pic30-as.exe v3.31, pic30-gcc.exe v3.31, pic30-ld.exe v3.31, pic30-ar.exe v3.31
    Preprocessor symbol `__DEBUG' is defined.
    Target debug platform is `__MPLAB_DEBUGGER_PK3=1'.
    Debug platform options are: `__ICD2RAM=1'.
    Mon Dec 24 09:15:48 2012
    ----------------------------------------------------------------------
    Clean: Deleting intermediary and output files.
    Clean: Deleted file "F:\!---Dale\CMI Linear encoder\QEI chip\dsPIC33E starter kit INSTALL 2\Firmware\objects\main.o".
    Clean: Done.
    Executing: "C:\Program Files\Microchip\MPLAB C30\bin\pic30-gcc.exe" -mcpu=33EP512MU810 -x c -c "main.c" -o".\objects\main.o" -I"." -I".\Microchip\include" -D__DEBUG -D__MPLAB_DEBUGGER_PK3=1 -g -Wall -DDSPIC33E_USB_STARTER_KIT
    Executing: "C:\Program Files\Microchip\MPLAB C30\bin\pic30-gcc.exe" -mcpu=33EP512MU810 -x c -c "F:\Microchip Solutions v2012-10-15\Microchip\USB\usb_hal_dspic33e.c" -o".\objects\usb_hal_dspic33e.o" -I"." -I".\Microchip\include" -D__DEBUG -D__MPLAB_DEBUGGER_PK3=1 -g -Wall -DDSPIC33E_USB_STARTER_KIT
    Executing: "C:\Program Files\Microchip\MPLAB C30\bin\pic30-gcc.exe" -mcpu=33EP512MU810 -x c -c "F:\Microchip Solutions v2012-10-15\Microchip\USB\CDC Device Driver\usb_function_cdc.c" -o".\objects\usb_function_cdc.o" -I"." -I".\Microchip\include" -D__DEBUG -D__MPLAB_DEBUGGER_PK3=1 -g -Wall -DDSPIC33E_USB_STARTER_KIT
    Executing: "C:\Program Files\Microchip\MPLAB C30\bin\pic30-gcc.exe" -mcpu=33EP512MU810 -x c -c "usb_descriptors.c" -o".\objects\usb_descriptors.o" -I"." -I".\Microchip\include" -D__DEBUG -D__MPLAB_DEBUGGER_PK3=1 -g -Wall -DDSPIC33E_USB_STARTER_KIT
    Executing: "C:\Program Files\Microchip\MPLAB C30\bin\pic30-gcc.exe" -mcpu=33EP512MU810 -x c -c "F:\Microchip Solutions v2012-10-15\Microchip\USB\usb_device.c" -o".\objects\usb_device.o" -I"." -I".\Microchip\include" -D__DEBUG -D__MPLAB_DEBUGGER_PK3=1 -g -Wall -DDSPIC33E_USB_STARTER_KIT
    F:\Microchip Solutions v2012-10-15\Microchip\USB\usb_device.c:323: error: syntax error before 'BDT_BASE_ADDR_TAG'
    F:\Microchip Solutions v2012-10-15\Microchip\USB\usb_device.c:323: warning: type defaults to 'int' in declaration of 'BDT_BASE_ADDR_TAG'
    F:\Microchip Solutions v2012-10-15\Microchip\USB\usb_device.c:323: warning: data definition has no type or storage class
    F:\Microchip Solutions v2012-10-15\Microchip\USB\usb_device.c:328: error: syntax error before 'CTRL_TRF_SETUP_ADDR_TAG'
    F:\Microchip Solutions v2012-10-15\Microchip\USB\usb_device.c:328: warning: type defaults to 'int' in declaration of 'CTRL_TRF_SETUP_ADDR_TAG'
    F:\Microchip Solutions v2012-10-15\Microchip\USB\usb_device.c:328: warning: data definition has no type or storage class
    F:\Microchip Solutions v2012-10-15\Microchip\USB\usb_device.c:329: error: syntax error before 'CTRL_TRF_DATA_ADDR_TAG'
    F:\Microchip Solutions v2012-10-15\Microchip\USB\usb_device.c:329: warning: type defaults to 'int' in declaration of 'CTRL_TRF_DATA_ADDR_TAG'
    F:\Microchip Solutions v2012-10-15\Microchip\USB\usb_device.c:329: warning: data definition has no type or storage class
    F:\Microchip Solutions v2012-10-15\Microchip\USB\usb_device.c: In function 'USBDeviceInit':
    F:\Microchip Solutions v2012-10-15\Microchip\USB\usb_device.c:486: error: 'BDT' undeclared (first use in this function)
    F:\Microchip Solutions v2012-10-15\Microchip\USB\usb_device.c:486: error: (Each undeclared identifier is reported only once
    F:\Microchip Solutions v2012-10-15\Microchip\USB\usb_device.c:486: error: for each function it appears in.)
    F:\Microchip Solutions v2012-10-15\Microchip\USB\usb_device.c:540: error: 'SetupPkt' undeclared (first use in this function)
    F:\Microchip Solutions v2012-10-15\Microchip\USB\usb_device.c: In function 'USBStallEndpoint':
    F:\Microchip Solutions v2012-10-15\Microchip\USB\usb_device.c:1256: error: 'SetupPkt' undeclared (first use in this function)
    F:\Microchip Solutions v2012-10-15\Microchip\USB\usb_device.c:1263: error: 'BDT' undeclared (first use in this function)
    F:\Microchip Solutions v2012-10-15\Microchip\USB\usb_device.c: In function 'USBCtrlEPAllowStatusStage':
    F:\Microchip Solutions v2012-10-15\Microchip\USB\usb_device.c:1615: error: 'SetupPkt' undeclared (first use in this function)
    F:\Microchip Solutions v2012-10-15\Microchip\USB\usb_device.c: In function 'USBCtrlEPAllowDataStage':
    F:\Microchip Solutions v2012-10-15\Microchip\USB\usb_device.c:1665: error: 'CtrlTrfData' undeclared (first use in this function)
    F:\Microchip Solutions v2012-10-15\Microchip\USB\usb_device.c:1672: error: 'SetupPkt' undeclared (first use in this function)
    F:\Microchip Solutions v2012-10-15\Microchip\USB\usb_device.c: In function 'USBConfigureEndpoint':
    F:\Microchip Solutions v2012-10-15\Microchip\USB\usb_device.c:1715: error: 'BDT' undeclared (first use in this function)
    F:\Microchip Solutions v2012-10-15\Microchip\USB\usb_device.c: In function 'USBCtrlEPServiceComplete':
    F:\Microchip Solutions v2012-10-15\Microchip\USB\usb_device.c:1826: error: 'SetupPkt' undeclared (first use in this function)
    F:\Microchip Solutions v2012-10-15\Microchip\USB\usb_device.c: In function 'USBCtrlTrfTxService':
    F:\Microchip Solutions v2012-10-15\Microchip\USB\usb_device.c:1971: error: 'CtrlTrfData' undeclared (first use in this function)
    F:\Microchip Solutions v2012-10-15\Microchip\USB\usb_device.c: In function 'USBCtrlTrfRxService':
    F:\Microchip Solutions v2012-10-15\Microchip\USB\usb_device.c:2039: error: 'CtrlTrfData' undeclared (first use in this function)
    F:\Microchip Solutions v2012-10-15\Microchip\USB\usb_device.c:2063: error: 'SetupPkt' undeclared (first use in this function)
    F:\Microchip Solutions v2012-10-15\Microchip\USB\usb_device.c: In function 'USBStdSetCfgHandler':
    F:\Microchip Solutions v2012-10-15\Microchip\USB\usb_device.c:2130: error: 'BDT' undeclared (first use in this function)
    F:\Microchip Solutions v2012-10-15\Microchip\USB\usb_device.c:2157: error: 'SetupPkt' undeclared (first use in this function)
    F:\Microchip Solutions v2012-10-15\Microchip\USB\usb_device.c: In function 'USBStdGetDscHandler':
    F:\Microchip Solutions v2012-10-15\Microchip\USB\usb_device.c:2196: error: 'SetupPkt' undeclared (first use in this function)
    F:\Microchip Solutions v2012-10-15\Microchip\USB\usb_device.c: In function 'USBStdGetStatusHandler':
    F:\Microchip Solutions v2012-10-15\Microchip\USB\usb_device.c:2272: error: 'CtrlTrfData' undeclared (first use in this function)
    F:\Microchip Solutions v2012-10-15\Microchip\USB\usb_device.c:2275: error: 'SetupPkt' undeclared (first use in this function)
    F:\Microchip Solutions v2012-10-15\Microchip\USB\usb_device.c: In function 'USBCtrlEPService':
    F:\Microchip Solutions v2012-10-15\Microchip\USB\usb_device.c:2526: error: 'BDT' undeclared (first use in this function)
    F:\Microchip Solutions v2012-10-15\Microchip\USB\usb_device.c:2547: error: 'SetupPkt' undeclared (first use in this function)
    F:\Microchip Solutions v2012-10-15\Microchip\USB\usb_device.c: In function 'USBCtrlTrfOutHandler':
    F:\Microchip Solutions v2012-10-15\Microchip\USB\usb_device.c:2702: error: 'SetupPkt' undeclared (first use in this function)
    F:\Microchip Solutions v2012-10-15\Microchip\USB\usb_device.c: In function 'USBCtrlTrfInHandler':
    F:\Microchip Solutions v2012-10-15\Microchip\USB\usb_device.c:2749: error: 'SetupPkt' undeclared (first use in this function)
    F:\Microchip Solutions v2012-10-15\Microchip\USB\usb_device.c:2763: error: 'CtrlTrfData' undeclared (first use in this function)
    F:\Microchip Solutions v2012-10-15\Microchip\USB\usb_device.c: In function 'USBCheckStdRequest':
    F:\Microchip Solutions v2012-10-15\Microchip\USB\usb_device.c:2828: error: 'SetupPkt' undeclared (first use in this function)
    F:\Microchip Solutions v2012-10-15\Microchip\USB\usb_device.c: In function 'USBStdFeatureReqHandler':
    F:\Microchip Solutions v2012-10-15\Microchip\USB\usb_device.c:2939: error: 'SetupPkt' undeclared (first use in this function)
    Halting build on first failure as requested.
    ----------------------------------------------------------------------
    Debug build of project `F:\!---Dale\CMI Linear encoder\QEI chip\dsPIC33E starter kit INSTALL 2\Firmware\USB Device - CDC - Basic Demo - dsPIC33E USB Starter Kit.mcp' failed.
    Language tool versions: pic30-as.exe v3.31, pic30-gcc.exe v3.31, pic30-ld.exe v3.31, pic30-ar.exe v3.31
    Preprocessor symbol `__DEBUG' is defined.
    Target debug platform is `__MPLAB_DEBUGGER_PK3=1'.
    Debug platform options are: `__ICD2RAM=1'.
    Mon Dec 24 09:16:02 2012
    ----------------------------------------------------------------------
    BUILD FAILED

    I am sure that this post is proving how much of a novice I am with all this but I am just a little frustrated right now.
    I will keep at it. 
    Dale
     
    post edited by KiloOne - 2012/12/24 07:33:41

    Attached Image(s)

    #5
    Dale Kramer
    Senior Member
    • Total Posts : 174
    • Reward points : 0
    • Joined: 2008/02/01 11:57:58
    • Location: New York
    • Status: offline
    Re:HID samples for dsPIC33E Demo Board 2012/12/24 07:48:11 (permalink)
    0
    Another clue, I used the usb_device.c from MAL version Microchip Solutions v2012-04-03 and the project compiles but still USB remains in POWERED_STATE.
    I am SURE that with all the differences in these two usb_device.c files it should not run but it is interesting that it does compile and has the same bad results when run.
    I know this was really grasping but I had to try something, I wish I was more familiar with this environment.
    Dale
    #6
    Dale Kramer
    Senior Member
    • Total Posts : 174
    • Reward points : 0
    • Joined: 2008/02/01 11:57:58
    • Location: New York
    • Status: offline
    Re:HID samples for dsPIC33E Demo Board 2012/12/24 08:36:24 (permalink)
    0
    Also, the CDC project seems to use C30 compiler while the XC16 compiler has been working for the HID Simple Custom Demo project that I have been modifying with success to have the Starter kit read a magnetic linear encoder and sending the info by UART1 thru a BC417 Bluetooth module to my VB6 project. 
    I tried XC16 with the CDC project but didn't get it compiling either.
    Why does CDC demo use C30 and HID demo use X16?  
    Dale
    post edited by KiloOne - 2012/12/24 08:42:07
    #7
    DarioG
    Allmächtig.
    • Total Posts : 54081
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: Oesterreich
    • Status: offline
    Re:HID samples for dsPIC33E Demo Board 2012/12/24 10:49:33 (permalink)
    0
    This gets "thick" Smile or "heavy" to quote Marty !
    The clock issue could still stand, yep, as you say. To check that, is never easy but you could at least check the Core clock using some tight loop and a Scope, and try to reverse-calculate USB clock from that.
     
    Hardware is supposedly ok.
     
    I was almost sure that all of the Projects in the MAL were still being provided in both "old" compiler and "new" one.. which I've not used yet.

    GENOVA :D :D ! GODO
    #8
    Dale Kramer
    Senior Member
    • Total Posts : 174
    • Reward points : 0
    • Joined: 2008/02/01 11:57:58
    • Location: New York
    • Status: offline
    Re:HID samples for dsPIC33E Demo Board 2012/12/24 11:32:28 (permalink)
    0
    So in my attempt to confirm core clock at 60 mhz I simply turned an LED on, looped for 9998 nop's, and then off LED. 
    Here is is disassembly code:
    726: mLED_3_On();
    01970 A84E34 bset.b 0x0e34,#2
    727: asm volatile ("REPEAT, #9998"); Nop();
    01972 092710 repeat #9998  
    01974 000000 nop
    728: mLED_3_Off();
    01976 A94E34 bclr.b 0x0e34,#2
     
    I then captured this on my 100mhz logic analyzer and got a 250.04 usec on pulse.
    I think that there are 4 cycles added to the 9998 loop so that is 10,002 instruction cycles.    
    Or, 0.0024999 usec per cycle or 40.00 mhz.    
    AHA, I thought the above code set the CPU clock to 60 mhz.
    Is this logic correct?
    If so, why didn't the clock setting to 60 mhz work?
    Dale
     
     

    post edited by KiloOne - 2012/12/24 11:41:40
    #9
    Dale Kramer
    Senior Member
    • Total Posts : 174
    • Reward points : 0
    • Joined: 2008/02/01 11:57:58
    • Location: New York
    • Status: offline
    Re:HID samples for dsPIC33E Demo Board 2012/12/24 11:59:29 (permalink)
    0
    From what I can decipher, PLLFBC should be 58 for a 60 x multiplier.
    I changed PLLFBC to 58 and got a 60 mhz clock going (166.69 usec pulse).
      BUT, still stuck in POWERED_STATE! (which I guess is to be expected because it is still the 8 mhz main oscillator feeding the APLL):

    Now what?
     
    post edited by KiloOne - 2012/12/24 12:44:52

    Attached Image(s)

    #10
    DarioG
    Allmächtig.
    • Total Posts : 54081
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: Oesterreich
    • Status: offline
    Re:HID samples for dsPIC33E Demo Board 2012/12/24 18:36:46 (permalink)
    0
    Unfortunately, as I said, I don't know in detail the Clocking system of that PIC - which combines the flexibility of dsPIC with a USB hardware Smile
    Even if you get proper (i.e. expected) frequency for Main Clock, can you check how is the USB clock derived from that? USB clock should be 48MHz for full-speed and 24 for low-speed...

    GENOVA :D :D ! GODO
    #11
    Dale Kramer
    Senior Member
    • Total Posts : 174
    • Reward points : 0
    • Joined: 2008/02/01 11:57:58
    • Location: New York
    • Status: offline
    Re:HID samples for dsPIC33E Demo Board 2012/12/24 18:59:16 (permalink)
    +2 (1)
    From what I can determine they set 48mhz USB clock with:
    ACLKCON3 = 0x24C1;
           This sets bit 13 SELACLK: Select Auxiliary Clock Source for Auxiliary Clock Divider bit
           to 1 = Auxiliary PLL or oscillator provides the source clock for auxiliary clock divider
           AND sets bit 10 ASRCSEL: Select Reference Clock Source for APLL bit
           to 1 = Primary Oscillator is the clock source for APLL
           AND sets bit 7-5 APLLPOST<2:0>: Select PLL VCO Output Divider bits
           to 110 = Divided by 2
           AND sets bit 2-0 APLLPRE<2:0>: PLL Phase Detector Input Divider bits
           to 001 = Divided by 2
    ACLKDIV3 = 0x7;
           This sets bit 2-0 APLLDIV<2:0>: PLL Feedback Divisor bits (PLL Multiplier Ratio)
           to 111 = 24
    I am not sure why SELACLK is set but the rest looks fine.  Basically taking the 8mhz clock, divide by APLLPRE (2), multiply by APLLDIV (24), and the divide by APLLPOST (2) to get 48 mhz.
    Wish I could probe this somehow.  Not sure about low speed, I don't use that.
     
    I have now uninstalled MAL, deleted the install directory and and then reinstalled it to make sure my files are clean.
    I have imported USB Device - HID - Simple Custom Demo - XC16 - dsPIC33E USB Starter Kit.mcp into Mplab X IDE v1.51 and was able to build and enter debug mode without any alterations in Project Properties or Project files.
     
    BOARD STILL STUCK AT POWERED_STATEpink
    Dale
     
    #12
    Dale Kramer
    Senior Member
    • Total Posts : 174
    • Reward points : 0
    • Joined: 2008/02/01 11:57:58
    • Location: New York
    • Status: offline
    Re:HID samples for dsPIC33E Demo Board 2012/12/25 09:38:09 (permalink)
    +2 (1)
    Well I confirmed that the USB clock is likely OK.
    I made a USB cable that allows me to watch the USB D+ and D- lines with my logic analyzer.
    I watched the lines on a working PIC LPC starter kit running a HID demo and then on  my dsPIC33E starter kit that was stuck in POWERED_STATE.
    They both had what appeared to be the same minimum pulse widths of 80 nanosecs.  Most of the pulses were this width. 
    Now I am back to investigating USB stack issues.
    Dale
    post edited by KiloOne - 2012/12/25 10:00:08
    #13
    Dale Kramer
    Senior Member
    • Total Posts : 174
    • Reward points : 0
    • Joined: 2008/02/01 11:57:58
    • Location: New York
    • Status: offline
    Re:HID samples for dsPIC33E Demo Board 2012/12/26 15:26:40 (permalink)
    0
    So, I believe now that USBDeviceTasks is not being called regularly (should be every 1.8msec or less).  
    In fact it is only being called once that I can determine.
    I remmed out the BlinkUSBState call so that I could use the LED's as outputs I could probe.
    I added two lines to the beginning of USBDeviceTasks to pulse LED3:
        
    #if defined(USB_INTERRUPT) 
          #if defined(__18CXX) || defined (_PIC14E)
                 void USBDeviceTasks(void)
           #elif defined(__C30__) || defined __XC16__
                 void __attribute__((interrupt,auto_psv)) _USB1Interrupt()
           #elif defined(__PIC32MX__)
                 void __attribute__((interrupt(),vector(_USB_1_VECTOR))) _USB1Interrupt( void ) 
           #endif
    #else
           void USBDeviceTasks(void)
    #endif
    {
           BYTE i;
           LATDbits.LATD2=1; //dale pules LED3 each call to this function
           LATDbits.LATD2=0;
    .
    .
    .

    When I run the program in either DEBUG or RELEASE I get only ONE LED PULSE. 
    I am not much of a C programmer but since I am using XC16 complier and USB_INTERRUPT is defined, it looks like this routine is serviced as an ISR on USB1Interrupt. 
    When I break the program I see that both that interrupt and all interrupts are enabled, the interrupt flag is cleared and the priority is 4.

    I am sure I am on the right track now but maybe someone with more experience here could give me a little guidance on how to further debug this.  
    Thanks,
    Dale
     
    post edited by KiloOne - 2012/12/26 16:00:42

    Attached Image(s)

    #14
    Dale Kramer
    Senior Member
    • Total Posts : 174
    • Reward points : 0
    • Joined: 2008/02/01 11:57:58
    • Location: New York
    • Status: offline
    Re:HID samples for dsPIC33E Demo Board 2012/12/26 18:22:57 (permalink)
    0
    So I defined USB_POLLING in usb_config.h and setup timer 1 to call USBDeviceTasks every 1.8 msec and have confirmed that it is called that often.
    Now it gets stuck at DEFAULT_STATE.
    A little progress but still no cigar.
    Dale
    #15
    DarioG
    Allmächtig.
    • Total Posts : 54081
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: Oesterreich
    • Status: offline
    Re:HID samples for dsPIC33E Demo Board 2012/12/27 05:11:55 (permalink)
    0
    Crazy.
    Sometimes there are slight changes in the way it works when switching from Interrupt to Polled mode... but the basic code works all the same in both.
    The polled mode can be "easier" to debug, it calls the USB handler (USBDeviceTasks() ) in the main loop, and it advances state properly...
     
     
    PS: make the led simply toggle in the above test, it's usually better Smile

    GENOVA :D :D ! GODO
    #16
    Dale Kramer
    Senior Member
    • Total Posts : 174
    • Reward points : 0
    • Joined: 2008/02/01 11:57:58
    • Location: New York
    • Status: offline
    Re:HID samples for dsPIC33E Demo Board 2012/12/27 06:27:38 (permalink)
    0
    Dario,
    I had relied on the polling call to USBDeviceTasks() in the main loop with no processIO calls when I first switched to polling and USBDeviceTasks() was called every 5 mircoseconds (should be often enough Smile ).
    But then I discovered that there was 50 msec at start of program that USBDeviceTasks was not called.
    That is why I also called it every 1.8 mseec with TMR1, just to be sure.
    I didn't know I would have to become so well versed in USB enumeration just to get a starter kit doing what it is supposed to do out of the box but I guess life is all about learning.
    Thanks,
    Dale
    #17
    DarioG
    Allmächtig.
    • Total Posts : 54081
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: Oesterreich
    • Status: offline
    Re:HID samples for dsPIC33E Demo Board 2012/12/27 09:02:04 (permalink)
    0
    Smile yeah, indeed!
     
    Strange because "usually" Microchip Code does work as is, even in the enumeration (critical) stage. I used it on "normal" PIC24 and PIC18, extensively.

    GENOVA :D :D ! GODO
    #18
    Dale Kramer
    Senior Member
    • Total Posts : 174
    • Reward points : 0
    • Joined: 2008/02/01 11:57:58
    • Location: New York
    • Status: offline
    Re:HID samples for dsPIC33E Demo Board 2012/12/27 10:43:33 (permalink)
    0
    So, to get past DEFAULT_STATE it appears to me that a completed USB transaction has to occur.
    Then, under the right conditions it will progress to ADDRESS_STATE and then, the holy grail, CONFIGURED_STATE.
    In my stuck state of DEFAULT_STATE, a USB transaction doesn't seem to happen, here is the code that is of interest:

    if(USBTransactionCompleteIE)
    {
          for(i = 0; i < 4u; i++) //Drain or deplete the USAT FIFO entries. If the USB FIFO ever gets full, USB bandwidth 
          { //utilization can be compromised, and the device won't be able to receive SETUP packets.
              if(USBTransactionCompleteIF)
              {
                  //Save and extract USTAT register info. Will use this info later.
                  USTATcopy.Val = U1STAT;
                  endpoint_number = USBHALGetLastEndpoint(USTATcopy);

                  USBClearInterruptFlag(USBTransactionCompleteIFReg,USBTransactionCompleteIFBitNum);

                  //Keep track of the hardware ping pong state for endpoints other
                  //than EP0, if ping pong buffering is enabled.
                  #if (USB_PING_PONG_MODE == USB_PING_PONG__ALL_BUT_EP0) || (USB_PING_PONG_MODE == USB_PING_PONG__FULL_PING_PONG) 
                  if(USBHALGetLastDirection(USTATcopy) == OUT_FROM_HOST)
                  {
                      ep_data_out[endpoint_number].bits.ping_pong_state ^= 1;
                  }  
                  else
                  {
                      ep_data_in[endpoint_number].bits.ping_pong_state ^= 1;
                  }  
              #endif  

              //USBCtrlEPService only services transactions over EP0.
              //It ignores all other EP transactions.
              if(endpoint_number == 0)
              {
                  USBCtrlEPService();
              }
              else
              {
                  USB_TRANSFER_COMPLETE_HANDLER(EVENT_TRANSFER, (BYTE*)&USTATcopy.Val, 0);
              }
          }//end if(USBTransactionCompleteIF)
          else
              break; //USTAT FIFO must be empty.
        }//end for()
     }//end if(USBTransactionCompleteIE)

    The if(USBTransactionCompleteIE) is entered.
    But if(USBTransactionCompleteIF) is never entered.
    I thought this had to do with the weird way USB interrupts are handled but probably not.
    So, with no USB transaction, does that mean that whatever is on the other end of my USB cable is playing dumb?
    I am able to enumerate the LPC USB starter kit on the same cable and USB port.
    Hope this triggers a lightbulb in someones head out there.
    Thanks,
    Dale
     
     

    #19
    Dale Kramer
    Senior Member
    • Total Posts : 174
    • Reward points : 0
    • Joined: 2008/02/01 11:57:58
    • Location: New York
    • Status: offline
    Re:HID samples for dsPIC33E Demo Board 2012/12/27 13:06:51 (permalink)
    0
    Other info to ponder.
    Here are all the USB registers and some relevant variables at a breakpoint on if(USBTransactionCompleteIF) when the program is run from reset condition:

    So far, my research on these registers show all should be in order.
    I'm looking for that light bulb idea from you guys.
    Thanks,
    Dale

    Attached Image(s)

    #20
    Page: 12 > Showing page 1 of 2
    Jump to:
    © 2019 APG vNext Commercial Version 4.5