2026-05-21 8:53 AM - last edited on 2026-05-21 8:56 AM by mƎALLEm
Hi,
I'm using the STM32C071K8U6's built-in USB DFU bootloader for one-time production programming. After flashing, PA11/PA12 (USB D+/D-) are used as regular GPIO outputs to control two P-MOSFETs (each with their 100kΩ gate pull-ups to 4.2V).
The USB functionality is not used by the end customer, but the USB connector remains accessible for charging. This means a PC's USB cable may be connected during normal use allowing for potential signal injected into those traces resulting into the PMOS being turned on/off by the PC if it detects there is a USB device connected and tries to enumerate it.
The two core issues:
a) When a user plugs into a PC for charging, we need to guarantee the host does not attempt enumeration, and that nothing the host does on D+/D- interferes with our GPIO-driven MOSFET gates.
b) because the PA11 and PA12 traces also go all over the PCB - i.e. they form very long stubs - we need to make sure this does not prevent the USB from working properly during that one time DFU happens in production.
Questions:
Thank you as always!
2026-05-21 9:14 AM
You should have shown the USB connector, too.
> Is this the correct approach to guarantee the host does not detect the microcontroller as a peripheral — i.e., ensuring it never attempts enumeration, thereby guaranteeing zero interference with the P-MOS switching
No.
Host observes the DP/DM pins and as soon as one of them goes high (DP for FullSpeed and DM for LowSpeed), it starts the enumeration by pulling both pins low. And it is even worse in your case than just "interference with MOS switching": in the normal USB setting, this initial DP/DM pulling up is through a 1k5 resistor which limits current flowing from + to host's transistor pulling the bus low; but here if you switch DP/DM to high as GPIO, there's nothing which would limit this current, potentially leading to damage.
I'd recommend you to use two physical jumpers or any other form of physical disconnect for the initial programming. Another and maybe better option would be to use some other means for connecting USB for initial programming than using the connector which you intend to use for charging during usage; that connector then can have DM/DP unconnected.
I also encourage you to experiment using the respective Nucleo board; but avoid the conflict outlined above.
JW