• AVR Freaks

PIC32MZ USB

Author
akashh
New Member
  • Total Posts : 12
  • Reward points : 0
  • Joined: 2013/09/07 03:56:13
  • Location: 0
  • Status: offline
2017/03/14 03:37:54 (permalink)
0

PIC32MZ USB

Hi guys,

I've been working hard on adapting the harmony USB framework on the PIC32MZ2048EFH064 to support my firmware that runs on the MX.  Everything else works fine, and the usb stack is pretty much implemented but I wanted to see if anyone here who works with the MZ has any tips on how I can solve the following:
I have the USB stack running in host mode, and I have a CDC device (USB dongle) that I set up after I make it modeswitch from an MSD device.  Everything works fine, it enumerates, the PPP stack works and I can even connect to the internet and reach the device remotely.  However, the CDC stack freezes when I send a Read_CDC command.  I have to manually after a fixed timeout interval call _DRV_USBHS_HOST_NonControlTransferProcess to simulate an interrupt to get it out of that state.  Now according to the docs the USB has a NIKLIMIT field that should be set to the number of NAKs before triggering an interrupt, this was set to 0.  Even manually setting it to a value does not seem to make it work.
The throughput is affected by this, because every time I request data from the dongle and none is available I have to wait till the timeout triggers before sending another request.
Does anyone else have any issues with this?
The system is running under FreeRTOS - I also noticed that the DMA interrrupt never triggers so I have disabled using DMA with the USB.
I read somewhere that someone said the SYSCLK needed to be 48 MHz but that does not seem logical - it's at 200MHz now.  External oscillator at 12.0 MHz
Any help would be appreciated!
Akash
#1

