AVR922: Add a Serial Number to your USB Device Features 20 characters Serial Number Unique ID for your device Enabled/Disabled by software 1 Introduction Adding to the VID (Vendor ID) and the PID (Product ID), the USB device may need a unique serial number. The AVR USB products offer you this feature and you do not need any external data to build this serial number. All you need is to read the unique ID provided in the AVR embedded flash. A familiarity with USB Software Library for AT90USBxxx Microcontrollers (Doc 7675, Included in the CD-ROM & Atmel website) and the USB specification (http://www.usb.org) is assumed. 8-bit Microcontrollers Application Note Rev.
2 Function needed to read the unique ID In the USB firmware package provided by Atmel, you have a flash driver library available in the flash_drv.h file. The macro Flash_read_sn(pos) allows you to read the byte from the position pos. Calling this macro 10 times using the position 0 to 9 will provide you a unique ID with 10 bytes (The position order does not matter). These 10 bytes will be used to generate the serial number. 3 How to build the serial number Once you have collected the 10 bytes, the serial number can be built for your USB device. This serial number will contain 20 characters. Each byte will be transformed on two characters. For example the byte 0x1A will generate two characters 1 and A (see the figure below). 4 When will the serial number be sent to the host During the enumeration process, the host asks for the USB descriptors information which includes the string descriptors. One of these string descriptors contains the Serial number if available (It is not mandatory to provide a serial number to the host). This request is managed by the usb_standard_request.c file. Please note that the serial number generation can be enabled or disabled in your firmware. To enable or disable the serial number generation, you have to set the correct configuration in the conf_usb.h header file, see below: #define USB_DEVICE_SN_USE ENABLE #define USE_DEVICE_SN_UNIQUE ENABLE If USB_DEVICE_SN_USE is disabled, no serial number will be sent to the host. If this parameter is enabled, two cases are possible: USB_DEVICE_SN_UNIQUE is disabled: In this case, the default serial number (will be the same for all devices) will be set. This default serial number is defined in the usb_descriptors.h header file: 2 AVR922
AVR922 #define USB_SN_LENGTH 0x05 #define USB_SERIAL_NUMBER \ { Usb_unicode('0') \ } USB_DEVICE_SN_UNIQUE is enabled: In this case, the unique serial number will be set and sent to the host as described above. The figures below show you the device proprieties window provided by the device manager (open your device manager and double click on the HID device to get this window, you may have many HID devices connected to your PC, please select the correct one, you can check with the demo name AVR USB MOUSE DEMO ) for each case: Unique serial number assigned: 3
Default serial number: No serial number: 4 AVR922
AVR922 Please note that the serial number showed in the below figure is set by Windows and nothing has been sent by the device. This serial number is not stored in your USB device. 5
Disclaimer Headquarters International Atmel Corporation 2325 Orchard Parkway San Jose, CA 95131 USA Tel: 1(408) 441-0311 Fax: 1(408) 487-2600 Atmel Asia Unit 1-5 & 16, 19/F BEA Tower, Millennium City 5 418 Kwun Tong Road Kwun Tong, Kowloon Hong Kong Tel: (852) 2245-6100 Fax: (852) 2722-1369 Atmel Europe Le Krebs 8, Rue Jean-Pierre Timbaud BP 309 78054 Saint-Quentin-en- Yvelines Cedex France Tel: (33) 1-30-60-70-00 Fax: (33) 1-30-60-71-11 Atmel 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 Product Contact Web Site www.atmel.com Technical Support avr@atmel.com Sales Contact www.atmel.com/contacts Literature Request www.atmel.com/literature Disclaimer: The information in this document is provided in connection with Atmel products. No license, express or implied, by estoppel or otherwise, to any intellectual property right is granted by this document or in connection with the sale of Atmel products. EXCEPT AS SET FORTH IN ATMEL S TERMS AND CONDITIONS OF SALE LOCATED ON ATMEL S WEB SITE, ATMEL ASSUMES NO LIABILITY WHATSOEVER AND DISCLAIMS ANY EXPRESS, IMPLIED OR STATUTORY WARRANTY RELATING TO ITS PRODUCTS INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, CONSEQUENTIAL, PUNITIVE, SPECIAL OR INCIDENTAL DAMAGES (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF PROFITS, BUSINESS INTERRUPTION, OR LOSS OF INFORMATION) ARISING OUT OF THE USE OR INABILITY TO USE THIS DOCUMENT, EVEN IF ATMEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. Atmel makes no representations or warranties with respect to the accuracy or completeness of the contents of this document and reserves the right to make changes to specifications and product descriptions at any time without notice. Atmel does not make any commitment to update the information contained herein. Unless specifically provided otherwise, Atmel products are not suitable for, and shall not be used in, automotive applications. Atmel s products are not intended, authorized, or warranted for use as components in applications intended to support or sustain life. 2009 Atmel Corporation. All rights reserved. Atmel, Atmel logo and combinations thereof, and others, are the registered trademarks or trademarks of Atmel Corporation or its subsidiaries. Windows is a registered trademark of Microsoft Corporation in US and or other countries. Other terms and product names may be trademarks of others.