Application Note. Migrating from RS-232 to USB Bridge Specification USB Microcontrollers. Doc Control. References. Abbreviations



Similar documents
8-bit Microcontroller. Application Note. AVR222: 8-point Moving Average Filter

8-bit RISC Microcontroller. Application Note. AVR182: Zero Cross Detector

AT89C5131A Starter Kit... Software User Guide

AVR305: Half Duplex Compact Software UART. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

AVR106: C functions for reading and writing to Flash memory. 8-bit Microcontrollers. Application Note. Features. Introduction

8-bit RISC Microcontroller. Application Note. AVR236: CRC Check of Program Memory

Quick Start Guide. CAN Microcontrollers. ATADAPCAN01 - STK501 CAN Extension. Requirements

AT91 ARM Thumb Microcontrollers. Application Note. Interfacing a PC Card to an AT91RM9200-DK. Introduction. Hardware Interface

8-bit Microcontroller. Application Note. AVR415: RC5 IR Remote Control Transmitter. Features. Introduction. Figure 1.

Tag Tuning/RFID. Application Note. Tag Tuning. Introduction. Antenna Equivalent Circuit

How to Calculate the Capacitor of the Reset Input of a C51 Microcontroller 80C51. Application Note. Microcontrollers. Introduction

AVR034: Mixing C and Assembly Code with IAR Embedded Workbench for AVR. 8-bit Microcontroller. Application Note. Features.

Application Note. C51 Bootloaders. C51 General Information about Bootloader and In System Programming. Overview. Abreviations

AVR317: Using the Master SPI Mode of the USART module. 8-bit Microcontrollers. Application Note. Features. Introduction

Application Note. 8-bit Microcontrollers. AVR272: USB CDC Demonstration UART to USB Bridge

8-bit Microcontroller. Application Note. AVR400: Low Cost A/D Converter

8-bit Microcontroller. Application Note. AVR105: Power Efficient High Endurance Parameter Storage in Flash Memory

AVR319: Using the USI module for SPI communication. 8-bit Microcontrollers. Application Note. Features. Introduction

AVR030: Getting Started with IAR Embedded Workbench for Atmel AVR. 8-bit Microcontrollers. Application Note. Features.

8-bit Microcontroller. Application Note. AVR314: DTMF Generator

General Porting Considerations. Memory EEPROM XRAM

8-bit Microcontroller. Application Note. AVR201: Using the AVR Hardware Multiplier

8-bit Microcontroller. Application. Note. AVR204: BCD Arithmetics. Features. Introduction. 16-bit Binary to 5-digit BCD Conversion bin2bcd16

AT91 ARM Thumb Microcontrollers. AT91SAM CAN Bootloader. AT91SAM CAN Bootloader User Notes. 1. Description. 2. Key Features

AVR245: Code Lock with 4x4 Keypad and I2C LCD. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

AVR241: Direct driving of LCD display using general IO. 8-bit Microcontrollers. Application Note. Features. Introduction AVR

USB 2.0 Full-Speed Host/Function Processor AT43USB370. Summary. Features. Overview

Application Note. 8-bit Microcontrollers. AVR280: USB Host CDC Demonstration. 1. Introduction

Application Note. USB Mass Storage Device Implementation. USB Microcontrollers. References. Abbreviations. Supported Controllers

8-bit RISC Microcontroller. Application Note. AVR155: Accessing an I 2 C LCD Display using the AVR 2-wire Serial Interface

AVR32100: Using the AVR32 USART. 32-bit Microcontrollers. Application Note. Features. 1 Introduction

8-bit Microcontroller. Application Note. AVR461: Quick Start Guide for the Embedded Internet Toolkit. Introduction. System Requirements

AVR134: Real Time Clock (RTC) using the Asynchronous Timer. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

3-output Laser Driver for HD-DVD/ Blu-ray/DVD/ CD-ROM ATR0885. Preliminary. Summary

AVR32110: Using the AVR32 Timer/Counter. 32-bit Microcontrollers. Application Note. Features. 1 Introduction

8-bit. Application Note. Microcontrollers. AVR282: USB Firmware Upgrade for AT90USB

AVR120: Characterization and Calibration of the ADC on an AVR. 8-bit Microcontrollers. Application Note. Features. Introduction

USB Test Environment ATUSBTEST- SS7400. Summary

Application Note. 8-bit Microcontrollers. AVR270: USB Mouse Demonstration

