• AVR Freaks

PIC18F27J53 and USB

Author
sirloon
New Member
  • Total Posts : 19
  • Reward points : 0
  • Joined: 2011/03/30 05:23:29
  • Location: 0
  • Status: offline
2011/03/30 05:55:25 (permalink)
0

PIC18F27J53 and USB

Hi guys,

I'm new to Microchip forums though I've been using PIC micros for several years, dvelopment environment involving open source jalv2 related projects.

I'm trying to play with PIC18F27J53, specifically USB. I've been able to blink-a-led and use USART peripheral. I'm using a prototyping PCB I've designed, with several mistakes I've been able to fix in order to perform this tests. Currently, schematic looks like attached picture.

Specifically, regarding USB, there are:
  - Vusb connected to +3V3, and GND through a 100nF (tested also 220nF) cap
  - 1uF from Vbus to GND
  - D+/D- traces are short on PCB, less than 1cm

and 10uF Vddcore cap and several decoupling caps as well.

Hex I'm using is created using jalv2 and jallib USB libraries, and should expose a CDC usb device on host. A very quite similar code, running with 18F4550, was successfully tested.

As results:

  - under Linux, plugging the board gives the following traces in syslog:
Mar 27 15:39:50 pixie kernel: [1042979.536099] usb 2-2: new full speed USB device using uhci_hcd and address 110
Mar 27 15:39:50 pixie kernel: [1042979.656092] usb 2-2: device descriptor read/64, error -71
Mar 27 15:39:50 pixie kernel: [1042979.880294] usb 2-2: device descriptor read/64, error -71
Mar 27 15:39:50 pixie kernel: [1042980.096148] usb 2-2: new full speed USB device using uhci_hcd and address 111
Mar 27 15:39:50 pixie kernel: [1042980.216152] usb 2-2: device descriptor read/64, error -71
Mar 27 15:39:50 pixie kernel: [1042980.441146] usb 2-2: device descriptor read/64, error -71
Mar 27 15:39:51 pixie kernel: [1042980.656175] usb 2-2: new full speed USB device using uhci_hcd and address 112
Mar 27 15:39:51 pixie kernel: [1042981.064134] usb 2-2: device not accepting address 112, error -71
Mar 27 15:39:51 pixie kernel: [1042981.176084] usb 2-2: new full speed USB device using uhci_hcd and address 113
Mar 27 15:39:52 pixie kernel: [1042981.584131] usb 2-2: device not accepting address 113, error -71
Mar 27 15:39:52 pixie kernel: [1042981.584179] hub 2-0:1.0: unable to enumerate USB device on port 2


 - under Windows, it says something has been plugged, configure it, but then claims there's a problem and no driver could be found (I need to dig this further)

Error -71 is often referred as an hardware problem, but I can't see what's wrong. In other words, I'm not sure if it's a hardware or software issue. I tried to sniff USB packets with usbmon and vusb analyzer, but it is very cryptic to me :)

Do you see something obvious (or less obvious) in my schematic that would troubles ? Are you aware of such errors ? How would you debug this ?

Thanks for your help !

Cheers,
Seb

Attached Image(s)

#1

