• AVR Freaks

USB Device not Recognized... After defining large array

Author
RadioActiveEd
New Member
  • Total Posts : 6
  • Reward points : 0
  • Joined: 2010/05/25 07:32:33
  • Location: 0
  • Status: offline
2010/07/19 11:50:44 (permalink)
0

USB Device not Recognized... After defining large array

I originally went to tech support with this issue, waited over a month only for them to ask if I still needed assistance, and then close my ticket!  So it goes, I guess...  I know those guys are busy.
 
 
I am using the PIC32 USB Starter Kit II (USB)
 
When compiling the sample application WINUSB High Bandwidth Demo, everything works perfectly. Everything compiles, the USB device is detected when running the code in debug mode etc...
 
When I add this line of code, creating a large data array...same thing, everything runs fine.
char IMAGEDATA[63500];
then I change that line to be
char IMAGEDATA[64000];
 
My usb device is no longer recognized. There is plenty of RAM left over, as it's a 128K device. The code compiles just fine. I do not get errors, like section fit errors etc,. I can even initialize the data in RAM without issue, verified in the MEMORY list.
Somewhere between 63500 and 64000 elements in the array something happens.
 
I did this on my modified code (and went back to the unchanged original example to make sure I didn't do anything else incorrectly). On the modified version these numbers are different, say around 64075 where the issue happens, so there is a limit somewhere I am hitting, but it is not 65535 or 65536 (16 bit).
 
I even broke the 64000 up into two arrays of 32000 and get the same results. Once I allocate so much in a single, or multiple arrays, it fails to detect my device.
More notes FYI:
On my modified code, the RAM usage was 66600 when it was working fine. I added ONE element to the array and the RAM usage went to 67112 and failed... only changing that by 1 byte, on the threshold of failure.
 
I would like to be able to use the max ram on this chip, but can't figure it out. I examined the memory MAP and associated register to change sizes of Kernal/User/Program etc, but didn't change any of those thinking that was not the issue. I am on day 46 and have nothing to show for my efforts!
 
This could just be a coding issue, on my part.  However, seeing that I can initialize the data, and only the USB part fails, I think this may be an issue with the USB stack, or something funny with the way this demo is written.  Thoughts?
Thanks for your help!
#1

3 Replies Related Threads

    chinzei
    Super Member
    • Total Posts : 2250
    • Reward points : 0
    • Joined: 2003/11/07 12:39:02
    • Location: Tokyo, Japan
    • Status: offline
    Re:USB Device not Recognized... After defining large array 2010/07/26 03:49:39 (permalink)
    0
    Your problem was reproduced on Explorer16 + PIC32MX795F512L PIM, too.
    It was revealed a bug on usb_hal_pic32.h

    When the array size is 63500, BDT is located on 0xA000FE00 (physical: 0x0000FE00) on the map.
    char IMAGEDATA[63500];
     *(COMMON) 
     COMMON         0xa0000200     0xf98c Objects\USB Device - WinUSB - High Bandwidth - C32\main.o
                    0xa0000200                IMAGEDATA
                    0xa000fa0c                EP2OUTOddBuffer
                    0xa000fa4c                EP2OUTEvenBuffer
                    0xa000fa8c                EP3OUTOddBuffer
                    0xa000facc                EP1OUTEvenBuffer
                    0xa000fb0c                EP3OUTEvenBuffer
                    0xa000fb4c                EP1OUTOddBuffer
     *fill*         0xa000fb8c       0x74 00
     COMMON         0xa000fc00      0x280 Objects\USB Device - WinUSB - High Bandwidth - C32\usb_device.o
                    0xa000fc00                outPipes
                    0xa000fc0c                pBDTEntryOut
                    0xa000fc1c                pBDTEntryIn
                    0xa000fc2c                USBInData
                    0xa000fe00                BDT   <-----------------------------
                    0xa000fe80                . = ALIGN (0x4)
                    0xa000fe80                . = ALIGN (0x4)
                    0xa000fe80                _end = .
                    0xa000fe80                _bss_end = .

    With this modification, the "USB Device - WinUSB - High Bandwidth - C32" example still works as expected.

    With increased array size, BDT moves to 0xA0010000 (physical: 0x00010000)
    char IMAGEDATA[64000];
     *(COMMON)   
     COMMON         0xa0000200     0xfb80 Objects\USB Device - WinUSB - High Bandwidth - C32\main.o
                    0xa0000200                IMAGEDATA
                    0xa000fc00                EP2OUTOddBuffer
                    0xa000fc40                EP2OUTEvenBuffer
                    0xa000fc80                EP3OUTOddBuffer
                    0xa000fcc0                EP1OUTEvenBuffer
                    0xa000fd00                EP3OUTEvenBuffer
                    0xa000fd40                EP1OUTOddBuffer
     *fill*         0xa000fd80       0x80 00
     COMMON         0xa000fe00      0x280 Objects\USB Device - WinUSB - High Bandwidth - C32\usb_device.o
                    0xa000fe00                outPipes
                    0xa000fe0c                pBDTEntryOut
                    0xa000fe1c                pBDTEntryIn
                    0xa000fe2c                USBInData
                    0xa0010000                BDT    <-----------------------------
                    0xa0010080                . = ALIGN (0x4)
                    0xa0010080                . = ALIGN (0x4)
                    0xa0010080                _end = .
                    0xa0010080                _bss_end = .

    With this change, the example fails even on the first Get_Descriptor() on enumeration.


    For PIC32, firmware has to set up BDT physical address to the BDT Pointer register. BDT Pointer register consists of three registers, U1BDTP3 : U1BDTP2 : U1BDTP1. Upper 24 bit of BDT base address is split into three 8-bit values, and each value is loaded to U1BDTP3-1 registers, respectively.

    U1BDTP3: 31 - 24 bits of BDT base address
    U1BDTP2: 23 - 16 bits
    U1BDTP1: 15 - 8 bits (actually, 15 - 9 bits, 512 bytes align)

    USBSetBDTAddress() macro does this assignment, on USB Framework v2.7 (v2010-04-28).
    C:\Microchip Solutions\Microchip\Include\USB\usb_hal_pic32.h
    #define USBSetBDTAddress(addr)         U1BDTP1 = (((unsigned int)addr)/256);

    USBSetBDTAddress() sets up just lowest U1BDTP1, but U1BDTP3 and U1BDTP2 are left untouched. It is the reason why the firmware fails when BDT moves to 0x00010000.

    This bug is fixed as follows,
       
    #define USBSetBDTAddress(addr)   {  \
            unsigned int PADDR = ConvertToPhysicalAddress(addr); \
            U1BDTP1 = PADDR >>  8;      \
            U1BDTP2 = PADDR >> 16;      \
            U1BDTP3 = PADDR >> 24;      \
            }


    Tsuneo
    post edited by chinzei - 2010/07/26 04:14:12
    #2
    RadioActiveEd
    New Member
    • Total Posts : 6
    • Reward points : 0
    • Joined: 2010/05/25 07:32:33
    • Location: 0
    • Status: offline
    Re:USB Device not Recognized... After defining large array 2010/08/04 07:06:40 (permalink)
    0
    That is some very good information!  I appreciate the assistance, and hope it helps someone else along the way.  I will try the solution this week and post results here, but I am sure it will be successful.
     
    Thanks!
     
    Ed
     
     
    #3
    streammylife
    Starting Member
    • Total Posts : 41
    • Reward points : 0
    • Joined: 2012/07/16 12:10:43
    • Location: Charlotte, NC
    • Status: offline
    Re:USB Device not Recognized... After defining large array 2012/09/26 14:02:14 (permalink)
    0
    This issue combined with a board that has an apparent USB issue stressed me out for over a week.  Thanks for this post as I was facing the same issue.
    #4
    Jump to:
    © 2019 APG vNext Commercial Version 4.5