A little help when programming Raspberry Pi Pico and compatible RP2040 and RP2350 boards.
After trying out the Raspberry Pi Pico, I became a big fan of this development board and other compatible ones based on the RP2040 and RP2350 microcontrollers.
One feature I really appreciate, in addition to its versatility, power and low cost, is definitely its support for programming via the UF2 file format, developed by Microsoft [1], which allows you to load firmware contained in a file with the .uf2 extension in the same way you drag a file to copy it to a USB stick.
With the Raspberry Pi Pico and compatible devices, simply press and hold the “BOOTSEL” button while connecting the USB cable to the computer, release the button and drag the .uf2 file into the window that will have opened on the screen.
The bootloader (the firmware preloaded into the microcontroller at the factory) has ensured that the computer sees part of the card's memory as mass storage, allowing us to flash the MCU with a simple drag and drop.
Many enthusiasts make their projects available online, complete with source code already compiled in .uf2 format, so they can be used immediately without specific programming skills. Even experts should appreciate the convenience of trying out a program “on the fly” or simply loading a blink.uf2 file to test the board.
However, if the operation described above has to be repeated many times in succession, it can become quite tedious to press the button while disconnecting and reconnecting the USB cable, especially if other hardware is temporarily connected to the board, not to mention the stress inflicted on the connector.
So, I thought of a very simple circuit to insert between the card and the computer, which, at the push of a button, interrupts the USB power supply (VBUS) for less than a second, just enough to simulate the disconnection and reconnection of the cable and open the device as mass storage.
In practice, connect the card to the computer via our circuit, the red LED will light up indicating the presence of VBUS, then:
press and hold “BOOTSEL”
briefly press the “Helper” button, the red LED turns off and then back on, you will see a window open on the screen
release “BOOTSEL” and copy (drag) the .uf2 file in to the window
The microcontroller automatically restarts and runs the program. It's definitely easier to do than to explain!
The Circuit
In the schematic diagram shown in Figure 1, the ground and data lines of the two USB connectors form a pass-through connection, while Q1, a P-channel MOSFET, is connected in series with the power supply line (VBUS) in a configuration known as a ‘High Side Switch’.
This MOSFET was chosen because it has a particularly low RDS(on) (on-state resistance) of 50 mΩ @ VGS = –2.5 V, as reported in the datasheet [2], thus minimizing the voltage drop. The rated current is greater than 2A, which is more than sufficient for the purpose.
The MOSFET behaves like an open switch when the gate is at the same potential (+5V, via R2 and R3), as the source terminal, but conducts if the gate is negatively biased with respect to to the source.
Figure 1: The schematic diagram
In fact, no negative voltage is required. For example, bringing the gate to a potential of +2V is equivalent to applying a voltage of -3V between the gate and source, which is sufficient to bring the device into full conduction. This is exactly what happens when U1 conducts, resulting in a characteristic voltage drop of 2V between the anode and cathode, just as desired.
The MOSFET switching is managed by a simple timing circuit, built around the U1 programmable shunt regulator, a TL431, better known for its use as a voltage reference in power supply circuits, which allows us to obtain a clean transition of the VBUS voltage, avoiding uncertainties and problems caused by the buttons' contact bounce. Figure 2 shows the VBUS waveform, traced with an oscilloscope, with a Raspberry Pi Pico board as the load, when the SW1 button is pressed.
Figure 2: VBUS interruption when SW1 is pressed
The interruption lasts approximately 900 ms and the transition from +5V to zero and vice versa is very sharp.
The application of the TL431 as a timer, shown in Figure 3, is suggested in the Texas Instruments datasheet [3].
The components strictly necessary are a resistor and a capacitor (R and C). In this case, the regulator acts as a comparator. When the switch is turned on, capacitor C charges through resistor R. When the voltage on the reference terminal exceeds 2.5V (the default threshold for the TL431), a maximum current of 100 mA can flow from the cathode to the anode, i.e. to GND.
In the diagram in Figure 1, the activation delay is determined by the values of R1 and C1 and can be calculated, with some adjustments, using the formula given in the datasheet.
Figure 3: TL431 as a timer, from the datasheet
The time required to reach the threshold voltage of the TL431, i.e. 2.5V, is therefore obtained using the formulaThe actual time measured on the prototype, probably due to the tolerance of C1, is approximately 900 ms.
To summarize, under normal conditions, C1 is kept charged via R1, the voltage on the reference terminal of the TL431 exceeds 2.5V and the TL431 conducts, negatively polarizing and also causing Q1 to conduct, powering the load.
When SW1 is pressed, capacitor C1 discharges, the reference terminal of the TL431 goes to GND potential, causing U1, and consequently Q1, to be turned off. The load is disconnected from VBUS.
As soon as SW1 is released, C1 begins to charge again via R1. After the predetermined time, the threshold voltage (2.5V) is reached, allowing U1 and Q1 to return to conduction, reconnecting the load to VBUS.
Prototype Construction
The prototype was built using a small piece of perfboard. Figure 4 shows the component side of the board.
Figure 4: The prototype, component side
I tried to keep the device small by using SMD components, except for the connectors, button and LED. Figure 5 shows the solder side of the board, where most of the components are located.
Figure 4: The prototype, solder side
It is definitely a good idea to insulate the circuit with a piece of heat-shrink tubing, preferably transparent, so that you end up with a small device that is safe to handle and easy to insert in series with the USB cables. Component List
Semiconductors U1 = TL431 SOT-23 Q1= FDN306P MOSFET SOT-23 D1= LED 3mm red Miscellaneous SW1 = Normally open button USB1 = USB-A male PCB connector USB2 = USB-A female PCB connector
Final Thought
Some readers of this article may have thought, “What a waste of time! All you had to do was cut a USB cable and insert a normally closed button!” My response would simply be, “I am a real electronics enthusiast, so this is pure fun for me!”
Veuillez saisir votre adresse électronique. Les instructions de réinitialisation de votre mot de passe vous seront immédiatement envoyées par courriel.
Discussion (0 commentaire(s))