USBSERVICE + serout2 problem


Closed Thread
Results 1 to 40 of 52

Hybrid View

  1. #1
    Join Date
    Dec 2007
    Location
    Paris
    Posts
    101

    Default

    Follow up on the monologue, and after a day of digging through literature, I now have a slightly deeper understanding of the USB protocol. The more helpful was Microchip datasheet, within the USB section related to BDT RAM.



    200h is start of USB RAM for PIC18F1xK50, 400h for 18Fx550/x455/x450.

    I moved the allocations to Endpoint 3 for CDC usage:

    RXOWNED VAR BD3STATOUT.7 ; Out report Owned (OUT is PC to PIC)
    TXOWNED VAR BD3STATIN.7 ; IN report Owned (IN is PIC to PC)
    -------------------------------------------------------------------------------------------------------
    BD3STATOUT = _USBMEMORYADDRESS + 18h ; 418h or 218h
    BD3STATIN = _USBMEMORYADDRESS + 1Ch ; 41Ch or 21Ch
    Bit 7 of BDxSTAT states which device (SIE or CPU) owns the right to write or read into the dual ported USB RAM space, so this is what is used for the TX and RX ready flag.

    For some reason the compiler doesn't like the 3 in "BD3STATOUT and BD3STATIN" (Bad data type error). CONFIGURED_STATE should not differs between HID or CDC as it is not endpoint dependent.
    Last edited by aberco; - 13th October 2010 at 22:36.

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959

    Default

    Quote Originally Posted by aberco View Post
    I moved the allocations to Endpoint 3 for CDC usage:
    ...
    For some reason the compiler doesn't like the 3 in "BD3STATOUT and BD3STATIN"
    You missed the EXT vars ...

    Code:
    BD3STATOUT         VAR BYTE EXT      ; OUT report status byte
    BD3STATIN          VAR BYTE EXT      ; IN report status byte
    DT

  3. #3
    Join Date
    Dec 2007
    Location
    Paris
    Posts
    101

    Default

    Ah thanks! that was just above, an easy fix.

    RX_Ready seems to work! but TX_Ready is always true... maybe because the time when the OUT endpoint is owned by the SIE is so short that I can't see it? However if I do a loop that sends data as soon as the SIE is ready I have huge data loss.
    Right now I have to add a 200ms delay between each 32Bytes packets I send in order to avoid data transmission loss. It is rather slow... reading a 24LC512 at this speed would take a bit less than 4h.

    Am I missing something here?
    Last edited by aberco; - 13th October 2010 at 23:28.

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959

    Default

    My shipping container just arrived yesterday with all my stuff from California, still unloading it.
    Hopefully I can get some computers setup soon to be able to work on this stuff again.

    Can't sit in the forum at work, just too busy during the day.

    If you haven't figured it out by next week, I'll be back on it.
    Sorry, I haven't been much help.
    DT

  5. #5
    Join Date
    Dec 2007
    Location
    Paris
    Posts
    101

    Default

    No Darrel, you have been very helpful so far, at least to set me on the right course to fix issues.

    I'm much more of an hardware person, getting better and better at programming but some time simple software tricks are not obvious to me... However when it comes to reading datasheets and understanding hardware peripherals, registers and configuration bits I feel at home.

    I will carry on progress one step at a time

  6. #6
    Join Date
    Dec 2007
    Location
    Paris
    Posts
    101

    Default

    I think that most of my USB problems are solved now!

    I rewrote the USB Out routine as such:

    Code:
    '*******************************************************
    'Writing data to USB port
    '*******************************************************
    DoUSBOut:
    
    USBBufferSizeTX = 0
    FOR Counter = 1 TO USBBufferSizeMax 'Calculate number of valid bytes within the string
    IF USBBuffer [Counter - 1] > 0 THEN USBBufferSizeTX = USBBufferSizeTX + 1
    NEXT Counter
    
    IF TX_READY THEN 'USB data can be transmitted
        TX_READY = 0 'Clear USB data send flag
        USBOUT 3, USBBuffer, USBBufferSizeTX, DoUSBOut
    ENDIF
    
    FOR Counter = 1 TO USBBufferSizeMax 'Clear the USB buffer after data has been sent
    USBBuffer [Counter - 1] = 0
    NEXT Counter
    
    RETURN
    - Fist step is to calculate how many bytes are used in the string (not = 0)
    - Second, sending data
    - third, blanking the data buffer for next operation

    I have no more garbage data in my strings, and I was able to remove the Pause without any data loss. Transmission is very fast now, with over 10kB/s (I have large conversion routines between my DoUSBOut, could even be faster without these).

    Now onto other problems, especially getting all the interrupts to work together,and implementing ADC and ultra-low power routine.

    What about publishing the generic code for CDC? I'll let you decide since it is actually minor modification to code you have written.

  7. #7
    Join Date
    Dec 2007
    Location
    Paris
    Posts
    101

    Default Re: USBSERVICE + serout2 problem

    And everything collapsed!

    The CDC USB routine was working well until now. It is working very well on my early prototypes, I made 3 more identical one and the PIC just stop running randomly after a few seconds up to several minutes. USB communication stops and LEDs turns off. It still respond to the INT0 interrupt though, and resume normal operation after reset... until it crashes again randomly.

    I am puzzled as the hardware is strictly identical, the only difference I could spot is in the silicon revision of the PIC18LF14K50, says 0000006 on the working batch and 0000005 on the batch that crashes. I have inserted a simple blinking LED loop routine at the very beginning of my code, and it still crashes and stop blinking. Removing part of the program related to USB solve the crashing problem so I would think that there is something wrong in the USB CDC code I have modified.

    Problem is that in the revision errata there is nothing linked to the USB SIE, and I am totally clueless about where to start to debug this issue. What could be wrong to have the PIC crash at a random time interval? some kind of buffer overflow?

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts