Bootloader - a pin for the usb d+ disconnect

Bootloader for boards that don't have the addition hardware found on the Maple mini, which resets the USB
User avatar
Pito
Posts: 864
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Bootloader - a pin for the usb d+ disconnect

Postby Pito » Fri Aug 12, 2016 4:39 pm

I've learned how to compile a bootloader with the green LED placed on a pin of choice, but I have not understood fully how it is with the PIN which disconnects the D+ for the usb enumeration.
In the hardware.c there is a comment "we do not do it with PC12" (even I saw there was a setPin(C,12) before in the source), maple mini uses PB9 for the disconnect, and Jaromir in his excellent soldering guide is using PB10 - why?
Also I've read somewhere we do it via PA12 (D+) today (no external transistor needed).
So where in the sources we can set a pinXY for the usb disconnect (with the external transistor)?
PS: I want to use PB2 (boot1) for that..
Pukao Hats Cleaning Services Ltd.

User avatar
Pito
Posts: 864
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: Bootloader - a pin for the usb d+ disconnect

Postby Pito » Fri Aug 12, 2016 6:20 pm

Ok, in usb.c lines 54-55 is the def for the BP disconnect pins.

BTW, a closer look at the MapleMini 2 transistors disconnect switch reveals there is a nice trick built in - the base of Q2 is powered from USB_5V (VUSB pin on the usb connector) - thus the Q2 cannot toggle the 1k5 resistor when the USB cable is disconnected. The resistor is then floating, for any DISC voltage level. So the circuit is fully off and you can toggle DISC as you wish.
8-)

With the BP's high-side Q1 pMosfet switch it may work similarly as the MM when the source/emitter of the transistor Q1 will be connected to VUSB (what is not the case when connected to 5V or 3.3V Vcc). So when connected to 3.3Vcc any logic change at the DISC signal will toggle the 1k5 resistor, not good.. :(

MM USB Disconnect.JPG
MM USB Disconnect.JPG (41.23 KiB) Viewed 429 times
Pukao Hats Cleaning Services Ltd.

User avatar
RogerClark
Posts: 5470
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Bootloader - a pin for the usb d+ disconnect

Postby RogerClark » Fri Aug 12, 2016 10:05 pm

Can you post a the part of the BluePill schematic you are referring to, as I didnt think it had any USB reset hardware.
What we do to reset the USB is basically a hack ( but thats the only option unless you change the BP hardware)

User avatar
Pito
Posts: 864
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: Bootloader - a pin for the usb d+ disconnect

Postby Pito » Sat Aug 13, 2016 12:13 am

@Roger - for BP's external DISC circuits I refer
the fredbox's bipolar:
http://www.stm32duino.com/viewtopic.php?t=780
and Jaromir's pmosfet hack:
http://www.stm32duino.com/viewtopic.php ... mos#p12933

A difficult to understand settings and processes with DISC pins, even weird imho :)

Basically we have two places where we handle the 1k5 resistor at USB's D+ :

1. in the bootloader, DISC pin defined in config.h (maples) or in usb.c (generics) - line 40+, DISC used in usb.c
===============================================================================================
- for Maple we: set the DISC pin as OpenDrain, then set it to 1, set it to 0, and that is it..
- for MM it is PB9

- for generic we: set DISC pin as PushPull, then set it to 0, wait about 50 useconds (??), set it to Input (let it float), and that is it..
- for generic it is PA12 (D+)

Signaling based on DISC pin level:
A. MapleMini:
log0: we pull D+ weak high via 1k5
log1: we let the D+ float (1k5 disconnected from Vcc)
B. Generic:
log0: we pull D+ hard low
Input: we let D+ be pulled weak high via 1k5


2. in the core - DISC pin defined in board.h - DISC pin is used for cdc connect and disconnect in usb_serial.cpp - line 60-90
===========================================================================================================
- for MM it is PB9
- for generic it is PB10 (??)

Signaling based on DISC pin level:
A. for MM we pull D+ weak high via 1k5, or, we let the D+ float (1k5 disconnected from Vcc)
B. for generic we pull D+ hard low, or, we let D+ be pulled weak high via 1k5

:?
Last edited by Pito on Sat Aug 13, 2016 12:43 am, edited 1 time in total.
Pukao Hats Cleaning Services Ltd.

User avatar
RogerClark
Posts: 5470
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Bootloader - a pin for the usb d+ disconnect

Postby RogerClark » Sat Aug 13, 2016 12:35 am

I have not looked in detail at the USB reset, but the MM is definitely different from the Generic method