AVR442: PC Fan Control using ATtiny13. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

AVR32701: AVR32AP7 USB Performance. 32-bit Microcontrollers. Application Note. Features. 1 Introduction

2-wire Serial EEPROM AT24C1024. Advance Information

Two-wire Automotive Serial EEPROM AT24C01A AT24C02 AT24C04 AT24C08 (1) AT24C16 (2)

2-Wire Serial EEPROM AT24C32 AT24C64. 2-Wire, 32K Serial E 2 PROM. Features. Description. Pin Configurations. 32K (4096 x 8) 64K (8192 x 8)

AVR1309: Using the XMEGA SPI. 8-bit Microcontrollers. Application Note. Features. 1 Introduction SCK MOSI MISO SS

Using CryptoMemory in Full I 2 C Compliant Mode. Using CryptoMemory in Full I 2 C Compliant Mode AT88SC0104CA AT88SC0204CA AT88SC0404CA AT88SC0808CA

AVR1900: Getting started with ATxmega128A1 on STK bit Microcontrollers. Application Note. 1 Introduction

AVR287: USB Host HID and Mass Storage Demonstration. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

Application Note. 8-bit Microcontrollers. AVR091: Replacing AT90S2313 by ATtiny2313. Features. Introduction

8-bit Microcontroller. Application Note. AVR134: Real-Time Clock (RTC) using the Asynchronous Timer. Features. Theory of Operation.

Application Note. 8-bit Microcontrollers. AVR293: USB Composite Device

Two-wire Serial EEPROM AT24C1024 (1)

8-bit Microcontroller. Application Note. AVR410: RC5 IR Remote Control Receiver

Atmel AVR4907: ASF - USB Device CDC Application. Atmel Microcontrollers. Application Note. Features. 1 Introduction

Atmel AVR4920: ASF - USB Device Stack - Compliance and Performance Figures. Atmel Microcontrollers. Application Note. Features.

DIP Top View VCC A16 A15 A12 A7 A6 A5 A4 A3 A2 A1 A0 I/O0 I/O1 I/O2 GND A17 A14 A13 A8 A9 A11 A10 I/O7 I/O6 I/O5 I/O4 I/O3. PLCC Top View VCC A17

AVR1318: Using the XMEGA built-in AES accelerator. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

Application Note. 8-bit Microcontrollers. AVR307: Half Duplex UART Using the USI Module

ATF15xx Product Family Conversion. Application Note. ATF15xx Product Family Conversion. Introduction

8-bit. Application Note. Microcontrollers. AVR273: USB Mass Storage Implementation. Features. 1. Introduction

Atmel AVR4921: ASF - USB Device Stack Differences between ASF V1 and V2. 8-bit Atmel Microcontrollers. Application Note. Features.

AVR1922: Xplain Board Controller Firmware. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

AVR115: Data Logging with Atmel File System on ATmega32U4. Microcontrollers. Application Note. 1 Introduction. Atmel

Step Motor Controller. Application Note. AVR360: Step Motor Controller. Theory of Operation. Features. Introduction

Table of Contents. Section 1 Introduction Section 2 Getting Started Section 3 Hardware Description

AT86RF230 (2450 MHz band) Radio Transceiver... User Guide

AVR444: Sensorless control of 3-phase brushless DC motors. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

AVR1600: Using the XMEGA Quadrature Decoder. 8-bit Microcontrollers. Application Note. Features. 1 Introduction. Sensors

AT91 ARM Thumb Microcontrollers. Application Note. AT91 USB CDC Driver Implementation. 1. Introduction. 2. Related Documents

How To Prevent Power Supply Corruption On An 8Bit Microcontroller From Overheating

AVR033: Getting Started with the CodeVisionAVR C Compiler. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

Atmel AVR4903: ASF - USB Device HID Mouse Application. Atmel Microcontrollers. Application Note. Features. 1 Introduction

AVR353: Voltage Reference Calibration and Voltage ADC Usage. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

AVR1301: Using the XMEGA DAC. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

AVR1510: Xplain training - XMEGA USART. 8-bit Microcontrollers. Application Note. Prerequisites. 1 Introduction

AT91 ARM Thumb Microcontrollers. Application Note. GNU-Based Software Development on AT91SAM Microcontrollers. 1. Introduction. 2.

