Most laptops and recent desktops do not have serial ports however many legacy
applications still use RS232. The scope of this application note is to migrate such RS232
applications to RS232/USB applications using Turbo Plus uPSD. Since Turbo Plus uPSD
has two UART ports, one of them is used for the USB-to-Serial Bridge connection. The
scope is to implement an easy migration with minimal impact on legacy applications.
Install the setup application provided with this example and the necessary CDC class
drivers will be loaded on your PC. The driver installed will work with Windows 2000 & XP
only. The .inf file has to be modified to work with Windows 98/Me. When connected to a
device that has CDC class implemented, Windows will see USB as a virtual COM port.
PC Application
1.3 .INF file
When a USB device is connected, windows checks the .inf file to load the appropriate driver
for the device.
Microsoft does not provide an .inf file with the usbser.sys driver file. The .inf file usbser.inf
provided via the setup application allows the user to load the usbser.sys driver file under
Windows 2000 and Windows XP. The .inf file has to be modified to work with Windows
98/Me.
Application manufacturers can modify this file and the device descriptors in usb_desc.h for
their own VID & PID.
To install the drivers from a directory instead of running the provided setup application, copy
the usbser.inf file and usbser.sys file to a folder. When the dialog box displaying “Found
New Hardware Wizard” opens up, choose Install from a specific location and point to the
folder where the usbser.inf file is copied.
Usbser.sys
CDC Descriptors
Target Device
Usbser.inf
Note:Do not copy the .inf file into the windows\inf folder manually.
[Strings]
String0="STMicroelectronics"
String1="STMicroelectronics USB Serial Emulator"
Enumerator = "USB Serial Emulator"
%USBFilterString% = "USB Serial Service"
1.4 CDC Firmware Driver
The device enumerates as a CDC driver and talks to the PC over USB on Virtual COM port.
To be considered as a COM port, the USB device declares two interfaces:
●Abstract Control Model Communication class interface using interrupt endpoint 2(IN).
●Data Class Interface using Bulk endpoint 1(IN & OUT)
Descriptors (Device, Configuration and Interface):
const device_descriptor code deviceDesc =
{
sizeof(device_descriptor), // Size of this Descriptor in Bytes
DT_DEVICE, // Descriptor Type (=1)
{USB_SPEC_REV_LSB, USB_SPEC_REV_MSB}, // USB Spec Release Number in BCD
CDC_CLASS, // Device Class Code (CDC class code)
0, // Device Subclass Code (CDC Subclass Code)
0, // Device Protocol Code (CDC Device Protocol)
EP0_PKT_SIZE, // Maximum Packet Size for EP0
{
VENDOR_ID_LSB, VENDOR_ID_MSB }, // Vendor ID
{PRODUCT_ID_LSB, PRODUCT_ID_MSB},// Product ID
{
0x01, 0x02},
0, // Index of String Desc for Manufacturer
0, // Index of String Desc for Product
0, // Index of String Desc for SerNo
1 // Number of possible Configurations
};
const uchar code configDesc[] =
{
9, // Configuration descriptor length
2, // Descriptor type (configuration)
0x43, // Total length of this descriptor 2EP+Control
0x00,
NO_OF_INTERFACES, // Number of interfaces
0x01, // Configuration value (OnSetConfiguration)
0x00, // Index of string descriptor (none)
BM_ATTRIBUTES,
0x32, // 100 mA max power consumption
//Communication class Interface Descriptor Requirement
0x09, // Descriptor length
0x04, // Descriptor type (interface)
0x00, // Number of interface
0x00, // Alternate setting
0x01, // Number of endpoints (except EP0)
CDC_CLASS, // Class code - CDC class code
ACM_VIRTUALCOM, // Subclass - Abstract Control Model(for virtual COM)
INTERFACE_PROTOCOL, // Protocol - 0(interface protocol)
0x00, // iInterface String
//Union Functional descriptor
0x05,//bFunctionalLength
CS_INTERFACE,//bDescriptor type - CS_INTERFACE
UNION_MANAGEMENT_FN,//bDescriptor subtype: Union func desc
0x00,//bMasterInterface: Communication class interface
0x01,//bSlaveInterface0: Data Class Interface
Note:1These requests can be used to configure the UARTs in USB-to Serial bridge
implementations.
RS-232 signal used to tell the DCE
device the DTE device is now present
Sends special carrier modulation used
to specify RS-232 style break
1.6 USB_UART1 Bridge (HW Connection-User setup or
Automatic USB Detect)
The target MCU for the migrated application is the Turbo Plus uPSD. The Turbo Plus uPSD
has two UARTs - UART0 and UART1 and a USB communication interface. The UARTs can
be configured using Timer2 to operate at one of the following Kbps baud rates:
f
MHz
OSC
40.0 115200FFF5113636-1.36%
40.0 57600FFEA56818-1.36%
40.028800FFD5290700.94%
40.0 19200FFBF192310.16%
40.09600FF7E96150.16%
Desired
Baud Rate
RCAP2H (hex) RCAP2L(hex)
Timer 2 SFRs
Resulting
Baud Rate
Optional
Optional
Baud Rate
Deviation
The Tx and Rx lines of UART0 must be connected to the Tx and Rx lines of UART1 when
using Virtual COM port. This will enable the data transferred over UART0 by the application
program to be transferred over USB by the USB-to Serial Bridge Plug-in program.
Target Device
RS232
or
USB
Rx
Tx
Host PC
This connection can be done by the user or can be done through automatic USB detection.
The USB-to-Serial Bridge Plug-in is provided as a library file (upsd3400_USB-to_Serial.lib .
Features of this library are:
●Small code footprint of approximately 3.5K
●Xdata memory space of 800 bytes including intermediate FIFO buffers used for transfer
●Data space of 50 bytes
1.8 Example of easy migration to RS232_USB application:
The scope is to provide an easy migration. The example application echoes back character
typed and sent to Turbo Plus uPSD. All received and transmitted characters are stored in
an intermediate FIFO buffer to avoid data being lost when UART is not able to handle them.
The example application is aimed at easy migration from RS232 only applications to
RS232/USB applications. There is a overhead of one UART port and the firmware is not
efficient in RS232 transfers. Once the reader has familiarized himself with the concepts of
USB and CDC Class implementation it is recommended that he moves to implement a USBto Serial bridge.
Information in this document is provided solely in connection with ST products. STMicroelectronics NV and its subsidiaries (“ST”) reserve the
right to make changes, corrections, modifications or improvements, to this document, and the products and services described herein at any
time, without notice.
All ST products are sold pursuant to ST’s terms and conditions of sale.
Purchasers are solely responsible for the choice, selection and use of the ST products and services described herein, and ST assumes no
liability whatsoever relating to the choice, selection or use of the ST products and services described herein.
No license, express or implied, by estoppel or otherwise, to any intellectual property rights is granted under this document. If any part of this
document refers to any third party products or services it shall not be deemed a license grant by ST for the use of such third party products
or services, or any intellectual property contained therein or considered as a warranty covering the use in any manner whatsoever of such
third party products or services or any intellectual property contained therein.
UNLESS OTHERWISE SET FORTH IN ST’S TERMS AND CONDITIONS OF SALE ST DISCLAIMS ANY EXPRESS OR IMPLIED
WARRANTY WITH RESPECT TO THE USE AND/OR SALE OF ST PRODUCTS INCLUDING WITHOUT LIMITATION IMPLIED
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE (AND THEIR EQUIVALENTS UNDER THE LAWS
OF ANY JURISDICTION), OR INFRINGEMENT OF ANY PATENT, COPYRIGHT OR OTHER INTELLECTUAL PROPERTY RIGHT.
UNLESS EXPRESSLY APPROVED IN WRITING BY AN AUTHORIZED ST REPRESENTATIVE, ST PRODUCTS ARE NOT
RECOMMENDED, AUTHORIZED OR WARRANTED FOR USE IN MILITARY, AIR CRAFT, SPACE, LIFE SAVING, OR LIFE SUSTAINING
APPLICATIONS, NOR IN PRODUCTS OR SYSTEMS WHERE FAILURE OR MALFUNCTION MAY RESULT IN PERSONAL INJURY,
DEATH, OR SEVERE PROPERTY OR ENVIRONMENTAL DAMAGE. ST PRODUCTS WHICH ARE NOT SPECIFIED AS "AUTOMOTIVE
GRADE" MAY ONLY BE USED IN AUTOMOTIVE APPLICATIONS AT USER’S OWN RISK.
Resale of ST products with provisions different from the statements and/or technical features set forth in this document shall immediately void
any warranty granted by ST for the ST product or service described herein and shall not create or extend in any manner whatsoever, any
liability of ST.
ST and the ST logo are trademarks or registered trademarks of ST in various countries.
Information in this document supersedes and replaces all information previously supplied.
The ST logo is a registered trademark of STMicroelectronics. All other names are the property of their respective owners.