March 26, 2025

Black Pill boards - F411 USB -- tidy up the source code - part 2

Part 1 was getting long enough, but we aren't done yet!

Eradicate another callback scheme

I find this one hard to understand. It is within the "vcp" directory and controls calls from the CDC to the VCP layer. Indeed, the VCP layer is a specific way to set up CDC which is much more general, but this would only be useful if alternative (and useful) alternatives to VCP were available.

In the current context it yields only obfuscation, with absolutely no benefit, so let's get rid of it. There are layers of crazy name mapping. A structure named VCP_fops is set up and initialized with actual functions like VCP_Init(). But then this is mapped to APP_FOPS and that is used to make calls like the following, that I will change as shown:

APP_FOPS.pIf_Init(pdev);
VCP_Init(pdev);
Who knows what pIf stands for, perhaps "Polish International Federation", but that is just a guess -- but it is going away.

Another callback scheme -- and another!

Now we are shifting our attention to "library"

This one pops up in usbd_core.c. This one is USR_cb which governs calls to usbd_usr.c (note also: usbd_usr.h). This is only a 163 line file and deals entirely with manipulating 3 bits in a private variable "usbd_status". We can move all of this to usbd_core.c, get rid of two files and this callback and its associated functions. In fact almost all of usbd_usr.h can be deleted. Why not?

So, I did it, condensing and moving what was in usbd_usr.* into what I now call "core.c" (I renamed usbd_core.c after getting tired of the extra typing).

Another callback scheme! Could this be the last?

As I am examining usbd_core.c, I discover another lurking callback structure:

USBD_DCD_INT_cb
We will look at this later. It seems to govern calls from the driver up into "library" as a result of things that take place during interrupts. All the callbacks seem to be in core.c, so I may prefix their names with CORE_ and dive in.
Feedback? Questions? Drop me a line!

Tom's Computer Info / tom@mmto.org