Author Topic: USB Development 'Blog'  (Read 9714 times)

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
USB Development 'Blog'
« on: February 13, 2008, 02:18:49 AM »
Hi All

Since the uTasker USB development is now (finally) in full swing I thought it timely to start writing a bit of information about it. The first project base is with the Freecale M5222X USB Coldfire with OTG (On-The-Go) capability but the stack is being constructed in a way to allow as much HW independency as possible. The present state (as of writing) is that a first HID (Human Interface Device) class is more or less up and running, but there is still a lot to do and learn before it can be considered as complete... so here's the first installment of a USB development 'Blog' for anyone interested in future USB, or  just enjoys having a laugh at the frustrations of a lonely software developer...


Introduction

USB (Universal Serial Bus) has firmly established itself in the world of PC connectivity. Originally a lot of people were very sceptical about whether it really represented the solution which its promoters reported it to be. How could it compete with Firewire? Did it really have any advantages in any function other than a new method of connecting dongles without having to pile them on the parallel ports? When will it be ready to really be used if Windows NT isn’t going to support it?

But history has shown that it does have a number of benefits which has enabled it to become the new connectivity standard. The version 2.0 has also increased operating speed capabilities to almost the Firewire performance level, at lower costs, and so now there are only a few areas where the interface can not be used.

My personal experiences with USB

I once had a project which involved USB 1.1. This was back in about 1999 when it was still quite new – new Windows 98 PCs already had good support for USB (the hardware had maybe 2 physical connections if one was lucky, whereby one was generally used by the USB mouse, although often PS-2 connections were available too). There were reports about a Windows NT version (possibly a service pack) which would also support USB and the project I was working on absolutely had to be compatible with Windows NT. As the project preparation evolved and the USB controller chips had been designed into the circuit board it became apparent that the NT promises were probably not going to be kept and so a USB interface was also probably going to backfire due to this – the idea was scrapped in place of a standard RS232 connection, which was also adequately fast (I think that later versions of NT could use a USB mouse but didn’t seem to really do much more than that).

So the first project, which would have given some useful early experience, fizzled out. Since then I have not had a second project which required USB and so the only further experience was as a user, where my main impressions of the technology are of headaches trying to get the PC to find drivers for newly installed devices; PC crashes when connecting; my digital camera which worked with XP for about a week and then reported that the device was no longer usable and has never worked since (although an old Win 98 laptop still works fine with it); strange behaviour requiring a USB connected device to be plugged out and back in to get things back to normal; drivers which need to be installed again after simply stopping working (P&E USB Coldfire Multilink is a classic example!!); why does my USB mouse sometimes stop working entirely when debugging with the P&E Coldfire Miltilink?; devices which work great with one PC but refuse to be recognised by the next; having no idea which COM port is being used when connecting a USB-RS232 converter – and it moving around when plugged in to a different connector; and….

As you can see – my experience has not always been the best and I still am very reluctant to use USB in any project where reliability is of importance. On the other hand, I haven’t had the knowledge to be able to solve such problems or identify their causes – I don’t know whether these problems are due to basic USB deficiencies, poor drivers or flaky embedded software, or hardware related issues, or user related stupidity….so it was time to learn more!

How to start with USB

I have read a lot of stuff about how simple USB is to use and it is also true that there are a great many USB controllers and processors with integrated USB which make life very easy. By loading demo software to the chips they do of course operate, but demo software generally is just that – it shows that it can work and does work (sometimes to a degree) but usually has no prevision for error handling and recovery from fault conditions which is important to achieve real long term operating reliability. So demo software is a useful starting point but the developer still needs to have a good understanding and the capability to extend and correct when moving from this starting point.

There are also a lot of USB books and or course masses of on-line information. I have read a lot of this and started with a nice muddle of terms such as “endpoints”, “Tokens”, “descriptors”, “functions”, “Enumeration”, “PIDs”, “IN and OUT transactions”, “Bulk and Isochronous”, “IDLEs, SOFs, EOPs transfers”, “Low, Full and High speed devices”, “Bit-stuffing and NRZI-Encoding”, “Hubs, Devices and the all important SIE” .. not to mention OTG.

So I had read all about it and heard how easy it all is (I mean everyone is using it nowadays), so surely I could pick up a processor with integrated USB interface and type in a few C-command to get it all going!

Fact is, I still didn’t have a clue…..

How on earth does one start implementing a USB stack?

Since I was serious about getting this sorted out I decided that a USB analyser was an essential tool to spy on the USB bus and see what is going on and later what was going wrong with my attempts. I went for the Ellisys USB Explorer which allows recording and analysing low speed, full speed and high speed links. It is not the cheapest and also not the most expensive analyser available but I didn’t want to miss out on having also the high speed support and have to buy a better version later anyway.

So with a muddle in my brain but with a hardware USB analyser at my side, plus a couple of reference books and some demo software as starting point it was at last time to get my coding fingers into operation and get my PC communicating with my first USB project.

----------------------------------------------------------

In the next installment I will introduce the Coldfire M52223 and some details of the enumeration process.

Regards

Mark
« Last Edit: February 16, 2008, 09:36:35 PM by mark »