Posts

Showing posts from 2009

JTAG Progromming on a PIC

Programming an FPGA is a simple job if you have a JTAG interface and programmer to hand. When a product is out in the field though, it's nice to have a more 'customer friendly' method of update.... We're using Lattice XP chips. Lattice supplies the source code for an embedded programmer with their IspVM programming solution. This used ' SlimVME ' files that are compressed for a smaller footprint. Instead of using .JED files, you get 2 VME files, one 'DATA' file containing the fuse settings and a ' ALGO ' file that has the programming algorithm. You can create them either in binary form or as HEX files with .c extensions that ley you compile them directly into code (each file contains a single big initialised array) In the lattice example, you compile a version of these files in with their programming code. Obviously this leads to a large code footprint ~200K for my code....not so good on a PIC! My solution is to use the binary export option

Remove USB devices from the registry

When messing about with USB devices you can end up with a lot of junk in the registry. If you plug a device into different USB hub ports or, worse, have several of the same device attached at once things can get really bad. If your devices don't have a unique serial number then Windows can't tell what devices it's seen before. The effect is that every time a device is plugged into a 'new' port, the driver will be re installed! if, like me, you have a lot of USB hubs and devices (24+ here) your PC can get unstable and crash. When I moved to putting a unique serial number on my devices I hit a problem... Windown won't recognise the serial number if it has previously seen a device with the same VID, PID combination that did NOT have a valid serial number... Again, that means needing to clear the registry: First, unplug the USB devices then: Run : regedit.exe Navigate to: HKEY_Local_Machine -> System -> CurrentControlSet -> Enum -> USB Now delete all the

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