AVR32138: How to optimize the ADC usage on AT32UC3A0/1, AT32UC3A3 and AT32UC3B0/1 series. 32-bit Microcontrollers. Application Note.

APPLICATION NOTE. Atmel AT02985: User s Guide for USB-CAN Demo on SAM4E-EK. Atmel AVR 32-bit Microcontroller. Features. Description.

2-wire Serial EEPROM AT24C512

AVR318: Dallas 1-Wire master. 8-bit Microcontrollers. Application Note. Features. Introduction

AVR2006: Design and characterization of the Radio Controller Board's 2.4GHz PCB Antenna. Application Note. Features.

AT91SAM ARM-based Flash MCU. Application Note

8-bit Microcontroller. Application Note. AVR313: Interfacing the PC AT Keyboard

AVR ONE!... Quick-start Guide. EVK Windows 32104B AVR ONE! 02/10

AVR068: STK500 Communication Protocol. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

All-band AM/FM Receiver and Audio Amplifier IC U2510B

How To Use An Atmel Atmel Avr32848 Demo For Android (32Bit) With A Microcontroller (32B) And An Android Accessory (32D) On A Microcontroller (32Gb) On An Android Phone Or

Application Note. 8-bit Microcontrollers. AVR435: BLDC/BLAC Motor Control Using a Sinus Modulated PWM Algorithm. 1. Features. 2.

256K (32K x 8) OTP EPROM AT27C256R 256K EPROM. Features. Description. Pin Configurations

AVR32788: AVR 32 How to use the SSC in I2S mode. 32-bit Microcontrollers. Application Note. Features. 1 Introduction

32-bit AVR UC3 Microcontrollers. 32-bit AtmelAVR Application Note. AVR32769: How to Compile the standalone AVR32 Software Framework in AVR32 Studio V2

STK 500, AVRISP, AVRISP

Application Note. USB Microcontrollers. USB PC Drivers Based on Generic HID Class. 1. Introduction

8-bit RISC Microcontroller. Application Note. AVR335: Digital Sound Recorder with AVR and DataFlash

Getting started with DfuSe USB device firmware upgrade STMicroelectronics extension

3-output Laser Driver for HD-DVD/ Blu-ray/DVD/ CD-ROM ATR0885. Preliminary. Summary. Features. Applications. 1. Description

8051 Flash Microcontroller. Application Note. A Digital Thermometer Using the Atmel AT89LP2052 Microcontroller

Using WinUSB in a Visual Studio Project with Freescale USB device controller

Application Note Microcontrollers. Guidelines to Keep ADC Resolution within Specification. Introduction. ADC Resolution

Transcription:

Migrating from RS-232 to USB Bridge Specification USB Microcontrollers Doc Control Rev Purpose of Modifications Date 0.0 Creation date 24 Nov 2003 Application Note 1.0 updates 22 Dec 2003 References Universal Serial Bus Specification, revision 2.0 Universal Serial Bus Class Definition for Communication Devices, version 1.1 USB CDC demo firmware Abbreviations USB: Universal Serial Bus CDC: Communication Device Class ACM: Abstract Control Model VID: Vendor Identifier PID: Product Identifier Rev. 1

Introduction Scope In the PC world, the RS-232 COM port is about to disappear from most computers (especially from laptops) in the future, replaced by the USB connection. However, many applications still use the RS-232 standard. One solution can be to use the USB bus as it is an RS-232. The advantages are: no need to change the PC application few hardware and software embedded modifications This document has two main objectives. The first one is to describe how to migrate from a RS-232 to the USB into the firmware using the Atmel USB RS232 Virtual COM port library. The second one is to describe how to build a USB <-> RS-232 bridge, using the Atmel library. Overview Many applications use the RS-232 communication port to communicate between the computer and the embedded application. Figure 1. Initial Application RS-232 FINAL APPLICATION (RS232 Firmware) Switching to the USB port offers many advantages: USB is present on every new computer, not RS-232 the final application can use the flexibility of the USB: data buffering, no data lost, automatic flow control, etc. USB link offers a power supply for the application. Many advantages are available in switching from RS-232 to USB. But the aim is also to perform this switch with a minimum time and effort. 2