15 Replies Related Threads

    NKurzman
    A Guy on the Net
    • Total Posts : 18038
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re: PIC32MZ USB 2017/03/14 09:06:44 (permalink)
    3 (1)
    What version of Harmony?

    If you look at the internal clock layout of the pic in MHC you will see the the USB subsystem gets 48 mhz.
    I am using USB host with versions up to V1.10 , no RTOS, USB thumb drives only, and have seen no issues.
    #2
    chipster
    New Member
    • Total Posts : 12
    • Reward points : 0
    • Joined: 2017/03/07 14:27:30
    • Location: 0
    • Status: offline
    Re: PIC32MZ USB 2017/03/14 13:01:29 (permalink)
    0
    I see that you both have some experience working with USB on the PIC32 family. I was hoping you could answer some beginner questions for me.
     
    I would like to use a PIC32MZ2048EFM100 board as a high speed data acquisition unit and send back data to a PC for display.
     
    Since I need to be able to sample the data at a predictable rate I need the USB peripheral to run independently in the background.
     
     
    a) In other words  would it be able to  send and receive data without interrupting a data sampling cycle.
     
    b) If I was doing this with the CDC device driver what would be the maximum speed I could send data to the PC?
     
    Any help would be greatly appreciatedSmile: Smile
     
     
     
     
    #3
    CinziaG
    die fucking humans
    • Total Posts : 3145
    • Reward points : 0
    • Joined: 2016/12/07 14:20:36
    • Location: Wien
    • Status: online
    Re: PIC32MZ USB 2017/03/14 13:04:48 (permalink)
    0
    chipster
     
    b) If I was doing this with the CDC device driver what would be the maximum speed I could send data to the PC?
     
     



    I would say 1MB/sec but would like to have confirmation for this PIC...

    in 2018 you signed for your annihilation. in 2019 it will come ;) I promise
    my most wonderful creations here
    https://www.youtube.com/c...dPFRvtwsbSTXp6Sk6azGOQ
    #4
    NKurzman
    A Guy on the Net
    • Total Posts : 18038
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re: PIC32MZ USB 2017/03/14 14:20:33 (permalink)
    0
    You want it to be a USB slave.
    What kind?
    What is you definition of high speed.
    What do you consider the background? It requires the CPU to work so it will take CPU time.
    #5
    chipster
    New Member
    • Total Posts : 12
    • Reward points : 0
    • Joined: 2017/03/07 14:27:30
    • Location: 0
    • Status: offline
    Re: PIC32MZ USB 2017/03/14 15:12:57 (permalink)
    0
    I am not very knowledgeable about the USB module and protocol - which kind of leads to my question. When I look at the USB data sheet I see mention of DMA and FIFO.
     
    I am assuming that the direct memory access is to sram in the CPU chip?
     
    My thought is that is that if my application is putting data into sram while doing the data acquisition the USB module can be fetching data and sending it out when ever my application is not writing to memory.
     
    I am new to PIC32 and USB so I am not sure if this is possible, however Microchip has produced several "independent" periopherals so I hoped it might be?
    #6
    chipster
    New Member
    • Total Posts : 12
    • Reward points : 0
    • Joined: 2017/03/07 14:27:30
    • Location: 0
    • Status: offline
    Re: PIC32MZ USB 2017/03/14 15:17:14 (permalink)
    3 (1)
    I am assuming that my board will act as a device as opposed to a host. 
     
    The simplest programming on the PC end would be if the board looks like a virtual com port. I would like to do sampling of digital signals at 50 MHZ and sampling of analog signals at 20 MHZ.
     
    #7
    NKurzman
    A Guy on the Net
    • Total Posts : 18038
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re: PIC32MZ USB 2017/03/14 15:42:20 (permalink)
    0
    It is not an independent peripheral. It requires a stack.
    You have a core running a 125mhz. I doublet you can collect data that fast for very long. I assume you want it continuous.
    I am not sure is the A2D samples that fast.

    I am not sure it is possible with a PIC32MZ.
    It may not be the tool for the job. See if others have any more helpful comments.
    #8
    NorthGuy
    Super Member
    • Total Posts : 5806
    • Reward points : 0
    • Joined: 2014/02/23 14:23:23
    • Location: Northern Canada
    • Status: offline
    Re: PIC32MZ USB 2017/03/14 15:53:26 (permalink)
    4 (2)
    chipster
    I would like to do sampling of digital signals at 50 MHZ and sampling of analog signals at 20 MHZ.



    I think either of these is too fast. ADC is 3MS/s. I don't think there are any means to sample digital at 50MHz. IC can probably go to 30MHz, but DMA may not be able to keep up with this.
    #9
    chipster
    New Member
    • Total Posts : 12
    • Reward points : 0
    • Joined: 2017/03/07 14:27:30
    • Location: 0
    • Status: offline
    Re: PIC32MZ USB 2017/03/14 21:51:55 (permalink)
    3 (1)
    I am referring to this chip found on the PIC32MZ curiousity board
    http://www.microchip.com/wwwproducts/en/PIC32MZ2048EFM100
     
    It seems like the A/D yields 18 Ms/s not quite 20 but I could live with it.
     
    The CPU runs at 200 MHz. Wouldn't I be able to read the pins at 50 Mhz?
     
    North Guy are you in agreement that the USB cannot run independently?
     
    Ideally I would like to stream Data to the PC via USB while it is being collected. If this is not possible I could store it in sram and send it after a collection cycle.
     
    However I don't think I can do this if the USB stack is constantly using CPU cycles.
     
    Excuse my lack of knowledge about the chip and the USB but it is a huge learning curve and I don't want to climb it if the chip has no possibility of doing it.
     
    #10
    NKurzman
    A Guy on the Net
    • Total Posts : 18038
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re: PIC32MZ USB 2017/03/14 22:21:57 (permalink)
    4.5 (2)
    The chip can run up to 250mhz.
    The bus half that. Bus that leaves you 5 opcode to read and store each instruction. You maybe able to do that is a burst, in Assembly. And assuming you are doing nothing else on the internal bus.
    A/d can run automatically via DMA but you would again need to minimize the internal bus use to assure the samples stay even in time. And you would need to unload the data after each save.

    If you are trying to make a scope or something like that you may need FPGAs to achieve what you want. Or a several GHz ARM.
    This does not appear to be a beginner project. It may not be possible, and if it is you will need to make the CPU dance to do it.
    #11
    akashh
    New Member
    • Total Posts : 12
    • Reward points : 0
    • Joined: 2013/09/07 03:56:13
    • Location: 0
    • Status: offline
    Re: PIC32MZ USB 2017/03/15 01:26:55 (permalink)
    0
    I am using harmony 1.07. 
    Not really sure where to look further.  Has anyone debugged the harmony stack to figure out whether DMA on USB works and also whether the NAK timeouts actually get properly triggered?
    #12
    NorthGuy
    Super Member
    • Total Posts : 5806
    • Reward points : 0
    • Joined: 2014/02/23 14:23:23
    • Location: Northern Canada
    • Status: offline
    Re: PIC32MZ USB 2017/03/15 08:30:55 (permalink)
    3 (1)
    chipster
    It seems like the A/D yields 18 Ms/s not quite 20 but I could live with it.

     
    Have you read the ADC docs? 18Ms/s is for 6 channels each running at 3Ms/s.
     
    chipster
    The CPU runs at 200 MHz. Wouldn't I be able to read the pins at 50 Mhz?

     
    CPU certainly cannot read a bit from a pin, store it somewhere and loop back in 4 cycles (assuming 200MHz clock). I think your best bet is some sort of periphery, such as IC.
     
    chipster
    North Guy are you in agreement that the USB cannot run independently?

     
    You may be able to come up with some sort of independent solution sending from pre-defined buffer, but not with stock Microchip code. The USB module is not documented beyond simple register descriptions, so this will take some effort, and then there's no guarantee. Besides, CPU is most likely using the same bus, so even when independent, it has a capability to bog down other operations.
     
    #13
    chipster
    New Member
    • Total Posts : 12
    • Reward points : 0
    • Joined: 2017/03/07 14:27:30
    • Location: 0
    • Status: offline
    Re: PIC32MZ USB 2017/03/16 17:40:44 (permalink)
    0
    Thanks for the heads up on the ADC Northguy. I read the bit about the 18ms/s on the first page of the "condensed" 600 or 700 page data sheet. I think it mentions the 3 X 6 = 18 ms/s somewhere around 500 pages in under electrical characteristics.
     
    I am presently trying to make sense of what "200 Mhz" means in the light of all the forum posts of people not being able to make pins toggle 20 Mhz. I am trying to come to grips with peripheral bus speed and caching etc.
     
    I am also reevaluating the specs for my project and whether I want to use this chip.
     
    Thanks again for your insights. I think I need to take good hard look at this board to see if I want to invest the time into it 
    #14
    timijk
    Super Member
    • Total Posts : 1216
    • Reward points : 0
    • Joined: 2007/11/26 00:30:07
    • Location: Taiwan
    • Status: offline
    Re: PIC32MZ USB 2017/03/16 17:43:03 (permalink)
    0
    You may try SPI, it can go up to 50MHz.
    #15
    NKurzman
    A Guy on the Net
    • Total Posts : 18038
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re: PIC32MZ USB 2017/03/16 18:24:22 (permalink)
    3 (1)
    The core runs at 200Mhz ( actually there is a 250MHZ Version).
    It executes 1 instruction per cycle.
    The I/O Bus runs at half that.
    Look at the internal structure in the Data sheet Figure 1-1  Notice everything goes though the system bus.
    so at 50 Mhz you can only execute 5 opcodes.  Not 5 lines of C code , just 5 instructions. So in your 5mhz rush , any interrupts will pause your collection or DMA will steal Bus cycles.
     
     
    move word from port to Acc
    Move from Acc to RAM indirect
    inc pointer.
    loop
    it is 100% CPU, if it is even possible.
     
    Your 20Mhz analog can't happen your top would be 6Mhz on a single channel, that assumes you would DMA buffer then send.
     
    You are going to need a Faster CPU, and a Flash conversion A/D.  And possibly an FPGA to tie it all together.
     
    #16
    Jump to:
    © 2019 APG vNext Commercial Version 4.5