• AVR Freaks

CDC Serial emulator of MCHPFSUSB v2.3.1 USB Framework

Author
buddacedcc
Senior Member
  • Total Posts : 167
  • Reward points : 0
  • Joined: 2009/02/01 15:39:06
  • Location: Italy
  • Status: offline
2009/02/01 15:41:33 (permalink)
0

CDC Serial emulator of MCHPFSUSB v2.3.1 USB Framework

This version ( http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=2680&dDocName=en537044 )  of serial emulator support hardware flow control (RTS/CTS) ?
post edited by buddacedcc - 2009/02/01 15:46:19
#1

14 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: CDC Serial emulator of MCHPFSUSB v2.3.1 USB Framework 2009/02/02 00:41:44 (permalink)
    0
    This version ( MCHPFSUSB v2.3.1 ) of serial emulator support hardware flow control (RTS/CTS) ?


    No, it doesn't.

    You'll see "#define USB_CDC_SUPPORT_HARDWARE_FLOW_CONTROL" in usb_config.h
    But this naming is wrong. What it actually does is just enabling flip of RTS pin by Set_Control_Line_State handler (usb_function_cdc.c USBCheckCDCRequest() ).

    You have to add your original code to the firmware, to support the REAL RTS/CTS hardware flow control.

    - Implement two cyclic buffers
    - Connect these buffers to the USB bulk IN and OUT endpoints, respectively
    - Connect these buffers to UART TX and RX register, respectively
    - Flip RTS pin seeing the data amount on the RX buffer
    - By CTS pin, switch on/off the data transfer from the TX buffer to the UART TX register
    - Ignore RTS bit in Set_Control_Line_State handler

    Maybe 200-300 lines of code in C.

    Tsuneo
    post edited by chinzei - 2009/02/02 01:24:39
    #2
    buddacedcc
    Senior Member
    • Total Posts : 167
    • Reward points : 0
    • Joined: 2009/02/01 15:39:06
    • Location: Italy
    • Status: offline
    RE: CDC Serial emulator of MCHPFSUSB v2.3.1 USB Framework 2009/02/02 01:34:32 (permalink)
    0
    LOL..I will use FT232 Chip :D
    #3
    Antipodean
    Super Member
    • Total Posts : 1704
    • Reward points : 0
    • Joined: 2008/12/09 10:19:08
    • Location: Didcot, United Kingdom
    • Status: online
    RE: CDC Serial emulator of MCHPFSUSB v2.3.1 USB Framework 2009/02/02 05:13:35 (permalink)
    0
    ORIGINAL: buddacedcc

    LOL..I will use FT232 Chip :D

     
    Why ???
     
    Modify the Microchip code so that it will use the handshake in a meaningful way, exactly as suggested. IIRC even the FTDI chip doesn't really handle handshaking in the manner that the original serial port does.

    Do not use my alias in your message body when replying, your message will disappear ...

    Alan
    #4
    buddacedcc
    Senior Member
    • Total Posts : 167
    • Reward points : 0
    • Joined: 2009/02/01 15:39:06
    • Location: Italy
    • Status: offline
    RE: CDC Serial emulator of MCHPFSUSB v2.3.1 USB Framework 2009/02/02 05:26:07 (permalink)
    0
    IIRC even the FTDI chip doesn't really handle handshaking in the manner that the original serial port does.

    Explain this please ?
    #5
    DarioG
    Allmächtig.
    • Total Posts : 54081
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: Oesterreich
    • Status: offline
    RE: CDC Serial emulator of MCHPFSUSB v2.3.1 USB Framework 2009/02/02 06:32:22 (permalink)
    0
    ORIGINAL: chinzei

    This version ( MCHPFSUSB v2.3.1 ) of serial emulator support hardware flow control (RTS/CTS) ?


    No, it doesn't.

    You'll see "#define USB_CDC_SUPPORT_HARDWARE_FLOW_CONTROL" in usb_config.h
    But this naming is wrong. What it actually does is just enabling flip of RTS pin by Set_Control_Line_State handler (usb_function_cdc.c USBCheckCDCRequest() ).

    You have to add your original code to the firmware, to support the REAL RTS/CTS hardware flow control.

    - Implement two cyclic buffers
    - Connect these buffers to the USB bulk IN and OUT endpoints, respectively
    - Connect these buffers to UART TX and RX register, respectively
    - Flip RTS pin seeing the data amount on the RX buffer
    - By CTS pin, switch on/off the data transfer from the TX buffer to the UART TX register
    - Ignore RTS bit in Set_Control_Line_State handler

    Maybe 200-300 lines of code in C.



    Thanks Tsuneo ! May help in the future...

    GENOVA :D :D ! GODO
    #6
    jsuijs
    New Member
    • Total Posts : 3
    • Reward points : 0
    • Joined: 2009/02/02 12:26:12
    • Location: 0
    • Status: offline
    RE: CDC Serial emulator of MCHPFSUSB v2.3.1 USB Framework 2009/02/02 12:37:01 (permalink)
    0
    Hi,
     
    I've tried to enable the 'hardware flow control' by adapting the cdc-demo for 18f4550 and noticed it does work for DTR (chang DTR at the PC and the code is called). But changing RTS does not seem to trigger any USB message to the 18f4550.
    Searching on the net, I came accross your statement that there is something odd with rts of usbser.sys. Could this be causing my problem?
    And if so, what are my options? Are there alternative cdc drivers available that emulate a comport and provide the pic with the data, break-info and setup (baudrate, rts, dtr)? And if so, how can I use them with the pic?
     
    Joep
     
    #7
    chinzei
    Super Member
    • Total Posts : 2250
    • Reward points : 0
    • Joined: 2003/11/07 12:39:02
    • Location: Tokyo, Japan
    • Status: offline
    RE: CDC Serial emulator of MCHPFSUSB v2.3.1 USB Framework 2009/02/03 11:23:29 (permalink)
    0
    I've tried to enable the 'hardware flow control' by adapting the cdc-demo for 18f4550 and noticed it does work for DTR (chang DTR at the PC and the code is called). But changing RTS does not seem to trigger any USB message to the 18f4550.

    usbser.sys issues no USB request, when PC app calls EscapeCommFunction (WinAPI) for RTS. But it holds the RTS value on it, and put the value when EscapeCommFunction is called for DTR. This weird behavior isn't affected by fRtsControl bit on DCB.

    Then, the workaround to change RTS status is,
    call EscapeCommFunction() twice, one for RTS and another for DTR, to put the RTS value to the device.


    These sequences show a monitoring result with PortMon and a bus analyzer.

    Sequennce 1

    Default after CreateFile (though GetCommState reports DCB.fRtsControl = 1)
    or
    DCB.fRtsControl = RTS_CONTROL_DISABLE (0x00)
    or
    DCB.fRtsControl = RTS_CONTROL_HANDSHAKE (0x02)
    or
    DCB.fRtsControl = RTS_CONTROL_TOGGLE (0x03)

    EscapeCommFunction PortMon USB wVal
    1 SETDTR IOCTL_SERIAL_SET_DTR SET_CONTROL_LINE_STATE 0x0001
    2 CLRDTR IOCTL_SERIAL_CLR_DTR SET_CONTROL_LINE_STATE 0x0000

    3 SETRTS IOCTL_SERIAL_SET_RTS --- (no request)
    4 CLRRTS IOCTL_SERIAL_CLR_RTS --- (no request)

    5 SETRTS IOCTL_SERIAL_SET_RTS --- (no request)
    6 SETDTR IOCTL_SERIAL_SET_DTR SET_CONTROL_LINE_STATE 0x0003
    7 CLRRTS IOCTL_SERIAL_CLR_RTS --- (no request)
    8 SETDTR IOCTL_SERIAL_SET_DTR SET_CONTROL_LINE_STATE 0x0001

    9 SETRTS IOCTL_SERIAL_SET_RTS --- (no request)
    10 CLRDTR IOCTL_SERIAL_CLR_DTR SET_CONTROL_LINE_STATE 0x0002
    11 CLRRTS IOCTL_SERIAL_CLR_RTS --- (no request)
    12 CLRDTR IOCTL_SERIAL_CLR_DTR SET_CONTROL_LINE_STATE 0x0000



    Sequennce 2

    DCB.fRtsControl = RTS_CONTROL_ENABLE (0x01)

    EscapeCommFunction PortMon USB wVal
    1 SETDTR IOCTL_SERIAL_SET_DTR SET_CONTROL_LINE_STATE 0x0003
    2 CLRDTR IOCTL_SERIAL_CLR_DTR SET_CONTROL_LINE_STATE 0x0002

    3 SETRTS IOCTL_SERIAL_SET_RTS --- (no request)
    4 CLRRTS IOCTL_SERIAL_CLR_RTS --- (no request)

    5 SETRTS IOCTL_SERIAL_SET_RTS --- (no request)
    6 SETDTR IOCTL_SERIAL_SET_DTR SET_CONTROL_LINE_STATE 0x0003
    7 CLRRTS IOCTL_SERIAL_CLR_RTS --- (no request)
    8 SETDTR IOCTL_SERIAL_SET_DTR SET_CONTROL_LINE_STATE 0x0001

    9 SETRTS IOCTL_SERIAL_SET_RTS --- (no request)
    10 CLRDTR IOCTL_SERIAL_CLR_DTR SET_CONTROL_LINE_STATE 0x0002
    11 CLRRTS IOCTL_SERIAL_CLR_RTS --- (no request)
    12 CLRDTR IOCTL_SERIAL_CLR_DTR SET_CONTROL_LINE_STATE 0x0000


    Anyway, it isn't "hardware flow control" Smile
    but you can emulate RTS flow control by the PC app.

    Unfortunately, CDC doesn't carry CTS signaling. Though I don't know the reason, the USB CDC spec doesn't define any bit for CTS on SerialState notification.

    Tsuneo
    post edited by chinzei - 2009/02/03 11:35:59
    #8
    jsuijs
    New Member
    • Total Posts : 3
    • Reward points : 0
    • Joined: 2009/02/02 12:26:12
    • Location: 0
    • Status: offline
    RE: CDC Serial emulator of MCHPFSUSB v2.3.1 USB Framework 2009/02/03 12:09:46 (permalink)
    0
    Hi Tsuneo,

    Thank you for your clear answer. This way I can handle this behaviour within my own applications.

    But... with usbser.sys, it won't work with existing applications that don't take this behavior into account.
    Are there any drivers around that emulate a serial port (although it seems the first choice, it does not need to be CDC), that can be used with by 18F4550 and does handle rts properly (I can live without the cts support)?

    Thanks,
    Joep
    post edited by jsuijs - 2009/02/03 12:49:13
    #9
    chinzei
    Super Member
    • Total Posts : 2250
    • Reward points : 0
    • Joined: 2003/11/07 12:39:02
    • Location: Tokyo, Japan
    • Status: offline
    RE: CDC Serial emulator of MCHPFSUSB v2.3.1 USB Framework 2009/02/03 13:25:12 (permalink)
    0
    Are there any drivers around that emulate a serial port (although it seems the first choice, it does not need to be CDC), that can be used with by 18F4550 and does handle rts properly (I can live without the cts support)?

    There are several commercial drivers which replace usbser.sys

    Thesycon: USB CDC/ACM Class Driver
    http://www.thesycon.de/eng/usb_cdcacm.shtml

    Jungo: DriverCore - USB Communication Device Class
    http://www.jungo.com/usb_communication_device_class.html


    For personal use, you can find projects which make a PIC to a FTDI clone (emulation) on this forum. Search it wink

    Tsuneo
    #10
    jsuijs
    New Member
    • Total Posts : 3
    • Reward points : 0
    • Joined: 2009/02/02 12:26:12
    • Location: 0
    • Status: offline
    RE: CDC Serial emulator of MCHPFSUSB v2.3.1 USB Framework 2009/02/03 14:50:44 (permalink)
    0




    For personal use, you can find projects which make a PIC to a FTDI clone (emulation) on this forum. Search it wink

    Tsuneo


    I did and found a lot to chew on.

    Thanks again!
    Joep
    post edited by jsuijs - 2009/02/04 00:12:17
    #11
    buddacedcc
    Senior Member
    • Total Posts : 167
    • Reward points : 0
    • Joined: 2009/02/01 15:39:06
    • Location: Italy
    • Status: offline
    RE: CDC Serial emulator of MCHPFSUSB v2.3.1 USB Framework 2009/02/04 01:20:22 (permalink)
    0
    For personal use, you can find projects which make a PIC to a FTDI clone (emulation) on this forum. Search it

    Suggest string for search ?
    #12
    igorkov
    New Member
    • Total Posts : 23
    • Reward points : 0
    • Joined: 2010/02/05 17:25:58
    • Location: Sebastopol, Ukraine
    • Status: offline
    RE: CDC Serial emulator of MCHPFSUSB v2.3.1 USB Framework 2010/02/24 16:24:16 (permalink)
    0
    ORIGINAL: chinzei

    Are there any drivers around that emulate a serial port (although it seems the first choice, it does not need to be CDC), that can be used with by 18F4550 and does handle rts properly (I can live without the cts support)?

    There are several commercial drivers which replace usbser.sys

    Thesycon: USB CDC/ACM Class Driver
    http://www.thesycon.de/eng/usb_cdcacm.shtml

    Jungo: DriverCore - USB Communication Device Class
    http://www.jungo.com/usb_communication_device_class.html


    For personal use, you can find projects which make a PIC to a FTDI clone (emulation) on this forum. Search it wink

    Tsuneo


    I tried this driver - RTS really works
    But 3000EUR - it's too expensive
    #13
    xiaofan
    Super Member
    • Total Posts : 6247
    • Reward points : 0
    • Joined: 2005/04/14 07:05:25
    • Location: Singapore
    • Status: offline
    RE: CDC Serial emulator of MCHPFSUSB v2.3.1 USB Framework 2010/02/24 16:55:59 (permalink)
    0
    ORIGINAL: buddacedcc

    For personal use, you can find projects which make a PIC to a FTDI clone (emulation) on this forum. Search it

    Suggest string for search ?


    I thought you were having some discussion in that thread. grin
    http://www.microchip.com/forums/tm.aspx?m=261649


      USB_Links and libusb
    #14
    icserny
    Super Member
    • Total Posts : 258
    • Reward points : 0
    • Joined: 2008/09/07 13:27:08
    • Location: Debrecen, Hungary
    • Status: offline
    RE: CDC Serial emulator of MCHPFSUSB v2.3.1 USB Framework 2011/01/30 23:32:28 (permalink)
    0
    What it actually does is just enabling flip of RTS pin by Set_Control_Line_State handler (usb_function_cdc.c USBCheckCDCRequest() ).
    Even this will not work in the USB Device - Serial Emulator  example program, since the UART_TRISRTS and UART_TRISDTR pins are only defined but are never set!

    One must:
    1. #define USB_CDC_SUPPORT_HARDWARE_FLOW_CONTROL (in usb_config.h)

    2. #define USB_CDC_SUPPORT_ABSTRACT_CONTROL_MANAGEMENT_CAPABILITIES_D1 (in usb_config.h)

    3. Add these lines to InitializeUSART(void) (in main.c), inside the #if defined(__18CXX) branch:
        #if defined(USB_CDC_SUPPORT_HARDWARE_FLOW_CONTROL)
            #if defined(UART_TRISDTR)
            UART_TRISRTS = 0;
            #endif
            #if defined(UART_TRISDTR)
            UART_TRISDTR = 0;
            #endif
        #endif

    #15
    Jump to:
    © 2019 APG vNext Commercial Version 4.5