cancel
Showing results for 
Search instead for 
Did you mean: 

Is it safe to reuse USB D+/D- (PA11/PA12) as GPIO after one-time DFU programming?

Ricko
Senior III

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:

  1. Attached is the schematic of how I am thinking of implementing this. 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 — while still allowing reliable DFU programming during production?
  2. if that is correct, are the values in my schematic correct (100% safe to achieve the goals)?
  3. I am fairly certain of the following but would like confirmation: despite using the USB pins for DFU during production, because PA11 and PA12 are used only as GPIOs at runtime, we should configure them as GPIOs in CubeMX from the outset — rather than configuring them as USB and then changing them to GPIO in firmware. Is that correct?

Thank you as always!

 

Ricko_0-1779378108139.png

 

 

1 REPLY 1
waclawek.jan
Super User

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