Skip to content

Build & Upload

Damian Philipp edited this page Jan 8, 2021 · 5 revisions

If you want to edit the code of the c6021light, possibly to contribute, or even if you just want to update to another software version, you will need a development toolchain installed. This page will walk you through the steps of setting up a development toolchain on your machine. The walkthrough is intended for beginners. If you are an advances user, you might find certain interesting breadcrumbs in here but can generally feel free to power-use the tools mentioned.

In this walkthrough, we will cover how to install the PlatformIO IDE, how to obtain the source code of c6021light, how to set up PlatformIO to work with the downloaded source code and how to upload source code from PlatformIO to the c6021light.

Prerequisites

To update the software of the BluePill board, you will need a bit of hardware. At minimum, you need a USB-to-Serial adapter capable of handling 3.3V on the Serial side. If you soldered on the USB-to-Serial adapter chip on the bottom of the C6021light, that will also work.

For more advances usecases, it is recommended to upload software using an ST-Link V2 Debugger. However, for most users the serial adapter will be sufficient.

Setting up the development environment: PlatformIO IDE

In general, the repository of c6021light is set up to be edited, compiled and uploaded with PlatformIO. PlatformIO is available cross-platform on Windows, Linux and Mac OS and takes care of installing all additional software required for compiling the code and uploading it to the c6021light on its own. To make use easier, PlatformIO provides the PlatformIO IDE. The PlatformIO has its own Installation Manual that is easy to follow: see here.

Downloading the Source Code

There are two general ways to obtain a copy of the source code: Downloading a ZIP file of a specific version of the source code or getting the source code via Git. For beginners, we recommend to use the ZIP download. However, we will also briefly mention the steps needed to obtain a copy using Git.

Downloading the Source Code as a ZIP archive

GitHub offers a variety of ways to get a ZIP archive of the code. You can download a specific release version, the latest and greatest development version, or a specific development version. We will show you all three options in the following.

Downloading a Release Version

Most people will be interested in downloading newer release versions of the source code. In this case, ZIP archives of the source code for every release are available from the Releases Page. Clicking any Download link will download a file named c6021light-vX.Y.zipto your harddisk, where X.Y denotes the version number of the software release, e.g., c6021light-v1.4.zip.

Downloading the latest Development Version

If you want to get a specific non-release version of the code or even the latest state of development, you can download it from the Code Page. Simply click on the green "Code" button in the top right and select "Download ZIP". This will download a file named c6021light-master.zip to your harddisk. While this file is perfectly useable, note that it contains no information about what version of the software you just downloaded. This is an issue if you ask for support, as noone will be able to reproduce your exact setup. A better approach is to download a specific Development Version.

Downloading a specific Development Version

When you first visit the Code Page, it shows you the contents of the latest commit to the master branch. To download an archive of a specific version (especially specifically this latest development version), first click on the Commit Hash slightly below the green "Code" button, shown with the red box in the following image:

Selecting a commit to download from

This will take you to a view of the changes made in that specific commit as shown in the next image. Next, go to the overview of the project files for this specific commit by clicking the "Browse Files" button (located roughly where the "Code" button was on the previous page, also highlited by the red box in the image below). Now click on the green "Code" button and select "Download Zip". Note that this will download a file with a cryptic name to your harddisk, e.g., c6021light-469f289820df5fd4852d942dc2a3e9cc254723f6.zip. This cryptig name is the Git Commit Hash that uniquely identifies the version of the software you just downloaded to everyone else. If you need help with a non-release version, make sure to have this commit hash available.

Downloading the Source Code using Git

You first need to install Git on your machine. On Linux, Git an be obtained from the packet manager of your distribution. On Mac OS, use a custom package manager yuch as homebrew. On Windows, installation Packages are available from Git for Windows.

Once you have git set up, you can clone any git repository to your harddrive by following the Instructions provided by GitHub.

Load the Source Code into the PlatformIO IDE

For the purpose of this section, we will assume that you downloaded the ZIP arhive called c6021light-1.4.zip. If you downloaded another archive, adjust the names accordingly.

Locating the Project Folder

Next, you need to load the code you just downloaded into the PlatformIO IDE. To this end, start by extracting the downloaded archive to a convenient location on your harddisk, e.g., C:\Users\<Your User Name>\Documents\PlatformIO\Projects\c6021light-1.4. Next, you will have to identify the project folder, which is actually a subfolder of the archive you just downloaded. To identify the project folder, go to the folder containing the contents of the extracted archive (in our example this is C:\Users\<Your User Name>\Documents\PlatformIO\Projects\c6021light-1.4). The project folder is the folder that contains a file called platformio.ini. In our example, this file is located at C:\Users\<Your User Name>\Documents\PlatformIO\Projects\c6021light-1.4\c6021light\platformio.ini, so the project folder for Platform IO is C:\Users\<Your User Name>\Documents\PlatformIO\Projects\c6021light-1.4\c6021light\. Make a note of this path.

Locating the Project Folder

Opening the Project in the PlatformIO IDE.

