Assembling your Software

From The Relativty Wiki
Other languages:
English • ‎français

Assembling your Software[edit]

The packages from STmicroelectronics[edit]

You should have two packages downloaded from STmicroelectronics:

  • en.stsw-link009.zip - The ST-Link Utility package
  • en.stsw-link004.zip - The ST-Link drivers package

Each zip file just contains the installer, along with its associated files and folders. Extract these zips files to somewhere sensible - I would advise popping them into the Arduino_STM32-master folder that you created when you extracted Roger Clark's STM32 Software and Tools package, so that everything is in one place. WARNING - You will need to create some folders to extract these zip files into (e.g. "ST-Link Utility" and "ST-Link Drivers") as it can get very messy if you don't.


For the ST-Link Drivers package, just right-click on the installer and select Run as administrator then follow the instructions. It should install several driver packages, all of which are vital to enable you to program your STM32 board.


For the Utility package, just right-click on stlink_winusb_install.bat and select Run as administrator. Not only will this install the Utility package, but it will also install some drivers too. These drivers are also vital. As I mentioned earlier, occasionally the installer "loses focus" for its windows, so either the main installer window or the drivers install window may well end up behind one of your other windows, so you' may need to click on it to bring it to the front again. You really need to be very aware of this, as if the installation of these drivers goes wrong, you won't be able to program your STM32 and your tracker won't work.

The packages from Roger Clark[edit]

You should have three packages downloaded from Roger Clark's GitHub site:

  • The main STM32 Software and Tools package
  • Black Pill bootloader binary file
  • Blue Pill bootloader binary file

We just need to be certain that you extracted the main STM32 Software and Tools package, and created a folder called: Arduino_STM32-master
If we navigate inside this, we can get to ..\Arduino_STM32-master\tools\win\stlink
You should have the two bootloader binary files here as well as the ST-LINK_CLI.exe program:

  • The Black Pill bootloader is called generic_boot20_pb12.bin
  • The Blue Pill bootloader is called generic_boot20_pc13.bin


The STM32 Tracker sketches[edit]

Finally, we should be ready to grab the STM32 Tracker sketches. This does assume that you have added the "STM32 Cores by STMicroelectronics" Boards to Boards Manager in your Arduino IDE...


Download the latest sketches from: https://github.com/JustinS-B/STM32-Tracker
The GitHub STM32 Tracker Repository contains both the Black Pill and Blue Pill sketches, along with library files.


We have tried to make this as straightforward to use as is possible, however, there are a host of hardware gotcha's that can easily catch you out. Likewise, there are a host of software gotcha's that can easily catch you out as well. We had to make a couple of changes to the the MPU-6050 and I2Cdev libraries so that we could compile the sketches on an STM32 board. Because of this, we had to move patched copies of the library files into each individual Pill folder, so that they didn't mess up any other sketches that need the original libraries.


Pretty much all Arduino sketch components rely upon included libraries. The I2Cdev is used almost everywhere in our type of tracker sketches. The MPU-6050 library actually includes the I2Cdev library itself, and needs it to run. However, the MPU-6050 library prefers the unpatched version of I2Cdev. For this reason the unpatched MPU-6050 and I2Cdev libraries are best copied to your main Arduino libraries folder. Meanwhile, the Black Pill and Blue Pill sketches are all self contained units, which means that their custom library files won't impact up on any other sketches you may have.


Some optional code has been placed into the sketch on Lines 47 and 48. All it does is to turn the LED on when the tracker sketch is running. Naturally, this is more useful when you are building and testing the tracker than it is when the tracker is finally built into the headset.


pinMode(PB12, OUTPUT); //PB12 for black pill PC13 for blue pill
digitalWrite(PB12, LOW); // HIGH is led off, LOW is led on (led is active low)


Both lines can easily be commented out (by using // at the beginning of the line) without affecting the tracker's functionality. If you want to disable the LED once you have tested your tracker, this is how these lines should look:


//pinMode(PB12, OUTPUT); //PB12 for black pill PC13 for blue pill
//digitalWrite(PB12, LOW); // HIGH is led off, LOW is led on (led is active low)

Opening a Pill Sketch and setting up the Arduino IDE[edit]

Depending on which board you are planning on using, you will either need to open the STM32_BlackPill or STM32_BluePill sketch in your Arduino IDE.

For both sketches, you will need to make nearly the same changes to your settings. The only difference is the Board part number section. Both Black and Blue Pills come with 64k of storage space as standard. There are still Rev A Blue Pill boards being sold, which only have 32k of storage space. If you get sent one by mistake, send it back as it doesn't have enough space to store the tracker sketch. Occasionally, you can get a Blue Pill with 128k of storage space. This has its own Board Part Number setting of BluePill F103C8 (128k) if you have one, but everything else remains the same.


The Board Part Number section drop down menu


In the Tools menu

  • Set Board to Generic STM32F1 series for both
  • Set Board part number to either BluePill F103C8 or BlackPill F103C8
  • Set U(S)ART support to Enabled (generic 'serial')
  • set USB support (if available) to CDC generic 'serial' supersede U(S)ART
  • set USB speed (if available) to Low/Full speed
  • set Optimize to Smallest (-Os default)
  • set Set C Runtime Library to Newlib Nano (default)
  • set Set Upload method to STLink
  • Don't touch the Port setting for now
Arduino Tools Menu for the Black Pill Board Arduino Tools Menu for the Blue Pill Board


Now click the green arrow to verify/compile the sketch. It should compile in around 30 seconds, even on a fast computer.

Testcompile.png

If you have followed the instructions, your sketch really should compile first time, without any issues.If it does, then it's finally time to start playing with the hardware...

Section 4 - Fun and Games with Bootloaders (Part 2)[edit]

Fun and Games with Bootloaders (Part 2)