November 18, 2023

Let's learn USB! -- use a Maple board

We are going to jump ship!!
No more blue pill!

The pill is a fine F103 board. The maple is bigger and more manly. It also has the USB disconnect circuit that I can manipulate in software (GPIO C12) and avoid bending over and unplugging/replugginf the USB cable. And I have these doggone things and ought to use them for something. Every change is more time and trouble than you would ever think -- but you always learn things too.

One thing I learned was that it was not sufficient to just connect SWCLK and SWDAT for the STLINK, I also had to connect ground. Not entirely surprising if you think about it at all.

Also the LED on the maple is on PA5 rather than PC13. But not only that, you must configure the GPIO to drive the LED with push pull. On the Maple, the chip drives the diode, while on the pill, the chip pulls the diode to ground. So for the pill you can configure the GPIO either way (push/pull or open drain). Probably open drain is better.

USB disconnect circuit

This is via PC12. If we do nothing at all, we get no benefit from using a Maple board. We reboot, the board sits. Linux is not even aware that the board is plugged in. A look at the circuit shows that the GPIO is an input, the transistor that could enable the 1.5K pullup is not enabling it.

If I now enable the gpio as an output and set it to one, on a reboot, linux sees the board "arrive" and a successful enumeration ensures.

If I now enable the gpio as an output and set it to zero, I get the exact same result. This is somewhat puzzling, but certainly works out OK. The enumeration goes very fast when the bit is set to zero.

So here is what does work. On reset, all GPIO get configured as inputs. When my code starts, I configure PC12 as a push/pull output. I get enumeration and everything works.
Later, to cause a disconnect when I get in the mood, I reconfigure PC12 again as an input, delay a while, then back to an output. This causes a disconnect and restarts enumeration. This satisfies me, at least for now.

Life with Maple

After far more work than I imagined, I am up and running using the Maple board. I just finished moving the MCU initialization code out of papoon and testing that my code in rcc.c works. All this was a good chance to learn and clean up some things.

And it is handy to have a reset trigger USB enumeration rather than having to bend over and grab my cable to yank it out and put it back in again. These little things are important and above all they maintain mental focus and clarity. One less thing to remember. Automation during code development is always good.

Baboon

I have started a new project: usb_baboon following on the heels of usb_papoon2 Clearly the names "papoon" and "baboon" are silly (but they rhyme). The idea with moving to a new "project" was to leave "papoon2" intact with its ability to analyze the packet traffic during enumeration with papoon. With "baboon" I have moved to working with the Maple board and intend to migrate entirely to my own code written in C.
Feedback? Questions? Drop me a line!

Tom's Computer Info / tom@mmto.org