I was struggling for some time to make my Mac communicate by USB with Arduino. It is part of a larger project of an USB-controlled Lab PSU that I am currently in prototype stage. Part of these problems solved when I finally realized that you cannot use an Arduino as an USB controller simply because the serial ports are just standard UART, with no USB endpoint definition.
It is not the subject of this post to discuss about USB devices and USB interface discovery and enumeration on Mac, although I am pretty sure I will write some posts on this subject since I got a lot of headaches when trying to use ad litteram Apple’s examples from their documentation (Working With USB Device Interfaces) and that is definitely a subject I am convinced many people will find interesting. In fact, programming for USB devices on Mac it is not complicated at all, but — as you will see — there is a small catch with a piece of code that you have to avoid/ tweak in order to get a successful USB interface enumeration, more importantly to be able to use an interface at all. An USB Prober app is mandatory prior to writing any code. Once this solved, USB communication with Arduino worked like a breeze but, again, you need a dedicated USB converter (or UART to USB converter). But this is another story and I will write extensively on this matter.
Luckily, in my scrap parts box I found an USB breakout board (part BOB-00718) that I once bought from SparkFun. This comes populated with a FT232RL chip from FTDI and connects to serial comm ports on Arduino (Tx and Rx). It is an USB to UART converter and is advertised as such on FTDI products page. It is not the scope of this post to elaborate on FTDI product offering, but it might be worth noting that these chips (FT232) are actually USB Slave Converters and not full–fledged USB Controllers. There is some penalty in controller functionality when using FT232 chips.
Anyway, while testing it I wanted to see if there is any possibility to change the device default parameters that come by default with the FTDI chip, especially the vendor ID and the product ID (PID), but also the device description string, manufacturer etc. Would be nice to have a personalised device that would advertise itself as such: „Alauda stuff” etc. More importantly, VID and PID are used to match the USB device with the driver or the application (cannot be both at same time) and it would be cool to document this process thoroughly.
When you want to change the FTDI device descriptors, there are two main steps you need to take:
- you need a PC; there is only a PC version of utility programmer.
- install the FTDI drivers
- lastly, install use the FT Prog application that can be downloaded from FTDI utilities page (here).
Before going further, you have to be aware of one VERY IMPORTANT thing, so important that I will write it in red:
Warning ! When you change the default FTDI VID and PID descriptors, matching against the original FTDI drivers will not work anymore ! Which means that any subsequent attempt to use FT Prog with the serial to USB converter will not work ! You cannot revert back the changes because the device is not longer discovered by the drivers.
There is a solution to this. However, we will not touch VID and PID today. Will leave this to another post where I will also discuss the solution to this problem. But, again, you need a PC for all this process. Actually, you need a PC for most of these low–level applications and some applications that do not have any Mac versions. With Microchip notable exception, there are very few — if none at all — companies that have Mac versions of their IDEs. One more: customising USB device parameters as in this example is only for educational purposes. For more information read here and also this USB compliance documentation.
Installing the drivers
There are two sets of drivers: virtual com (VCP) and direct–to–device (D2XX) drivers: The VCP driver emulates a standard PC serial port such that the USB device may be communicated with as a standard RS232 device.
The D2XX driver allows direct access to a USB device via a software interface (libs or frameworks). The application software can access the USB device through a series of function calls that will be part of your custom dylib, DLL or framework. The functions available are listed in the D2XX Programmer’s Guide pdf document which is available from the Documents section of FTDI’s site. Programming examples using the D2XX drivers and DLL can be found in the projects section of FTDI’s site. The good news here is that the documentation is very well written, the examples work and there are Win as well as OS X versions of the D2XX drivers. This is a very cool area, but we will not use these here.
Virtual COM port (VCP) drivers cause the USB device to appear as an additional port available to the computer (COM on PC, /dev/tty for OS X). Application software can access the USB device in the same way as it would access a standard port. This discussion assumes installation of VCP drivers. Latest version for Win is 2.08.30 for 32 bit and 64 bit; and 2.2.18 for Mac (32 bit, 64 bit and PPC). Install the PC drivers, restart etc. The port is listed under COMx (where X can be anything, at windows’ discretion).
Install and use FT Prog
Connect the device and wait to be discovered. A generic COM port will be assigned, in this case COM5:
Open FT_Prog. By default, with no device connected, the app shows no info. Connect the FTDI device and click on the loupe icon. This will read chip’s EEPROM.
After several seconds (it depends on the enumerating speed), the chip’s parameters are read, displayed, together with an EEPROM dump:
Note the values of the USB Device Descriptor parameters: I have already changed my FTDI to 9999 for vendor ID and 6666 for product ID and will leave this for another demo. As said, there’s a bit more to discuss when changing the VID and PID (on the driver side), so today I will change only the string descriptor. Current values are „Alauda Projects” for manufacturer string and „Custom USB Interface” for product description. You can also specify whether you want to enable serial numbering and change parameters for serial number generation: manual or automatic with prefix. Also, note that the second and third words in the EEPROM dump are, actually, the vendor ID and the product ID. Will explain the significance of the rest in another post. Moreover, I will not get here into details about using this app, there is an excellent User Guide for FTDI FT_Prog utility and a lot of related documentation that can be downloaded from FTDI Documents page. For the scope of this demo we will change only the Product Description string.
Enter another string. I chose „My Funny USB”. Click on the small thunderbolt icon next to the loupe. The app will enter programming mode and will change the parameter. The result is shown below:
That’s it. Next article will focus on vendor and product ID change, how to tackle any issues with driver matching and diving deeper into some other parameters. Enjoy. As always, I’d be more than happy to get comments from you.