USB flash drive power problems
By Patrick Wigmore, , published: , updated
When I found that I couldn’t reliably record MJPEG webcam video onto a USB flash drive plugged into the Home Hub 5a, and the drive seemed to keep crashing off of the USB bus without saying goodbye to the host, I eventually came to suspect a power supply issue with the USB flash drive.
The flash drive was connected via a USB hub. I thought perhaps the hub wasn’t able to pass through the full power supply. The hub was a little bit battered and all of its USB sockets, including the mini USB for the host connection, were suspect for possible bad connections, because moving the hub seemed to cause issues too.
And bear in mind that I had previously modified the Home Hub to beef up the 5V supply to its USB port, which is where the USB flash drive was getting its power from.
Investigation
Plugging in different things
First, I tried plugging the USB hub directly into the Home Hub. I had been connecting it via a power splitter, which leeched off a 5V supply for the 380mA infrared illuminator. This more direct connection initially seemed to permit much more stable operation of the USB flash drive, with a run of 1200 frames achieved at about 15fps, which is about two minutes. But, based on later results, I think this was a fluke. There were still a very large number of dropped frames and eventually the flash drive crashed offline, once again.
The performance was only just below the required standard when running at 7.5fps, but again this was inconsistent and unreliable.
Note that I had already decided that the recording framerate was going to be 7.5fps, but it was interesting to test 30fps as well, to get a better idea of the capabilities of the storage device.
I also tried telling v4l2-ctl
to record with different numbers of buffers. The results were variable and inconclusive.
Next, I tried substituting a different USB hub. Once again, the USB hub was connected directly to the BT Home Hub, with no interstitial power splitter cable.
Initially, the new USB hub seemed to result in fewer dropped buffers at 7.5fps, but it ended the first 400 frame run with a flurry of dropped buffers which pulled the average frame rate below 7fps. Repeat runs were just as poor as those seen with the other hub. Using 1 buffer instead of 3 did seem to raise the average framerate significantly though.
Nevertheless, I persisted with the new USB hub and abandoned the old one, because the new hub’s physical connections were more robust than the first one’s.
I tried various combinations:
Storage device | Filesystem | Result |
---|---|---|
Integral USB flash drive | FAT32 | (Original drive – baseline for comparisons) |
PNY USB flash drive | FAT32 | no significant difference |
80GB USB 2.0 HDD | ext4 | partitions not recognised by OpenWRT for some reason |
Sandisk Extreme USB flash drive | FAT32 | consistent 7.49fps when aiming for 7.5, crash unmount at 30fps |
1TB USB 2.0 HDD | ext4 | Achieved over 27fps! Matches Sandisk Extreme in framerate for 7.5fps, but less consistent frame timings. |
Integral USB flash drive | ext4 | no significant difference |
(I had to install kmod-fs-ext4
to mount ext4 partitions, but this didn’t help with the 80GB drive. Maybe I needed to install support for a different kind of partition table.)
I hypothesised that, although hard disks require more energy than flash drives, their power consumption over time is less variable, and so they cause less voltage fluctuation, making them more resilient in the face of a weak power supply.
I tried reintroducing the power splitter cable, in combination with the ’new’ USB hub and the ext4-formatted Integral flash drive. The performance actually seemed to improve initially, but not indefinitely. Adding the IR illuminator didn’t seem to make a difference either. Then the webcam hardware seemed to ‘crash’ and needed unplugging and replugging.
In summary, nothing I plugged in was consistently performant.
Messing with the power supply
It’s a bypass. You’ve got to build bypasses.
Clearly it was possible to get enough performance from a USB mass storage device, but there was something a bit flaky about either the power supply or the USB signal integrity.
I decided to try measuring the voltage. With the Sandisk Extreme flash drive and the hub being powered through the splitter cable, but without the IR illuminator connected, I achieve a run that never dropped below 29fps. The voltage measured on another port of the USB hub did not fall below 4.72V, but that is relatively low.
Adding a (very slightly “cursed”) USB type A to type A cable between the power port on the power splitter and one of the downstream ports on the hub; effectively backfeeding power into the downstream side of the hub so that it didn’t have to pass through the hub circuitry; enabled the voltage on the hub output to stay above 4.75V at all times, keeping it within specification for USB.
Unfortunately, returning to the Integral flash drive, the performance was still not as good as with the Sandisk Extreme. I didn’t really want to use the expensive Sandisk Extreme for this project.
I guessed that if I could keep the voltage closer to 5V, all of the flash drives would work well. I also thought I should try adding a capacitor. If there was a lot of ripple on the 5V supply, then that could be enough to put the supply out of spec for USB when combined with the voltage drop.
Throwing capacitors at the problem
I tried some capacitors to see whether any of them make a difference to the performance. Empirically, I found that I needed a 1000µF capacitor in order to make a significant difference.
It was difficult to test the results without soldering the capacitor onto something, so I made up a (slightly more cursed) USB hub power bypass cable, with a capacitor in the middle. This is designed with a Type A plug and socket on one end, which connect inline with the hub’s Type A host connection and tap off power to backfeed into the downstream side of the USB hub. Glorious.
The cable did improve performance compared to not using it, but the arrangement fell short of acceptable performances. 7.5fps recording was mostly good, but occasionally dropped down to lower rates, was unpredictable, and always dropped frames. 30fps was not achievable.
I guess I should probably measure the voltage at some point
I put my multimeter in its DC volts “crest” mode (a high-speed min/max mode) to find the lowest transient voltage. At 7.5fps, the lowest voltage was 4.766V and at 30fps it was 4.736. If the USB specification requires a minimum of 4.75V, then these are very borderline.
Since the no-load voltage was less than 5V, I decided I needed to open the Home Hub up and tweak the voltage of the buck converter upwards slightly. 5.1V would hopefully mean the voltage at the USB hub only dipped to 4.85V, while 5.2V, which is still within spec for USB, would hopefully keep the hub at a minimum of 4.95V. All of these voltages ought to be acceptable to a reasonable USB device, I figured.
I also connected the USB hub’s power to the oscilloscope, AC coupled, to see what sort of ripple it might have. I noticed that it was the flash drive rather than the power supply which generated the vast majority of the ripple. Flash drives seem to have very “spiky”, bursty current draw.
Remind me, why did I glue the regulator in place like that?
Unfortunately, when I installed the 5V buck regulator into the Home Hub, I used its fixed 5V output option. Because of the way I’d permanently glued it in place, the solder pad to select the adjustable voltage option was inaccessible and the potentiometer to adjust the voltage was almost inaccessible too. Whoops.
Luckily, with a bit of careful soldering, I did manage to add a jumper wire that had the same effect as selecting the adjustable option, and I was able to use the head of a pin to rotate the potentiometer! It was really sensitive, but I eventually got it to 5.2V. I would have preferred 5.1V, but it was so sensitive that, when I saw it was reading 5.2V, I thought I’d better quit while I was ahead!
The increased voltage, combined with the USB hub power bypass cable containing the 1000µF capacitor, seemed to get things working. But I had been planning to buy a new flash drive to use in this project. My existing ones either didn’t have enough capacity, or they were too expensive to wear out with hours of video recordings, or I was technically already using them for something else.
Buying a less spiky flash drive
Clearly not all USB flash drives are made equal when it comes to power draw characteristics. If I bought a new one, I would run the risk that it would not cope with the power supply I was giving it.
Unfortunately, datasheets for USB flash drives don’t tend to include detailed data about the way they consume power.
It struck me that the very fast Sandisk Extreme flash drive was probably working well because I wasn’t really stressing it. Its maximum performance can only be attained using USB 3.0. If It’s designed to have acceptable power characteristics at top speed, it would make sense for it to have better than acceptable power characteristics at reduced speed.
It also struck me that power consumption equates to the production of heat inside the flash drive. A fast flash drive would need to be more power-efficient per byte written in order to avoid overheating, compared to a slower one. And a flash drive designed not to produce much heat might have a lower power consumption. What kind of flash drive would be designed to produce less heat? Well, I supposed, one of those little tiny ones that barely sticks out of the USB connector would have to produce less heat, because it doesn’t have much surface area to dissipate it. So, I bought a little tiny flash drive that barely sticks out of the USB connector.
Whether by luck or by design, the little tiny flash drive that barely stuck out of the USB connector seemed to do the business. It worked consistently fast enough to serve as the storage medium for the Hedgehog Camera’s recordings, provided they were only 7.5fps, which was the plan.