]> USB 2.0 HID 1.11 device running on a SiLabs C8051F342 or a C8051F346 microcontroller unit

USB 2.0 HID 1.11 running on a SiLabs C8051F342 or a C8051F346 microcontroller unit

by Stephan K.H. Seidl

Version 1, Mon, 13 Jan 2020 21:16:08 +0100


Nowadays, USB HIDs are widely used to connect hotplug devices to a computer without the need to provide a device driver. In order not to be rejected, such a device meticulously answers all requests from the host, but formulates the descriptors so that the host cannot determine what the device is intended for. The device is available in that way, but cannot be accessed by the operating system. It is therefore immediately available in the user space if the application in question has the necessary rights. It is further of secondary importance whether the user space application then uses the standard HID interfaces or proprietary vendor USB interfaces for the actual work.

Regardless, creating a properly functioning USB HID is not that easy. It is therefore sensible to publish the code of a standard-compliant and quite complex device one time in order to give beginners or interested parties a reasonable start.

To do

Writing to the flash program memory has not yet been tested, but will be done one day.

Change log

For the change log click Changelog.
Comments, bug reports, and better ideas are welcome.


The file mainusb.c (click here for download) contains the source code of a particular USB HID. The present code controls the bare silicon without any library. In addition to the fact that this code impressively shows how asynchronous peripherals are operated at a very low level, the first time dealing with the Harvard architecture leads to very special insights. The device control here does without the use of generic pointers for reasons of efficiency. So much more caution needs to be exercised, for example, with cast operators applied to pointers. On the other hand, it becomes clear that the strict separation of the different memory areas has to be somehow undermined in order to cope with such an architecture as a whole. What is missing on this website is the small startup file, which cannot be displayed for licensing reasons. Startup files in assembly language are usually located in the development system used. The following photo shows a candidate for the underlying hardware as offered by Crossware in the past.


That's it.

Mon, 13 Jan 2020 21:16:08 +0100

Stephan K.H. Seidl