Yesterday I described how the first step when connecting to a TUSB3410 chip is to upload firmware to it. After losing quite a few hairs with my TI TUSB3410 user-space driver not working on macOS while working perfectly fine on Linux, I've come to a few conclusions.
After the firmware is sent to the TUSB3410 chip, it stops responding until you perform a soft reset. The only problem is that since El Capitan, macOS ignores soft resets from libusb, the library used by node-usb. I have verified this by looking at the Wireshark traces. Nothing appears on the bus after the firmware is sent.
There seems to be a workaround, which involves re-enumerating the device instead of a soft reset, but this means modifying the libusb library itself. I think I've spent enough time on this for now, and will maybe look into again in future.
I think I have finally figured out the problem with my TUSB3410 driver, including why it's not working on my USB host shield. In short, the chip requires that you upload its firmware into the chip every time it is plugged in.
I noticed today that sometimes when I plug it into a host PC, there is only one USB configuration with only an OUT endpoint. There should be two configurations with the second one having multiple endpoints, including an IN endpoint.
This made me realise that it's possible that when I plug the device into a system with a working kernel driver, that driver is loading the firmware into the chip, so that when I then unload the kernel driver I see the two configurations when connecting with the user-space driver.
To confirm this I added the ti_usb_3410_5052 Linux kernel driver to the kernel module blacklist (/etc/modprobe.d/blacklist.conf) to prevent it from loading. I then verified this by running usb-devices[1] and checking that it says Driver=(none) next to the device description.
I then checked the number of configurations and low and behold, there was only one this time.
Luckily Texas Instruments has made the source code for their macOS driver available online, even though the macOS driver itself was never officially released. The source code also contains the chip firmware, so I just had to look at the source code to see how to write the firmware to the chip. Basically you just write a bulk out transfer, with the firmware bytes prepended by three special bytes: [size & 0xFF, (size >> 8) & 0xFF, checksum & 0xFF], where size is the length of the firmware byte array, and checksum is just adding all the bytes in the firmware array together.
I've got this working on Linux now. macOS is the next step, and then I can go back to my Espruino code and get it working on the USB host shield.
So after getting the CP2102 user-space driver working on Friday, I started on writing a user-space driver for the Texas Instruments (TI) TUSB3410 chip. This is the same chip that I'm writing a driver for on the USB host shield, so now I'm porting my WebUSB version over to Node.js.
I haven't been successful in getting data back from the device just yet, but this should be much easier to debug than on the embedded USB host controller chip, so I hope to have an update tomorrow with some good news.
I've come down with some kind of stomach bug. I've been feeling horrible all day, but I am hoping that whatever this is will be over quickly.
I have also been thinking a lot about this Twitter thread today. While it's true that conventional gardening techniques will not provide the yield required to feed ourselves and our families, I do wonder if the increased yield from hydroponics, and the ability to grow year round, will make this feasible?
There are lots of things to do in the new house before we can move in. One of these is cleaning the carpets. Usually we get a company to do it, but this time round I wanted to see if I could it myself.
Here in the UK you can rent carpet cleaning machines from most supermarkets and hardware stores. They're all from the same company, Rug Doctor. You pay around £24 to rent it for 24 hours, and then pay another £10-£15 for carpet detergent[1].
The machine was easier to use than I expected. The most time-consuming part is refilling it with warm water and detergent each time. The actual cleaning part consists of pushing a button and pulling it across the carpet, timing it right to release the button before you turn so that you don't make the carpet too wet.
All in all, it was a tiring but reasonably rewarding experience in doing it myself, kind of like putting together Ikea furniture. I guess I might just do it myself again next time round.
Yesterday I mentioned starting on a Silicon Labs CP2102 user-space driver for Node.js. Well, I just managed to successfully read data from the device! The source code for the driver is already on GitHub, but I still need to write up usage instructions and do some testing.
I wrote it as a kind of WebUSB to node-usb interface, so that I can re-use parts of the code to easily port WebUSB drivers over to Node.js, or maybe I could even package the interface up as an NPM package? Then you can re-use your WebUSB drivers in Node.js by just by adding one line of code to import this package.
One thing that I found non-intuitive was that after sending a request for data as a USB bulk out transfer, you then either need to create another USB bulk in transfer to read data, or use node-usb's startPoll() function, which essentially starts polling for data on the IN endpoint. Also, if you're using endpoint 1, 0x01 is OUT and 0x81 is IN. You may find this code useful if you're trying to create a USB request type:
Today I started working on two user-space USB drivers for Node.js. The first one is for the Prolific PL2303 chipset. We have quite a few diabetes devices at Tidepool that make use of the PL2303, like the IR dongles used by the Animas pumps. When using this driver there is no kernel extensionon required on macOS anymore, and you can connect directly to the device over USB.
The PL2303 driver code was originally written by a former CTO of Mozilla, Andreas Gal. He co-founded an IoT company (Silk Labs), so my guess is that he wrote this driver for one of his IoT experiments, as it's on his personal GitHub profile. Silk Labs have now pivoted from IoT to embedded AI, so I doubt he is interested in maintaining his code. I've forked his repo and started adding some improvements, like specifying the baud rate. I also want to publish this as an NPM package.
In addition, I started working on a Silicon Labs CP2102 user-space driver for Node.js today. And once that works, I'm planning on porting my WebUSB Texas Instruments 3410 USB driver over to Node.js as well. User-space drivers FTW!
I've been enjoying a new e-mail newsletter by James Bowman of Excamera Labs. James is the creator behind awesome electronics projects like the Gameduino 2, a full colour touchscreen for Arduino.
He has a bunch of new projects at the moment, like the SPIDriver that let's you connect to SPI devices from your computer. And some of these projects he is building at home, as he explains in the latest edition of the newsletter:
For short-run through-hole PCB assembly, there's not much point in having these made abroad vs. making them yourself. Either way an 18-year-old with a soldering iron will be doing the work.
He pays his son $12 per hour for assembly and here is his argument on why it's a good thing:
It's also good just to get young people involved. Often when we're thinking of ways of introducing people to technology, we think of putting them in class. They already spend a lot of time in class! Much better to engage them in something practical and slightly unfamiliar. They seem to find it satisfying, and catching the inevitable failures gives them a hands-on insight into how things work.
I don't know what your high school work experiences were like, but I feel like maybe he's got a point. He goes on to explain how, due to Chinese manufacturers now selling directly online, getting electronic components doesn't have to be expensive. Buying 350 components of specific type would cost him $144 from a US distributor, while he could buy it directly from the Chinese manufacturer for $15.
In an earlier edition of the newsletter he describes how to make a “placement stencil” using a laser cutter, which makes it very easy to place components on a PCB by hand. Stencils for applying soldering past are also cheap nowadays, and you could get an IR reflow oven for a reasonable price as well.
In short, if you're making hundreds (instead of thousands) of something, it may just be easier and cheaper to do it yourself, even if said something is electronics.
On Sunday I made some bobotie and we had the leftovers for dinner tonight. It is a typical South African dish mainly consisting of mince meat with raisins and covered with an egg-milk mixture, baked in the oven.
We got a packet with the recipe and most of the required spices in South Africa when we last visited in February, and all the remaining ingredients are readily available here in the UK, including the South African chutney brand Mrs. Balls. I think it may be the only product on British supermarket shelves with Afrikaans instructions on it: “Skud die bottel”!
The Ananas is a three-dimensional PCB with LEDs that flash with different timings. It was great fun soldering it together in January, but I wanted a nice stand for it so that it doesn't fall over.
Luckily someone else had the same idea and posted a stand design to Thingiverse. I just printed it out and it works great!