In the sketch, I think MM sets DISC (High) to reset the USB, this pulls D+ to USB (Vdd). MM then leaves DISC set to 1 .
I presume USB DP is pulled low by the host (PC)

The Generic does not have a way to disconnect the 1.5k from Vdd as its permanently pulled high, so the trick is to set the pin as GPIO and drive it LOW, then release the GPIO pin, so that USB DP is pulled high by the 1.5k

The difference between these 2 methods, will be that on the Generic board, as soon as it is plugged in USB DP will be High (on the MM it will initially be Low). After some "setup" time USB DP is driven low and then released.

So there is a delay between the board being connected and USB DP going from Low to High.

I can't remember what the bootloader does. But I presume it must reset DISC (on MM) to Low, for some time, then set DISC so that USB DP can be pulled high via the transistor.


BTW. I think the USB spec says that USB DP should not be driven low by the target, but we don't have any choice - and normally it works OK.

User avatar
Pito
Posts: 864
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: Bootloader - a pin for the usb d+ disconnect

Postby Pito » Sat Aug 13, 2016 12:55 am

With an external pnp transistor or pmosfet, which switches the 1k5 resistor against Vcc ( so called high-side switch) there are only 2 states with D+ , based on DISC pin signal level:

1. D+ is pulled "weak" high via the 1k5 resistor to Vcc,

2. D+ is not pulled weak high, D+ does not see the 1k5 resistor (a high impedance), as the 1k5 resistor is disconnected from Vcc.

There are none such DISC pin levels where the D+ could be pulled hard low, weak low, or hard high..
Pukao Hats Cleaning Services Ltd.

User avatar
RogerClark
Posts: 5470
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Bootloader - a pin for the usb d+ disconnect

Postby RogerClark » Sat Aug 13, 2016 3:45 am

@pito

Yes. I suspect using a FET is the best system. I did try to modify a GD32 board to add a P Channel FET for Reset but didnt manage to make it work, however I suspect I had some problem with the clock speed on the GD32 vs the STM32 wen trying to use the MM code in the bootloader

User avatar
Pito
Posts: 864
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: Bootloader - a pin for the usb d+ disconnect

Postby Pito » Sat Aug 13, 2016 9:39 am

I've been messing with the PB2 as the DISC pin.
It has got a 100k resistor builtin on the pcb (R4) in series with the signal, but it must not be a problem with a pmosfet (provided we do not talk about 15ns long pulse, the RC of this circuit is about 40usecs).
However, I cannot get it working on PB2.
Built a new bootloader with PB2 and with maple hardware option. It does not find the DFU..yet..
PB2 disconnect.JPG
PB2 disconnect.JPG (12 KiB) Viewed 402 times

IT DOES NOT WORK WITH THESE RESISTORS VALUES..
Last edited by Pito on Sun Aug 14, 2016 11:11 am, edited 1 time in total.
Pukao Hats Cleaning Services Ltd.

User avatar
RogerClark
Posts: 5470
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Bootloader - a pin for the usb d+ disconnect

Postby RogerClark » Sat Aug 13, 2016 10:34 am

@pito

I think I had similar problems, I tried using a P FET to reset the USB on a GD32, but it didnt work.

And I didnt have time to debug the hardware or software.

I still have the GD32 board with the PFET on it, so I will try to look at the waveform's tomorrow with my oscilloscope to see it I can see why it doesnt work

User avatar
Pito
Posts: 864
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: Bootloader - a pin for the usb d+ disconnect

Postby Pito » Sat Aug 13, 2016 11:14 am

I've changed the DISC pin to PB12 to make the stuff easier to debug. No 100k resistor in series with DISC signal now. The 10k resistor (D+, Vcc) on the BP's pcb removed. I also have replaced the 1Meg resistor with 68k to speed up the circuit, but no change.

After I press hw reset (during the reset button is pressed down the 1k5 is disconnected):
1. it switches the 1k5 to 3.3V
2. Windows bells and enumerates immediately and in the device manager I see the DFU driver, green LED blinks aprox 3Hz
3. it keeps 1k5 switched to 3.3V for another 8 secs, DFU still in dev manager visible, green LED still blinks
4. after 8 secs it disconnects the 1k5, win bells and the DFU disappears from the dev manager, green LED stops blinking.

Upload from arduino does not work, it cannot find DFU.
:?
Pukao Hats Cleaning Services Ltd.


Return to “Generic bootloader”

Who is online

Users browsing this forum: No registered users and 1 guest