Posts

Showing posts from July, 2009

Badly written examples

I'm currently in the middle of writing the host side of a USB bootloader for the Microchip F8 xJxx series processors. This weeks lesson: 1- Don't try to convert online example code to do what you need, you'll invariable end up with an unmaintainable mess.... The clever people who can work out how to get the basic USB calls working are rarely the best at writing nicely structured libraries! I've decided its much easier in the long run to take the time to understand the calls fully and implement them from scratch I currently have working libraries for WinUsb , HID and Microchip based drivers (all implemented in C#). The full ones belong to Quarch but I'm happy to put up snippets if you're having trouble with any particular parts. Just leave a request in the comments. Andy

Custom USB devices (Part 2)

For those trying to decide how to start off with custom USB devices, here's what I think of the main ways you can go.... 1 - CDC This is a serial port emulator. Its a simple way of attaching a USB device and making it look like a normal COM port Good: Simple for beginners to understand, you can ignore most of the USB part entirely and pretend you're still running an old style serial port. Bad: Great if you're making something that has an ASCII command terminal....otherwise its a bit of a bodge. USB is designed to do far more than COM ports were so your device might be inefficient, Also it will not appear nicely as "My Funky Device" in the device manager, it'll just come up as a new COM port. Personally I'd ditch this for most devices 2 - HID This is a standard was of talking to generic devices like keyboards and mice. It can be used to attach just about anything you like though and supports most of the USB transfer types such as 'bulk' and &

Custom USB devices (Part 1)

I've recently been working on a series of custom designed USB devices. based on Microchip PIC processors (18F87J50 and 18F4550) and have a few observations to make for those doing similar things 1 - Get the Microchip USB firmware examples (MCHPFSUSB; search for "USB Stack" on their website). Some of the examples are pretty badly written but they are very useful for beginners. 2 - If you will ever have multiple devices of the same type attached at once you REALLY should add a unique serial number to each device. This is done by altering the USB descriptors. In my case, I set the number with a special command after the device has been programmed. The number is burned into ROM in the bootloader section so the user can never change it. If you don't have a serial number, Windows can get confused. In my case I had up to 28 devices that attach via a chain of USB hubs. If you connect them all at the same time, Windows will fail to find them all or may even blue screen. Addin