11 Replies Related Threads

    newfound
    Super Member
    • Total Posts : 1827
    • Reward points : 0
    • Joined: 2003/11/07 12:35:49
    • Status: offline
    Re:PIC18F27J53 and USB 2011/03/30 06:58:51 (permalink)
    0

    The JAL USB stack is not aware of the PIC18FxxJ53 parts. The buffer descriptor table is located at 0xd00. Jal only supports PICs that have the buffer descriptor @ either 0x200 or 0x400.

    From usb_defs.jal:

    -- Set the base address of the USB dual port memory location
    if (     (target_chip == PIC_18F14K50 ) |
            (target_chip == PIC_18F13K50 ) |
            (target_chip == PIC_18LF14K50 ) |
            (target_chip == PIC_18LF13K50 ) )then
            const USB_BASE_ADDRESS = 0x0200
    else
            const USB_BASE_ADDRESS = 0x0400
    end if


    You can edit this code in usb_defs.jal to include the 18F26J53, 18F27J53, 18F46J53, 18F47J53 parts and this will advance your cause somewhat.

    These may not be the only changes required. I had never heard of JALv2 and had no idea that there was such a usb stack until your post. Therefore I have not parsed through it to know what else lurks. There are some other differences with the xxJ53 parts. Some of the USB SPRs are/may not in the same location or in the ACCESS BANK. Whether or not JALv2 handles these correctly I cannot say.

    Still, you know now that you may have to look for them and if you find anything then I'm sure that the JAL community would be very interested to hear of what you find, as I would be too.

    post edited by newfound - 2011/03/30 07:09:46
    #2
    sirloon
    New Member
    • Total Posts : 19
    • Reward points : 0
    • Joined: 2011/03/30 05:23:29
    • Location: 0
    • Status: offline
    Re:PIC18F27J53 and USB 2011/03/31 03:31:50 (permalink)
    0

    Thanks for your reply !


    newfound
     The JAL USB stack is not aware of the PIC18FxxJ53 parts. The buffer descriptor table is located at 0xd00. Jal only supports PICs that have the buffer descriptor @ either 0x200 or 0x400. 
     


    I've updated usb_defs.jal to adjust base address for this PIC. And indeed, it seems there's progress ! Error is this time different:


    Mar 31 11:58:14 debian kernel: [3982393.602633] usb 4-1: new full speed USB device using uhci_hcd and address 36
    Mar 31 11:58:14 debian kernel: [3982393.769201] usb 4-1: device descriptor read/64, error 8
    Mar 31 11:58:14 debian kernel: [3982394.205348] usb 4-1: device descriptor read/64, error 8
    Mar 31 11:58:15 debian kernel: [3982394.992006] usb 4-1: new full speed USB device using uhci_hcd and address 37
    Mar 31 11:58:15 debian kernel: [3982395.180117] usb 4-1: device descriptor read/64, error 8
    Mar 31 11:58:15 debian kernel: [3982395.447772] usb 4-1: device descriptor read/64, error 8
    Mar 31 11:58:15 debian kernel: [3982396.190363] usb 4-1: new full speed USB device using uhci_hcd and address 38
    Mar 31 11:58:15 debian kernel: [3982396.260225] usb 4-1: device descriptor read/8, error -71
    Mar 31 11:58:15 debian kernel: [3982396.442930] usb 4-1: device descriptor read/8, error -71
    Mar 31 11:58:16 debian kernel: [3982397.147234] usb 4-1: new full speed USB device using uhci_hcd and address 39
    Mar 31 11:58:16 debian kernel: [3982397.199236] usb 4-1: device descriptor read/8, error -71
    Mar 31 11:58:16 debian kernel: [3982397.939349] usb 4-1: device descriptor read/8, error -71
    Mar 31 11:58:16 debian kernel: [3982398.115117] hub 4-0:1.0: unable to enumerate USB device on port 1


    Host seems to try to configure USB device, using both modes (read/64 then read/8, I can't remember what the correct terms for these modes)


    newfound 
    These may not be the only changes required. I had never heard of JALv2 and had no idea that there was such a usb stack until your post.


    I think we're refering to the same JAL compiler version (previous version was jal 0.x) . I'm not aware of USB stack on old version, USB stack has been added (Albert Faber's huge contribution) to jalv2 and jallib projects. Lastest stable version of jal (v2) is 2.4n: http://casadeyork.com/jalv2/

    newfound 
    There are some other differences with the xxJ53 parts. Some of the USB SPRs are/may not in the same location or in the ACCESS BANK. Whether or not JALv2 handles these correctly I cannot say. 



    So as you mention current USB stack doesn't support this PIC, but it seems at least it's not a hardware problem. I need to dig into USB stack though I would have preferred to stay away :) Thanks for these hints.


    newfound 
    Still, you know now that you may have to look for them and if you find anything then I'm sure that the JAL community would be very interested to hear of what you find, as I would be too.
     


    I'll sure report this and see how I can include these changes in jallib repository.



    Cheers,
    Seb



    #3
    sirloon
    New Member
    • Total Posts : 19
    • Reward points : 0
    • Joined: 2011/03/30 05:23:29
    • Location: 0
    • Status: offline
    Re:PIC18F27J53 and USB 2011/03/31 07:17:04 (permalink)
    0
    OK, I think I'm starting to better understand why it's not working... As you said, BDT starts at 0x400 for 18F4550, and 0xD00 for 18F27J53. For 18F4550, BDT is at the beginning of USB RAM, following banks being used for USB data (buffer descriptors and buffer themselves are contiguous). Current USB stack implementation (in JAL) make an assumption about this memory structure, where buffer are described as: 

      - starting memory (ie. BDT) + offset
    On the contrary, 18F27J53 has some sort of opposed memory structure: USB data can be used from 0x00 to 0xEBF (bank 0 to 14), but 0xD00 to 0xDFF (bank 13) is used for BDT. Not fully contiguous anymore, as only the last bank is. If buffers can't fit that space, troubles are expected...


    Does this make sense anyway ?

    TIA
    Seb
    #4
    newfound
    Super Member
    • Total Posts : 1827
    • Reward points : 0
    • Joined: 2003/11/07 12:35:49
    • Status: offline
    Re:PIC18F27J53 and USB 2011/03/31 07:43:57 (permalink)
    0
    Yeah, I downloaded the JAL USB stack and had a cursory look through it and that is how I found the buffer descriptor address error. In reality all of the other device differences should be taken care of via the header files.

    Now I have had a bit more of a look and it appear that the header file does take care of the different USB SPR addresses so that is good news.

    Make sure you are enabling the PLL and wait >= 2ms for it to lock. Also check that no other part of your code is using the page @ 0xd00 for anything else.

    Other than that I cannot really see anything else that is obviously wrong. 
    #5
    newfound
    Super Member
    • Total Posts : 1827
    • Reward points : 0
    • Joined: 2003/11/07 12:35:49
    • Status: offline
    Re:PIC18F27J53 and USB 2011/03/31 07:45:50 (permalink)
    0
    Oh, I missed you new post. I will have a look. I am not sure. Stay tuned.
    #6
    newfound
    Super Member
    • Total Posts : 1827
    • Reward points : 0
    • Joined: 2003/11/07 12:35:49
    • Status: offline
    Re:PIC18F27J53 and USB 2011/03/31 07:52:06 (permalink)
    0
    sirloon

    On the contrary, 18F27J53 has some sort of opposed memory structure: USB data can be used from 0x00 to 0xEBF (bank 0 to 14), but 0xD00 to 0xDFF (bank 13) is used for BDT. Not fully contiguous anymore, as only the last bank is. If buffers can't fit that space, troubles are expected...


    Does this make sense anyway ?

    TIA
    Seb


    No, just confirmed with the data sheet and the space behind the BDT can be used as usb ram the same as any other PIC18 USB part. You can try moving the USB ram somewhere else perchance there is a memory conflict but failing that the existing system should work just fine.
    #7
    sirloon
    New Member
    • Total Posts : 19
    • Reward points : 0
    • Joined: 2011/03/30 05:23:29
    • Location: 0
    • Status: offline
    Re:PIC18F27J53 and USB 2011/04/01 22:39:18 (permalink)
    0
    Hi, 

    Finally got it working ! Except usb memory base address, existing system works fine, I had troubles with an old beta compiler. At least I know a litlle more about USB...

    We @jallib will see how to upgrade USB stack to include this change, and possibly make the more generic to handle more USB PIC.

    Thanks for your support !

    Cheers,
    Seb
    #8
    newfound
    Super Member
    • Total Posts : 1827
    • Reward points : 0
    • Joined: 2003/11/07 12:35:49
    • Status: offline
    Re:PIC18F27J53 and USB 2011/04/02 02:32:21 (permalink)
    0
    Hey, that is great news! Thanks for the update.

    I have some code that pretty much maps out all the differences in the PIC18 USB pics. (There is not much really.)

    Let me know if that might be helpful and I will send it to you.
    #9
    sirloon
    New Member
    • Total Posts : 19
    • Reward points : 0
    • Joined: 2011/03/30 05:23:29
    • Location: 0
    • Status: offline
    Re:PIC18F27J53 and USB 2011/04/02 09:44:13 (permalink)
    0
    That may be very useful, please share ! Ideally this specific information should be extracted from header file (inc) but to make it more generic and handle future PIC  but I can't see anything. Rob Hamerling, our jalv2 device files (aka header files) guru is having a look about this, but your code (and the way you produced it: manual datasheet reading ? specific source of information ?) surely will help

    Thanks
    Seb

    #10
    newfound
    Super Member
    • Total Posts : 1827
    • Reward points : 0
    • Joined: 2003/11/07 12:35:49
    • Status: offline
    Re:PIC18F27J53 and USB 2011/04/02 10:32:00 (permalink)
    0
    Actually, I had a look at the header files for JALv2 and my stuff and I realized there is almost nothing more to add. It is already there mostly in the existing header files and the stuff I have put together is mostly related not to USB itself rather other things that the open source USB stack I worked on needed and a lot of that was for the PIC24.

    The only thing that I have that may save a little time is a  complete PIC18F USB list that defines the buffer descriptor locations.

    if (target_chip ==PIC_18F2450) | (target_chip == PIC_18F2455) |
    (target_chip == PIC_18F2458) | (target_chip == PIC_18F2550) |
    (target_chip == PIC_18F2553)| (target_chip == PIC_18F4450) |
    (target_chip == PIC_18F4455) | (target_chip == PIC_18F4458) |
    (target_chip == PIC_18F4550) | (target_chip == PIC_18F4553) then
    const  USB_BASE_ADDRESS = 0x400
    end if

    if (target_chip == PIC_18F13K50) | (target_chip == PIC_18F14K50) then
    const  USB_BASE_ADDRESS = 0x200
    end if

    if (target_chip == PIC_18F24J50) | (target_chip == PIC_18F25J50) |
    (target_chip == PIC_18F26J50) |  (target_chip == PIC_18F44J50) |
    (target_chip == PIC_18F45J50) | (target_chip == PIC_18F46J50) then
    const  USB_BASE_ADDRESS = 0x400
    //#define PLLEN_REQD
    end if

    if (target_chip == PIC_18F26J53) | (target_chip == PIC_18F27J53) |
    (target_chip == PIC_18F46J53)  | (target_chip == PIC_18F47J53) then
    const  USB_BASE_ADDRESS = 0xd00
    //#define PLLEN_REQD
    end if

    if (target_chip == PIC_18F65J50) | (target_chip == PIC_18F66J50) |
    (target_chip == PIC_18F66J55) | (target_chip == PIC_18F67J50) |
    (target_chip == PIC_18F85J50) | (target_chip == PIC_18F86J50) |
    (target_chip == PIC_18F66J55) | (target_chip == PIC_18F67J50) then
    const  USB_BASE_ADDRESS = 0x400
    //#define PLLEN_REQD
    //#define USE_ALT_ANCON
    end if

    Note that there is some logic to the groupings as there tends to be one or two non USB related features that can be included for each generic family.  I left some examples commented out.

    This might save an hour to two's work and it gives the full list of all PIC18 USB parts.
    #11
    sirloon
    New Member
    • Total Posts : 19
    • Reward points : 0
    • Joined: 2011/03/30 05:23:29
    • Location: 0
    • Status: offline
    Re:PIC18F27J53 and USB 2011/04/03 01:54:01 (permalink)
    0
    Hi,

    FWIW progress about this issue can be followed here: http://code.google.com/p/jallib/issues/detail?id=154
    Main thread on jallib mailing list: http://groups.google.com/...hread/e637e8c84ef50248

    Next step for me is to make PDFUSB bootloader works with 18F27J53.

    Cheers,
    Seb
    #12
    Jump to:
    © 2019 APG vNext Commercial Version 4.5