Software Architecture The aim of a Virtual COM port implementation is to move from a real UART system to a UART-USB system: PC Application PC Application OS UART drivers OS UART drivers OS CDC Driver Hardware UART Hardware USB RS-232 USB Hardware UART Hardware USB UART drivers UART USB drivers Embedded Application Embedded Application This architecture induces very few modifications. From the PC side, nothing to change! The USB device is seen as a COM port and the application doesn t need to be changed. From the embedded side, the UART driver is replaced by the UART USB drivers. The embedded application calls UART-USB functions instead of UART functions. USB CDC Class The USB Communication Device Class document describes a way to implement devices such as ISDN modems, virtual COM ports, etc. Refer to this document for more details (http:\\www.usb.org). In order to be considered a COM port, the USB device declares 2 interfaces: Abstract Control Model Communication, with 1 Interrupt IN endpoint Abstract Control Model Data, with 1 Bulk IN and 1 Bulk OUT endpoint 3

Loading the CDC Driver under Windows Example of INF file The CDC class is implemented in all releases of Windows, from Windows 98SE to Windows XP. When plugging a new USB device, Windows checks all its INF files to load the appropriate driver. The INF file contains the Vendor ID, the Product ID or the USB Class definition. If the VID/PID or the USB Class Definition of the USB device matches with one INF file, Windows will load the driver described in this file. As Microsoft does not provide standard INF file for the CDC driver, Atmel provides an INF file that allows to load this driver under Windows 2000 and Windows XP. When plugged for the first time, the user indicates to the Operating System which driver to use by selecting this INF file. The application manufacturer has to use its own VID and PID. It has to modify these values in the embedded application (config.h) AND the INF file given in the example below. ; Windows 2000 and XP setup File for AT89C5131 demo [Version] Signature="$Windows NT$" Class=Ports ClassGuid={4D36E978-E325-11CE-BFC1-08002BE10318} Provider=%ATMEL% LayoutFile=layout.inf DriverVer=10/15/1999,5.0.2153.1 [Manufacturer] %ATMEL%=ATMEL [ATMEL] %ATMEL_CDC%=Reader, USB\VID_03EB&PID_2009 [Reader_Install.NTx86] ;Windows2000 [DestinationDirs] DefaultDestDir=12 Reader.NT.Copy=12 [Reader.NT] CopyFiles=Reader.NT.Copy AddReg=Reader.NT.AddReg [Reader.NT.Copy] usbser.sys [Reader.NT.AddReg] HKR,,DevLoader,,*ntkern HKR,,NTMPDriver,,usbser.sys 4

HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider" [Reader.NT.Services] AddService = usbser, 0x00000002, Service_Inst [Service_Inst] DisplayName = %Serial.SvcDesc% ServiceType = 1 ; SERVICE_KERNEL_DRIVER StartType = 3 ; SERVICE_DEMAND_START ErrorControl = 1 ; SERVICE_ERROR_NORMAL ServiceBinary = %12%\usbser.sys LoadOrderGroup = Base [Strings] ATMEL = "ATMEL, Inc." ATMEL_CDC = "AT89C5131 CDC USB to UART" Serial.SvcDesc = "USB Serial emulation driver" 5

UART USB Library Elementary functions uart_usb_test_hit() bit uart_usb_test_hit (void); This function checks if at least one character has been received. uart_usb_getchar() char uart_usb_getchar (void); This function returns the byte received in the OUT Endpoint FIFO if there is at least one byte in the FIFO. If there is no byte in the stack, this function waits for a new USB receipt. uart_usb_putchar() char uart_usb_putchar (char); This function writes the byte put in parameter into the USB IN Endpoint FIFO. If this Endpoint is full, this function sends the entire FIFO to the Host. uart_usb_tx_ready() bit uart_usb_tx_ready (void); This function checks if the firmware can write a byte in the IN Endpoint FIFO. uart_usb_flush() bit uart_usb_flush (void); If there is data stored into the IN Endpoint FIFO, this function sends them. This prevents waiting for the IN Endpoint FIFO to be full before it is sent to the Host. Example of use: USB to RS232 bridge The aim of this example is to implement a very simple USB <-> RS-232 bridge: HYPER TERMINAL (COM1) (Virtual COM Port) HYPER TERMINAL (COM1) (True RS-232) USB AT89C5131 RS-232 Note: the UART configuration can t be changed in this example. 6

