• AVR Freaks

Hot!PIC32MZ USB DMA doesn't fill buffer when doing step by step

Author
drapeauchaudiere
New Member
  • Total Posts : 1
  • Reward points : 0
  • Joined: 2017/06/28 11:51:57
  • Location: 0
  • Status: offline
2017/06/29 09:02:45 (permalink)
0

PIC32MZ USB DMA doesn't fill buffer when doing step by step

Controller : PIC32MZ2048EFH
IDE : MPLABX 3.6
Compiler XC32
Language : C

Hi ! 
I'm developing an optical powermeter that reads an ADC and sends data to a PC via High Speed USB. The USB communication works well right up until the DMA takes the DATA from the endpoint FIFO and tries to put it in the input buffer.  At this point the first command that is sent to the PIC from the PC, a test command to toggle the LEDs, works and the LEDs light up.  The second command (toggle LEDs again) is received and processed, but when the endpoint Read Callback routine is called, the input data buffer that is analyzed by software is empty.  
As I'm trying to debug this, the outcomes change.  If I go step by step for the first command in the USB ISR (where the DMA transfer is enabled), once I get to the Callback routine, the data buffer is empty, but if I let the program roll (as explained before) the buffer has the command data and the software turns on the LEDs .  Also, if I put breakpoints in the USB ISR and don't check the values of the variables the first toggle LEDs command is OK, but if I let the Variables or my Watches load, the buffer comes out empty.  

Has anyone experienced this kind of behavior while debugging DMAs or USB communication? Both the USB and DMAs use interrupt routines, which are working (they are called at the right times in the code leading to this error). Below is the function used to enable the DMA transfer, since the first command works when not in step by step, I don't think the error is here, but then again.  The way I see it it seems to be a timing error between the FIFO and the DMA .. 
 
Thank you in advance! 
 - DC
 
void _USB_DMA_Enable
(
    USB_DMA_CHANNELS channel,
    uint8_t endpoint,
    uint8_t * address,
    uint32_t count,
    bool direction
)
{
    volatile uint32_t reg;
    
    *(&USBDMA1A + (channel-1)*0x4) = ((uint32_t)(address) & 0x1fffffff);
    *(&USBDMA1N + (channel-1)*0x4) = (uint32_t)(count);
    
    reg = (uint32_t) 0x608; // BRSTM = 3, IE = 1, MODE = 0
    reg |= ((uint32_t)endpoint)<<4;
    reg |= ((uint32_t)(direction))<<1;
    
    *(&USBDMA1C + (channel-1)*0x4) = reg;
    *(&USBDMA1C + (channel-1)*0x4) |= 1; // DMA EN
}

#1

3 Replies Related Threads

    GeorgePauley
    Moderator
    • Total Posts : 1184
    • Reward points : 0
    • Joined: 2009/12/01 13:59:30
    • Location: Chandler AZ
    • Status: offline
    Re: PIC32MZ USB DMA doesn't fill buffer when doing step by step 2017/06/29 09:20:34 (permalink)
    +1 (1)
    As I recall, one cannot single-step into an interrupt service routine.  Could this be the cause of the behavior you are seeing?
    #2
    GoEk
    Senior Member
    • Total Posts : 120
    • Reward points : 0
    • Joined: 2012/09/27 00:32:28
    • Location: Sweden
    • Status: offline
    Re: PIC32MZ USB DMA doesn't fill buffer when doing step by step 2017/06/29 13:00:56 (permalink)
    +1 (1)
    drapeauchaudiere
    ...Has anyone experienced this kind of behavior while debugging DMAs or USB communication?...



    I don't know if this applies to your problem but my recent experience with making a USB Device on a PIC24F is that you cannot break the PIC with an active Host IN or OUT transaction (in my case WinUSB). WinUSB must complete the full transaction before breaking the PIC, otherwise the USB bus goes haywire and all must be reset.
    #3
    MisterHemi
    Senior Member
    • Total Posts : 178
    • Reward points : 0
    • Joined: 2017/11/02 12:24:21
    • Location: Commerce, CA USA
    • Status: offline
    Re: PIC32MZ USB DMA doesn't fill buffer when doing step by step 2019/11/11 06:49:41 (permalink)
    0
    I'm having a similar issue (see link below). Were you able to resolve the issue?
     
    https://www.microchip.com/forums/m486482.aspx

    My configuration:
    MacBook Pro (Retina, 15-inch, Mid 2015) with MacOS High Sierra (10.14.5) and MPLAB X IDE v5.20
     
    Curiosity PIC32MZ EF, PIC24F Curiosity, XPRESS EVAL BOARD (PIC16F18855), SAMA5D3 Xplained and various custom boards.
    #4
    Jump to:
    © 2019 APG vNext Commercial Version 4.5