5 Hardware Setup
Levi Pearson edited this page 2022-03-09 10:04:51 +00:00

Hardware Setup

"Blue Pill" Board

Jumpers

The board comes with 2 jumpers; for normal operation they should be placed so they bridge the center pin with the one marked "0". Other positions can be used to change the boot mode, but we won't need to do that.

Headers

The long sides of the board each have a series of 0.1"-between-center plated through-holes. You can solder wires and component leads directly to these, but for the sake of re-use it is often preferable to solder in headers, which are supplied.

If the headers are supplied in one long strip, place the long end of the headers into the holes on one side, lining up one end of the header strip with the end of the board. Mark the position between the last pin that fits in a hole (it should be 20 pins down) and then remove it and cut or snap the header cleanly at the marked point.

Decide if you want wires to attach to the top of the board (where the jumpers are already sticking up) or the bottom (which will make it easier to reach the reset button). The bottom orientation is also convenient for putting the BluePill in a solderless breadboard. Now, put the short end of the headers into the row of holes on one side of the board. Hold it or prop it in place while you solder one joint from the other side.

At this point the header will most likely be a little crooked, but it will be held in place by the hardened solder joint. Apply light pressure in the direction that would straighten it with one hand while you re-heat the solder joint on the other side until it's just hot enough to allow the header to be adjusted straight. Remove the iron and hold the header still for a moment until the solder cools. You might need to repeat a time or two to get it right, but it's far easier with only one solder joint.

Once you are happy with the header's position, solder in the rest of the pins from the back. Make sure the iron is heating both the pin and the plated hole for a moment, then bring the solder to the junction. It should flow down into the hole and around the pin, forming a nicely filleted joint, but it may take some practice before that happens reliably. If you have trouble, ensure that your iron tip starts out "tinned", i.e. with a coating of melted solder on it. This coating should be substantial but not a blob; it helps to conduct heat from the tip to the components you are trying to solder.

STLinkV2 Clone Debugger

You need to connect the the debugger (which looks like a USB flash drive with a connector at its far end) correctly to the Blue Pill board in order to power it, load programs, and debug them. The debugger has 10 pins on its connector, but only 4 need to be connected to the board.

  • 3.3V
  • GND
  • SWD (SWDIO)
  • SWCLK

The wires connect to the right-angle headers on the narrow side of the Blue Pill board opposite the USB connector. The labels are on the underside of the board.

There are a couple of different varieties of STLinkV2 Clone debuggers, and their connectors have different pinouts. It is extremely important that the pins with matching labels are connected. The legend for the pins is printed on the debugger, and the right-hand column of labels corresponds to the bottom row of pins if the debugger is laying on the desk with the legend facing up at you.

When you are sure that the wires are connected correctly, remove the cap from the USB port on the debugger and plug it in to a powered USB port (this can be just a USB power supply if you want to be cautious about shorting out your computer's USB ports). You should see a light on the side of the debugger, and there should be a power light along with the blinking light on the Blue Pill.

OLED Display

This display requires 4 wires to attach as well:

  • GND
  • VCC (3.3V)
  • SCL (B10)
  • SDA (B11)

There are other possibilities for connecting SCL and SDA, but the example code uses these ones which hook to peripheral I2C2 via pins managed by GPIO B.

Rotary Encoder

The encoder has a right-angle pin header with 5 pins:

  • CLK (A8)
  • DT (A9)
  • SW (A10)
  • + (3.3V)
  • GND

There are other possibilities for connecting CLK, DT, and SW, but the example code uses these in GPIO mode via GPIO A.

USB Resistor Fix

Note: This isn't necessary for the workshop, but you may want to do it for your own projects

To use the Blue Pill as a USB device, a hardware mod may be required due to a design flaw that persists on many of these inexpensive boards. USB requires a pull-up resistor on the D+ line of a specific value; while some host adapters are tolerant of weaker pull-ups, others are not and will fail to enumerate the device. Fortunately the fix isn't hard.

Check the resistor labeled "R10" on the back side of the board. The correct value is 1.5kOhm, which should be marked "152" on the tiny resistor. Common incorrect values are 10kOhm (marked "01C" or "103") or 4.7kOhm (marked "472"). If you have an incorrect value, you might try connecting it via different USB ports and hubs to see if any work as-is, but if not, you'll have to modify the board.

These are 0603 size surface mount resistors, which are extremely inexpensive from standard component distributors like Mouser, Digikey, etc., but they can require some skill and patience to replace with tweezers and a soldering iron. If you are not up to that, you can hook a small through-hole resistor between PA12 and +3.3V pins, which places it in parallel with the one at R10. See this resistance calculator for help picking resistors; depending on what values you have available and what R10 is, you may need more than one.

If R10 is 10kOhm, 1.8kOhm would be close to ideal, but you are more likely to find a 1.5kOhm and it is likely to work. If R10 is 4.7kOhm, a 2.3kOhm would be close to ideal, but you are more likely to find a 2.2kOhm or 2.7kOhm, and either would be likely to work.

If USB still does not work, it is sometimes the case that the USB connector is not soldered properly, and reflowing the USB solder joints can get it working.