Dual USB port design for automatic DFU bootloader entry (foolproof No Buttons!) - Page 1
Forum section: electronics / projects

author: Georgy.Moshkin
author_rank: Frequent Contributor
timestamp: August 20, 2025, 10:38:18 am
content: To make my PCB more foolproof, I'm using two USB-C connectors connected to a single USB port on the STM32 MCU. This completely eliminates the need for BOOTSEL buttons - not everyone understands electronics or the concept of holding buttons while plugging in USB cables.The second USB port solves an important usability problem: simple device recovery. While firmware upgrades normally happen through a custom bootloader, if power is lost during an update, this dedicated recovery port makes the device accessible to users of all ages and technical skill levels.At USB 2.0 speeds, the USB interface should be OK with paralleling DATA pins as long as it's kept short on the PCB (can add switches though). Here are two designs. The N-Channel MOSFET-based version is to ensure that 3.3V is applied to the BOOT0 pin only after the LDO output capacitor is charged and VDD is at 3.3v level (V_VDD = V_BOOT0).First schematic:1) When the cable is inserted into the "Upgrade Mode" USB-C connector, a resistive divider will provide 3.3V directly to the BOOT0 pin of the MCU.2) When the cable is inserted into "Normal Mode" USB-C connector, diode prevents from powering of upper 10k resistor, so BOOT0 is pulled down to GND by 20k resistorSecond schematic (with MOSFET)1) When the cable is inserted into the "Upgrade Mode" USB-C connector, gate of MOSFET is pulled down with 100k (MOSFET in OFF state), so the BOOT0 pin is pulled up through 10k resistor from the LDO output2) When the cable is inserted into "Normal Mode" USB-C connector, MOSFET gate has 5v VBUS applied through 1k, and the BOOT0 is connected to ground, making 10k pullup ineffectiveIdeas? Critique?

author: shabaz
author_rank: Frequent Contributor
timestamp: August 20, 2025, 12:19:00 pm
content: I think I partially understand what you're doing, but it does move the problem slightly in that the user may need to know which USB port to use for which circumstance, in which case the user instruction overhead seems about the same as instructing them to push a button.I've thought about it for the situations where the bootloader is accessed by via UART (i.e. a USB-to-UART is on the board) which is different to your scenario where you have a directly USB connected bootloader. With UART there are a few options, for instance, the possibility to send special character sequences, or UART break, or use the hardware flow control lines, and either use a little dedicated microcontroller (could be a cheap and tiny CH32V003) to intercept these kind of like an out-of-band comms, or use a few logic gates or transistors to detect certain scenarios. For instance, some Adafruit boards use a couple of MOSFETs and DTR and RTS to assert reset when required. I've messed around with using a couple of inverters and a timing capacitor and break sequence to do the same thing, from just the RXD, not requiring any flow control signals. Anyway, just throwing this out there as a suggestion for some scenarios, obviously it won't apply to yours.

author: Georgy.Moshkin
author_rank: Frequent Contributor
timestamp: August 21, 2025, 01:39:11 am
content: I understand what you mean. I forgot to mention that PCB boards will be shipped to the users without any firmware (except STM32 internal DFU). Basically, I want to avoid two uncertainties: 1) user communicating with the PCB assembly house to ask to flash the board, 2) DFU update process is interrupted during upgrade.In both cases boards may end up unflashed with high probability. I see the second USB as a remedy that allows to explain it easily with the video of upgrade process: PCB has a clear silkscreen near the USB, and visually it's much more certain than testing coordination with pushing the button while inserting the USB cable. I think that I've already decided how to implement this, but thought that asking a question and providing schematic may be beneficial in some ways.

author: shabaz
author_rank: Frequent Contributor
timestamp: August 21, 2025, 02:22:19 am
content: Another add-on idea after you have developed your product, maybe you've already considered, is to supply a QR code or similar, maybe even on the product (might not always be sensible) that directs the user to a product page for the firmware file location, and a YouTube video for several languages showing your final product, so users can see where to connect the USB cable and do the transfer.I gave it a quick stab for the Pi Pico a while back in this video, although this isn't for consumers and still assumes some knowledge:It's easy to forget, that although it seems obvious to just hold a button, in reality if you've never done a firmware upgrade before, then you're going to be unsure the first time, especially when text wording in instructions might end up ambiguous, whereas watching someone do it provides additional reassurance. So I can understand for sure why you're aiming to improve the process for non-experts.

author: coromonadalix
author_rank: Super Contributor
timestamp: August 22, 2025, 02:23:22 pm
content: while i can understand some people are non tech savy using 2 usb port is kinda useless, if you do provide a clear way to do an upgrade path,people should be able to understand if they don't read, it's their problems if it fail, but it will come back at you ...or build an unit with some pin hole switch ...you can not substitute human behavior, bad or good, provide a paper, a manual etc ... and make it available ...some will forget the second port REAL usage and will say and cry i doesn't work or else ....adding a second port does add more possible hardware failures if someone badly manipulate it ...you could even design some dfu or other bootloader type IE: like a small drive who appears once connected, push the FW update file in it, disconnect and reboot ... no button pressedwhat is you upgrade procedure : an usb key with a defined file type ? sd-card ? a flash loader ? do you provide a jtag spi header or other ways to recover a bricked unit ?do you issues warnings like the famous DO NOT CUT POWER WHILE DOING UPGRADEmy pun would be shipping unit without any FW, are your units rugged / industrial / plc / controller or else ? what status does it have when no fw in it, can it become dangerous if fully connected, can it trigger problemswill it undergo certifications ?no pun you try to avoid human usability but in a sense you're creating a few yourself, you will never be able to avoid human mistakes, wrong manipulations etc ...you can put in place good procedures and informations, closed softwares or ecrypt / protect ... and provide way to recover if anything did go bad,but in the end the client will need to do his part ...

