From The Relativty Wiki
Revision as of 11:49, 9 May 2019 by Relativty (talk | contribs) (Marked this version for translation)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Other languages:

The STM32 board and an MPU-6050 as the Relativ tracker

The STM32 tracker code was developed from our original Arduino Due tracker code by Saraghz.

I've assumed that anyone building this tracker is probably not a hardware guru, but instead is just starting out with STM32 boards. Please forgive me if parts of these instructions are rather basic, & definitely please correct anything that you find that's wrong, or misleading. I've done my best to to keep things like soldering down to the barest minimum (there's a couple of minutes worth that couldn't be avoided), but apart from that it ought to be straightforward enough for a competent beginner to tackle in a single evening, once all of the bits of kit have been delivered.

Section 1: Getting your Hardware

You will need:
An STM32 board (model number STM32F103C8T6)
An ST-Link v2 USB Adapter
An MPU-6050
At least 5 F/F Dupont cables or 0.5m of wire
A soldering iron and some solder


Required software:
The standard Arduino IDE package
The ST-Link Windows drivers (please read below before downloading this)
The ST-Link utility (please read below before downloading this)
Roger Clark's STM32 Software and tools

WARNING - Do not plug in any hardware until you are told to

Fun and games with bootloaders (part 1)

VITAL - You may or may not get an STM32 with a bootloader. This is just the luck of the draw (unless you buy a genuine Robotdyn Black Pill from Robotdyn themselves, see later for details). However, if your board doesn't have a bootloader, it will appear to be Dead On Arrival (DOA). It takes about 30 seconds to fix it, but it is really important that this is the first thing that you do once you have got your software organised. Without checking this first, everything else will completely fail. Fun and games with bootloaders (part 2) later in this Wiki walks you through all of this, as this is one of the biggest Hardware gotcha's that you'll come across when dealing with an STM32 board.

Purchasing your STM32 board

A quick note on buying hardware

The STM32 boards seem to be bleeding edge tech. They may only cost a couple of dollars/pounds/euros each, but two thirds of the STM32 kit that I bought from eBay whilst preparing this wiki were Dead On Arrival (DOA). I spent days faffing around, trying to troubleshoot software, firmware & drivers for boards that actually turned out to have been faulty from the beginning... Under Windows 10, once you have installed the software & drivers (following the instructions below), and checked your bootloader status (flashing one if required), your hardware should just work, straight away, straight out of the box (OK, packet). If it doesn't, assume the hardware is DOA rather than wasting time faffing around with your software. If you plug the USB end of an STM32 into your computer (please install the drivers first, see below), it should instantly be recognised as a known device. If it isn't, & you definitely installed the drivers first, then it is probably one (of the many) STM32 boards that have dead USB ports. Likewise, if you jack in the pins on the other end of your STM32 into your ST-Link (having double-checked your pins are correctly connected, and having gone through the bootloader tests) & you can't flash it, assume that the board is DOA rather than assuming that your software is somehow wrong & wasting days pulling your system to pieces & reinstalling everything trying to find a problem that doesn't exist. Sadly, I assume that this is why the packs of three or five STM32 boards are so popular on eBay - because the failure rate is so high... There are actually very few software glitches that you will encounter, all of which should be detailed in the instructions below. Once you get a a good STM32 and a good ST-Link USB Adapter, it really does just take a few seconds to get it up and running...

WARNING: A great many STM32 STM32F103C8T6 boards are available, and the choice can quickly become quite daunting. Unfortunately, many of the cheaper clones also have the quite serious hardware issues that I touch on below. These are detailed in the STM32 Wiki in their Known Issues section. Basically, the worst of the cheap clones have the wrong pullup resistor value for the R10 resistor that's soldered onto the board, which stops the USB from working. They are also very badly soldered together, so the USB pins aren't properly connected and the USB socket is very weak & prone to falling off, as are the other components.

Whilst buying an STM32 would appear to be a complete lottery, there may be a way of finding a worthwhile board without resorting to randomly buying one and waiting for it to be delivered in the post. The trick, however, is all in the details! These are very simple boards, with few visible components. The only component that obviously varies to the naked eye is the reset switch, which oddly enough appears to help quickly identify better Blue Pill boards! The boards seem to fall into three different categories: Dirt cheap and prone to problems; Slightly more expensive and slightly less prone to problems; and Robotdyn Black Pills, which are well built and reliable.

From what I have currently experienced, the cheaper Blue Pill boards have round switches, mounted parallel to the long side of a blue board. The better, marginally more expensive Blue Pill boards have rectangular switches, again mounted parallel to the long side of a blue board. However, the top of the range, custom Black Pill boards have switches parallel to the short side of a black board and some other, more obvious details. For the record, Blue Pills are called Blue Pills because the board is coloured blue (& because originally, someone liked the film The Matrix). Proper Black Pills have black boards, are only made by RobotDyn, and have RobotDyn STM32 MINI printed on them. Naturally, there are also black boards appearing from the Chinese clone houses which are probably best avoided for now, as they are yet another completely unknown quantity.