Next, open the PlatformIO IDE by starting Visual Studio Code. In Visual Studio Code, click on File -> Open Folder. This will open an "Open File" dialog. Navigate to the project folder you identified in the previous step, i.e., the folder directly containing the platformio.ini file. Then, click Open Folder.

Open the Open Folder Dialog in VS Code

Open the Project Folder

This will open the project and show you the source code. The result should look roughly like the following image:

Successful upload using serial

It will not yet download all the software tools needed to compile and upload the software - this happens in the next step.

Compiling the Software

With the project open in the PlatformIO IDE, click on the Checkmark Icon at the bottom left of the screen. This causes PlatformIO to compile the software. While compiling, PlatformIO will download and install all prerequisite software - such as the compiler for the CPU on the c6021light. A terminal window will pop open at the bottom of your screen, showing you what is currently being done. Depending on your internet connection and the speed of your computer, this might take a while. Later compilation becomes faster, as all the prerequisites will already be installed.

When all download and compile operations succeed, the terminal will show roughly the following:

Linking .pio\build\bluepill\firmware.elf
Checking size .pio\build\bluepill\firmware.elf
Building .pio\build\bluepill\firmware.bin
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [======    ]  64.1% (used 13120 bytes from 20480 bytes)
Flash: [======    ]  59.4% (used 38936 bytes from 65536 bytes)
====================================== [SUCCESS] Took 18.34 seconds ======================================

Terminal will be reused by tasks, press any key to close it.

Successful compile

Uploading the Software

To upload the software, there are again two options. The beginners' option is to use a USB-to-Serial converter capable of working with 3.3V. The more advanced option is to use an ST-Link V2 Clone Debugger. Either of these devices can be had for under 10 Euros from countless outlets. Uploading using the Debugger is faster and also allows you to inspect what the software does at runtime - thus it is the recommended option for anyone wanting to do more than just update the software of their c6021light. That said, even software development is possible using only the "Upload using Serial" option.

Note Issue #7: On some versions of the c6021light PCB, the RX and TX lines on J52 are swapped. If your PCB is affected by this bug, use jumper cables to cross over RX and TX.

Note that the USB port on the BluePill board (the blue PCB that sits on top of the c6021light Circuit Board and houses the CPU) is not useable!

Upload using Serial

To upload using the serial port, first make sure that your USB-to-Serial adapter is set to operate at 3.3V. Most adapters capable of this offer a hardware switch to select 3.3V or 5V. With the voltage set to te correct level, connect the USB-to-Serial adapter to the Serial header on the c6021light board and to your computer. Then power up the c6021light. The should be a red LED lighting up on the Bluepill board. If no LED lights up on the BluePill board, the board has no power and uploading will not work.

As a second step, tell the PlatformIO IDE to upload the software using a serial connection. To this end, open the file platformio.ini. In the Section [env:bluepill], insert the line upload_protocol = serial anywhere in the section, for example as follows:

...

[env:bluepill]
upload_protocol = serial
platform = ststm32@11.0.0
board = bluepill_f103c8
framework = libopencm3

...

platformio.ini configured for serial upload

Next, you need to correctly set the yellow jumpers on the Bluepill board. The two jumpers are labeled "Boot0" and "Boot1" on the Board. With the USB port facing away from you, "Boot0" is the jumper on the right. Both jumpers have settings "0" and "1", again labeled on the board. "0" is when the jumper is set closer to the USB port, "1" is when the jumper is set away from the USB port. Note that other revisions of the BluePill board might swap the order or direction of the jumpers, so make sure to verify these settings against what is printed on the board if you run into problems.

For software upload, only Boot0 is relevant. The setting of "Boot1" can be ignored. To upload software using serial, set Boot0 to the "1" position and press the RESET button on the board. The RESET button in located right next to the Jumpers. Now, start the Upload from the PlatformIO IDE by pressing the Arrow icon in the bottom left of the IDE window. For reference, the setting of the Jumpers for Serial Upload is shown in this picture:

Jumper setting for serial upload

The upload process will first check if it needs to recompile the code, then attempt to identify the serial port for the BluePill board and finally upload the compiled software to the BluePill board. When the upload succeeds, the output in the terminal window will look roughly as follows:

Successful upload using serial

After uploading, the new software should start right away. However, note that you still have the Boot0 jumper set to the "1" position. This causes the c6021light to enter flash mode again, once the board is reset. Therefore make sure to reset the jumper to the "0" position and to then press the RESET button on the board once again to start the software. For reference, the jumper setting for regular boot is shown in the following image:

Jumper setting for regular boot

Note that if you were using another Terminal Program, e.g., PuTTY, to use the Serial Command Line of the c6021light, you need to terminate PuTTY to free up the serial interface. Otherwise, the upload from the PlatfromIO IDE will fail.

Upload using ST-Link V2 Debugger

  • Connect the SWD, SWCLK and GND wires between the debugger and the BluePill board. Do not connect the Power line - power to the BluePill board will be supplied through the c6021light circuit board.
  • Power up the c6021light
  • Connect the Debugger to your computer.
  • Click the Arrow icon at the bottom left of the PlatformIO IDE Window or select "PlatformIO: Upload" in the command pallete.