CDC : Revengeance

This page is a collection of interesting information about the USB CDC library and the VCP library I built on top of it. Check it out once in a while, it’s probably going to grow every time I work with a new STM32 family, find a bug or add a feature.

1.1.         Deploying on the Nucleo-H743ZI2

The ST Nucleo-144 boards carry a USB OTG interface. OTG (On The Go) means it can work as either a host or a device, and even switch between those roles at runtime. This idiotic rule-breaking feature exists only because people didn’t want two different USB ports on their cell phones. Hence the name. And now people cry when their phone doesn’t have a headphone jack. Make up your mind, sheeple !

OTG make our lives harder because it adds a few wrinkles to deploying the VCP library. Let’s go through it together.

I’m going to assume that you’ve created a project for your Nucleo board using the default settings for the board peripherals. This means USB OTG is already enabled in your .ioc file and you should have six different pins configured for USB :

To understand what these do, I strongly suggest you peruse the manual and schematics for your board. There are slight differences depending on which Nucleo you’re using.

Basically, because of its ability to operate as a USB host, the OTG interface requires the ability to control VBUS among other things. As a device, however, we really don’t want to send voltage to the host.

If you’re into that OTG lifestyle, you probably know what you’re doing. Chances are, however, that you’re just looking to use your STM32 as a USB device. To do that, you will very likely need to open and/or close solder bridges on your Nucleo board. You’ll need to study your board’s documentation to determine what modifications are necessary, I can’t list them all. Be diligent about it : a mistake could result in permanent damage to your Nucleo but also to the unfortunate computer you plug it in.

In the case of the Nucleo-H743ZI2 (which is not the same as the older ZI design) you need to open solder bridges SB76 and SB77.

Next, let’s disable the SOF pin, which isn’t actually used on the board, as well as VBUS activation :

Notice that the relevant pins have turned from green to yellow. You should change the multiplexing to “Reset State”, which will be harmless to the electronics.

The OVCR pin is for overcurrent detection, a signal produced when a USB device tries to draw too much current from your Nucleo acting as USB host. This signal is meaningless in our scenario, so change the pin back to its reset state as well.

The PWR_EN pin controls the distribution of VBUS (5V) to the USB connector. This must never happen in a USB device. Again, return this pin to its default state. A pull-up resistor on the board will ensure that no juice goes to the USB connector.

You’re now back to just the D+ and D- signals a device needs :

In the Middleware section, nothing’s different : under USB_DEVICE, select the Communication Device Class middleware :

Depending on how the rest of your project is setup, you may also need to modify your clocking setup so that the USB device peripheral block receives 48 MHz.

From this point on, you can deploy the library by following the steps on the deployment page.