Unfortunately, this is all mostly theoretical, YMMV, it could all change as another batch ships out from the factories, and its all a bit of a lottery anyway. It's only based on the good handful of boards that I've had to play around with. Even the genuine Robotdyn Black Pill boards are pretty cheap, but it is something that you need to be aware of, especially if you are using the ultra-cheap Blue Pill boards. Hence the packs of three and five available on eBay. These are my own, very subjective experiences. I made a great many mistakes and bought an awful lot of junk whilst I was ironing out the glitches in the procedures that became these instructions. Hopefully they will help you to make less mistakes than I did, and to dig yourselves out quicker than I was able to.

Whilst there are ways of fixing the R10 resistor problem and it's relatively easy to resolder the USB port if you do end up buying a substandard board, it is so much easier not to have to any of that in the first place by buying kit that just works first time. That's why we have standardised on using the Robotdyn Black Pill boards, because they are far more reliable and the build quality is reliable. It's also almost impossible to troubleshoot an intermittent hardware fault on a dodgy Chinese clone Blue Pill board via an Internet discussion forum, so you will save yourself and us all a great deal of time by getting the best quality board that you can. Whilst you can plough through eBay or Amazon, the simplest and best way of getting a genuine Robotdyn Black Pill board is to buy it from Robotdyn themselves. The can ship your Black Pill to you from Hong Kong in a week or two, which is comparable with anywhere else that you can buy one. You want the $3.89 STM32 ARM Arduino Mini System Dev.board (blue pill) with Arduino bootloader with the soldered headers. Yes, we know that they call their boards Blue Pills, even though they are Black, and the rest of the Internet calls them Black Pills - life's like that sometimes.

A quick note on header pins


The less you pay for an STM32 board, the less likely you are that the header pins on each side of the board will have been soldered in at the factory. That's another good reason for buying a Black Pill board, as you have the option of paying an additional 40¢ for the soldered headers when you buy it - which is what we advise you to do, oddly enough. Don't forget, your MPU-6050 almost certainly comes with the header pins unsoldered, although it has a much more manageable eight pins. If you have a Black Pill that already has the header pins soldered, then all you need to do is to solder in the MPU-6050 headers and you can use your F/F Dupont patch cables to hook it all up in a matter of seconds. This is the easiest and most flexible approach, and is what I would generally advise doing as it will save you a great deal of time and effort.

Purchasing your ST-Link v2 USB adapter

As you can see from the photos above, The STM32 boards have header pins on either of the long sides. They also have a USB port on one end, and four debug/programming pins on the other end. The ST-Link v2 USB adapter is slightly simpler, as you can see in the photos below. It has a standard USB type A plug at one end and ten pins at the other. They almost always have the pinouts printed on the side of the USB casing.

If you look 'very' closely (the images enlarge if you click on them), you should be able to see that although they look identical, the pinouts on the ST-Link types 1 and 2 are quite different. We only need to use four of these pins to connect to our STM32 board: SWCLK, SWDIO, GND and 3.3v. This is the pin layout on the bottom row of a Type 1 ST-Link v2 USB adapter. The layout on the Type 2 ST-Link v2 USB adapter is SWDIO, GND, SWCLK and 3.3v instead. The two Type 1 adapters that I bought worked flawlessly, whereas the single Type 2 that I bought was DOA (but the discovery process was hampered by the fact that the STM32 that I was testing it with was also DOA). Naturally, of course, YMMV.

Almost every ST-Link v2 that you buy comes with 4 F/F Dupont patch cables, which you need to connect your STM32 board. Amazon and eBay are full of people selling apparently identical ST-Link v2 USB adapters for between 3 and 5 euros/dollars/pounds. Besides my own preference for a Type 1 based on my poor experience with a Type 2, there is no way of making an informed decision as they really do seem to be completely identical. Of course, the good thing about eBay is the instant returns policy, which I had to use depressingly often whilst testing out all this kit. Now, if I did it all again, I would just buy my Robotdyn Black Pill straight from Robotdyn themselves and I'd buy a Type 1 ST-Link USB adapter from Amazon or eBay. Whilst I was buying stuff, I'd also get 10 or 20 15cm F/F Dupont cables (that's Female to Female cables, i.e. the ones with sockets on either end, not pins). Don't use your 4 F/F Dupont cables that come with your ST-Link for wiring up your MPU-6050. For starters, the MPU-6050 needs 5 Dupont cables, and it is so much easier not to have to disassemble everything each time you do anything.

Hopefully this has helped you to make some good purchasing decisions. Now, though, you'll probably have to wait until your new kit is posted out to you, when you'll be able to see what you've ended up with. You might as well get your software all organised now, so you can have a look through everything and get a feel for how it all fits together.

Purchasing your MPU-6050 sensor


This is the easy part. Amazon and eBay are full of these type of sensors. They are all essentially identical and are available for between 1 and 3 dollars/pounds/euros each. They have 8 pins, which usually aren't soldered in place. Usually, they come with two sets of pins: straight and right-angle ones. If you buy a pre-soldered Robotdyn Black Pill STM32 board, then these 8 header pins are the only soldering that you will need to do (honestly, it's pretty straightforward). There is nothing else to do with these boards except attaching the pins and plugging the wires in, following the pin connection list on the next page.

Section 2: Downloading your Software

Downloading your Software