anelok: a bit of USB

Werner Almesberger werner at
Sat Oct 26 18:06:39 EDT 2013

To test how the device performs when on USB power, I added support
for measuring the supply voltage (should stay at 3.3 V when powered
from 5 V USB) and also the temperature (since there is a temperature
sensor in the chip and it would be a shame not to use it.)

There are still a few bits of weirdness in the ADC code, but after
a few tries, it gets plausible results and then continues to do so.
With this, I verified that the system voltage does indeed stay at
3.3 V when I ramp up the USB voltage from ~3.3 V to 5.5 V.

Then I added activation of the USB module. The chip's reference manual
does a good job at steering the reader around finding the last clock
gate one has to enable for the USB module to work at all, but I
eventually found it.

The firmware can now detect:
- USB A: USB ID is pulled low by the cable,
- USB B: USB ID floats and we receive SOFs,
- no USB: USB ID floats and we don't receive SOFs.

Here's a screenshot:

The 39.730 MHz clock frequency shown is before switching to the
crystal-based RF clock. After, it would be 48.000 MHz, as required for

The precision of the temperature is a shameless exaggeration - the
theoretical maximum resolution the hardware could possibly achieve is
about 0.1 K and in reality I'm lucky if measurements don't vary by
more than one degree.

The next challenge will be a the USB stack. Freescale actually provide
one but it's under a messy license. Well, it's not that I hadn't done
this before, and the USB controller actually looks fairly nice, even
if the documentation is particularly cryptic.

- Werner

More information about the discussion mailing list