Embedded firmware architecture: USB task task Y Scheduler task X USB task Intermediate Buffer buffer = uart_getchar if(uart_usb_tx_ready) if(uart_test_hit) uart_usb_putchar(buffer) USB UART if(uart_tx_ready && uart_usb_test_hit) uart_putchar(uart_usb_getchar) In this implementation, all the received characters from UART are stored in an intermediate buffer in order to avoid data lost when the USB is not able to handle the data. if (uart_test_hit()) { buff[uart_usb_index++]=uart_getchar(); if (uart_usb_tx_ready()) { for (j=0;j<uart_usb_index;j++) {uart_usb_putchar (buff[j]); } uart_usb_index=0; } } if (Uart_tx_ready()) { if (uart_usb_test_hit()) { uart_putchar(uart_usb_getchar()); } } 7

Example of use: Hello World When the HELLO_WORLD_DEMO is defined in the config.h file, the standard STDIO functions are mapped on the USB instead of UART. The firmware can directly use the printf() function for example to write on the USB port. The HELLO WORLD message is continuously sent when pressing on the INT0 button of the AT89C5131 demoboard. All character typed and sent to the AT89C5131 through the Virtual COM port is echoed. if (P3_2 == 0) { printf ("Hello World\r\n"); } if (test_hit()) { putchar (_getkey()); } 8

Atmel Corporation 2325 Orchard Parkway San Jose, CA 95131 Tel: 1(408) 441-0311 Fax: 1(408) 487-2600 Regional Headquarters Europe Atmel Sarl Route des Arsenaux 41 Case Postale 80 CH-1705 Fribourg Switzerland Tel: (41) 26-426-5555 Fax: (41) 26-426-5500 Asia Room 1219 Chinachem Golden Plaza 77 Mody Road Tsimshatsui East Kowloon Hong Kong Tel: (852) 2721-9778 Fax: (852) 2722-1369 Japan 9F, Tonetsu Shinkawa Bldg. 1-24-8 Shinkawa Chuo-ku, Tokyo 104-0033 Japan Tel: (81) 3-3523-3551 Fax: (81) 3-3523-7581 Atmel Operations Memory 2325 Orchard Parkway San Jose, CA 95131 Tel: 1(408) 441-0311 Fax: 1(408) 436-4314 Microcontrollers 2325 Orchard Parkway San Jose, CA 95131 Tel: 1(408) 441-0311 Fax: 1(408) 436-4314 La Chantrerie BP 70602 44306 Nantes Cedex 3, France Tel: (33) 2-40-18-18-18 Fax: (33) 2-40-18-19-60 ASIC/ASSP/Smart Cards Zone Industrielle 13106 Rousset Cedex, France Tel: (33) 4-42-53-60-00 Fax: (33) 4-42-53-60-01 1150 East Cheyenne Mtn. Blvd. Colorado Springs, CO 80906 Tel: 1(719) 576-3300 Fax: 1(719) 540-1759 Scottish Enterprise Technology Park Maxwell Building East Kilbride G75 0QR, Scotland Tel: (44) 1355-803-000 Fax: (44) 1355-242-743 RF/Automotive Theresienstrasse 2 Postfach 3535 74025 Heilbronn, Germany Tel: (49) 71-31-67-0 Fax: (49) 71-31-67-2340 1150 East Cheyenne Mtn. Blvd. Colorado Springs, CO 80906 Tel: 1(719) 576-3300 Fax: 1(719) 540-1759 Biometrics/Imaging/Hi-Rel MPU/ High Speed Converters/RF Datacom Avenue de Rochepleine BP 123 38521 Saint-Egreve Cedex, France Tel: (33) 4-76-58-30-00 Fax: (33) 4-76-58-34-80 e-mail literature@atmel.com Web Site http://www.atmel.com Disclaimer: Atmel Corporation makes no warranty for the use of its products, other than those expressly contained in the Company s standard warranty which is detailed in Atmel s Terms and Conditions located on the Company s web site. The Company assumes no responsibility for any errors which may appear in this document, reserves the right to change devices or specifications detailed herein at any time without notice, and does not make any commitment to update the information contained herein. No licenses to patents or other intellectual property of Atmel are granted by the Company in connection with the sale of Atmel products, expressly or by implication. Atmel s products are not authorized for use as critical components in life support devices or systems. Atmel Corporation 2004. All rights reserved. Atmel, the Atmel logo, andcombinations thereof are registered trademarks of Atmel Corporation or its subsidiaries. Windows Windows 98, Windows XP, and Windows 2000 are trademarks and/ore registered trademark of Microsoft Corporation. Other terms and product names in this document may be the trademarks of others. Printed on recycled paper. /xm