📜 ⬆️ ⬇️

How I did a USB device

Somewhere I once read that the creators of the first USB specification intended to make this standard easy to implement in hardware due to the complexity of the software. Thus, the goal was to make production as cheap as possible and make USB devices very accessible. Now we can say that the chip makers did it, but is it really that easy to implement in this standard? I'm afraid the answer is not obvious.



Suppose I need to make my simple USB device. What are my options?
')
There are several options:

1. Using external special chips, for example, USB-to-Serial converters. Anyone can use the serial port. FTDI company produces such chips. This and FT232R USB-UART and FT245R USB-FIFO. The use of these microcircuits makes the development of the device very simple, but slightly increases its cost.

2. Using microcontrollers with built-in USB interface. Such chips are released, for example, by Atmel (for example, the AT90USB82 chip). A good solution requires knowledge of the AVR command system and the AVR microprocessor in general.

3. Using AVR microcontrollers with software emulation USB interface. This is the famous V-USB library.

It should be noted that choosing any of these three ways, we greatly simplify our lives and in fact remain in ignorance: “Is it difficult to implement USB in hardware?”

Here, under the implementation "in hardware", I mean the lowest level of design - circuit engineering.

I wanted to check the very possibility of implementing USB at home. The case was not very simple, but it turned out!



For my USB implementation, I took the Altera EPM240T100C5 FPGA Mars Rover (240 logic elements). Her scheme is here .
Development environment Altera Quartus II v9.

Were written in Verilog language: receiver and transmitter module, USB core - deciding when and what to send. All packages and descriptors were placed in the CPLD flash memory.

For my device, I took Alter's idVendor = 0x9FB (I hope they will forgive me?) And idProduct = 0x60A5 (from the ceiling).

I did not write a driver for Windows - I took the example of the BULKUSB.SYS driver from the Microsoft Windows Driver Developer Kit and just compiled it. But the INF file had to be changed - specify your manufacturer ID and product ID.

The program for working with the device of course had to write.



It can read one byte from the device and write one byte to the device. There are 8 LEDs on the Mars Rover board - now I can light them programmatically. There are also 4 buttons on the board - now I can programmatically read their status from the device. A bit, right? But this thing can actually replace, for example, a parallel or serial port - you can connect some self-made "mood lamp" or something else.

All source codes of programs, drivers and the project for CPLD can be taken here .

So my simple device took 215 gates in the CPLD chip.

Of course, I didn’t follow the USB standard too much — I didn’t check the checksums of the received packets or even the toggle parity check. Nevertheless, the tests showed quite stable operation of the device for a long time.

For more information, see the Mars Rover site .

Source: https://habr.com/ru/post/106420/


All Articles