author: Georgy.Moshkin
author_rank: Frequent Contributor
timestamp: August 23, 2025, 04:25:37 am
content: Quote from: coromonadalix on August 22, 2025, 02:23:22 pmMy product is fully digital in a sense that it's a thoroughly documented project with design files ready to be manufactured using online PCB service. I hope this makes my reasoning clearer. The first upgrade of the board can be performed through any of 2 ports thanks to empty chip's factory bootloader logic. After a first successful upgrade with my custom firmware, it becomes virtually unbrickable and upgradeable: bootloader sector is write-protected, and any upgrades are booted into only if checksum is correct.In this scenario any jumpers/buttons/dip switches are unnecessary. For instance, 2.54mm jumpers affect slick design of the board and require sourcing of jumper which can't be part of SMT assembly; dip switches are not very practical and may require to use tweezers; buttons increase risk of accidental ESD discharges and additional stress on the board and surrounding components by pressing finger.There is a clear upgrade path: after first successful upgrade, device can be upgraded anytime even without unplugging it from USB, because everything is nicely handled. Now, if something went wrong during the first upgrade using chip's internal factory bootloader, there is a need for some solution. Button indeed can be a solution, but only if it's single press without need to test user's coordination with "inserting the usb while pressing the button". Therefore, the button should manipulate USB D+ to trigger re-enumeration and control MCU's reset pin. This is actually a good solution that may be better than dual USB.Quote from: coromonadalix on August 22, 2025, 02:23:22 pmCurrently there is no enclosure is planned unless someone design it on their own. A bare PCB that can be mounted on smartphone stand (PCB width is the same as smarphone's width)Quote from: coromonadalix on August 22, 2025, 02:23:22 pmThis is a possibility, that's exactly why I thought about dual USB solutions: it's very easy to demonstrate in the video, and it includes a whole bunch of manipulations: unplugging, translational movement, plugging-in. It's much harder to demonstrate with a button: vertical movement of the finger is extremely tiny for the SMD button, yet some users may assume it's a capacitive touch button. And, as I've mentioned before, a possible mechanical stress on the PCB and surrounding components, some people have large fingers, etc. I banned dip switches and jumpers from my project because they are generally not user-friendly. Note that we need to consider not only the ability of end user to perform some operations, but the current mood as well. Imagine if you are not proficient in electronics and something does not work. Your anxiety and disappointment on a rise, and then someone prepared a quest with a button or some tiny dip switches and tweezers. Instead, we need to provide something that user is already familiar with: "Unplug USB cable? I can do that." And we have minimized the number of manipulations: should you keep the button pressed before or after unplugging the USB? For how long? When to press the button? The same with dip switches and jumpers. Uncertainty! With the Dual USB ports there are only three states which user will go through naturally, without need to remember what they have already tried.Quote from: coromonadalix on August 22, 2025, 02:23:22 pmThere are all kinds of nice stuff can be done, but the board will be shipped from the PCB fab without any firmware. The first upgrade may fail because the empty MCU's embedded bootloader does not have any features to prevent this (I think so, going to check this later).Quote from: coromonadalix on August 22, 2025, 02:23:22 pmI think that recovery through sdcard/spi/jtag is unnecessary. There will be unpopulated SWD (serial wire debug) connector, but that's all. SD card is too uncertain: adding more quests for the user with FAT32/NTFS formatting, copying a file, etc. All this unnecessary stuff that may be good for embedded engineers but only adding problems for an ordinary user.Quote from: coromonadalix on August 22, 2025, 02:23:22 pmNo, it's a fully digital experimental product that can be turned by the user into a physical fully populated PCB by using online services. Depending on the user proficiency, customizations can be made to the hardware or software part of the design. I am not going to solder, assemble or ship anything. I know what you mean, but all these applications you've listed are too niche and do not resonate with my vision, and not compatible with the approach. Idea is to provide access to the design, which is ready for manufacturing, yet changes dynamically over time. Experiment with technology applications for entertainment, audio&video and similar applications.Quote from: coromonadalix on August 22, 2025, 02:23:22 pmIt's good that your post made me re-evaluate the idea and I appreciate this. I am still more interested in practical implementation, the schematic itself. I still convinced that the dual-USB approach is good one and pretty determined to use it. Button may be good but remember large fingers, timing uncertainty and it's quicky becomes an irritating time-wasting experience. I need user experience with a faster outcome, even if it doesn't work, I need to shield user from doubting their own proficiency. Just imagine you have project design files and a single explanatory video. In my opinion, dual USB is a winner here both visually and practically.