new mbed Project from online to the command line

A project log for STM32 BluePill Frameworks Evaluation

The STM32F103 BluePill, what's under the hoods of mbed, platformIO, Arduino,...

wassimWassim 04/14/2017 at 09:000 Comments

mbed versioning mess

Even after reading about it, it took sometime to realize that version break changed the component name, so we have :

mbed mbed 2 library
mbed-os mbed 5 os and libraries

New mbed online Project

To create the project online, simply follow the link and click on import into Compiler

No need to comment, out of the box compilation

Funny enough, the result is 1 KB beyond the Free Keil MDK limit, so won't be able to use the free version to recompile it offline.

STM32F103C8T6_USBSerialNUCLEO_F103RB.bin 33 KB

Export to the free world

The export is very simple, but note that you're moving from the arm compiler into the gcc compiler, and that won't be without consequences.

After the build, what a surprise !!!!!

PS D:\Projects\STM32\mbed\STM32F103C8T6_USBSerial> arm-none-eabi-size -B -d -t .\BUILD\STM32F103C8T6_USBSerial.hex
   text    data     bss     dec     hex filename
      0   68320       0   68320   10ae0 .\BUILD\STM32F103C8T6_USBSerial.hex
      0   68320       0   68320   10ae0 (TOTALS)
STM32F103C8T6_USBSerial.bin 67 KB

As you might have noticed that goes beyond the Bluepill Flash size.

Next steps will cover creating mbed cli and platformIO projects and try to manage the dependencies "mbed-STM32F103C8T6" and "USBDevice_STM32F103" to make them work. Understanding how to modify the environment parameter is crucial for such cases that require optimization.


The idea here is not to create a tutorial on how to use mbed CLI, for that and other install and use steps please refer to the up link. Here is meant to have a quick view on possibilities and a reminder for steps and commands.

To use the GCC (Free and open), one way is to configure a system variable


or simply in ""

GCC_ARM_PATH = "C:\Program Files (x86)\GNU Tools ARM Embedded\6 2017-q1-update\bin"

import an existing project with mbed CLI

>mbed import
>cd mbed
>mbed update
>cd ..
>mbed compile -t GCC_ARM -m NUCLEO_F103RB

Not updating it gets a compiler error, I don't know if this is a dependency mistake or a configuration error.

The target "BLUEPILL_F103C8" not recognised (only recognized in platformIO) you have to build for the Nucleo. Reason behind this is that the Blue pill does not have an mbed drag and drop ability, I find this reason funny. so here the hack is the already patched main including the right header before mbed.h and very important is to call yourself the confSysClock();

#include "stm32f103c8t6.h"
#include "mbed.h"
int main() {
    confSysClock();     //Configure system clock (72MHz HSE clock, 48MHz USB clock)

Better way to import a project by knowing what is going on

clone the complete repo or just copy the content of the sub directory test project, note you can also create a new project this way which I find more convenient as the whole thing is just around 1 KB.

The ".mbed" contains all the magic, tool chain, target,...

I do not knwo why the mbed has a different file extension for its library reference in the "mbed.bld"
There you could check and change the version manually if you want

and we're using a library, where there could be many, each should have a .lib file with one line :
And you're ready to go. The mbed import does both create the file reference and download the whole thing, which we have here in separate steps. Now when we want to download the content after having committed the new project for example :

mbed deploy
and to compile, as we already declared the toolchain and target, it is an easy to type command :

mbed compile

mbed vs mbed-os

no big difference, the size difference was coming from the usage of the printf function.

Error with mbed-STM32F103C8T6

I got this error, which only happens if you do not compile in steps

[ERROR] .\mbed-os\targets\TARGET_STM\pinmap.c: In function 'pin_function':
although the code does not compile with the library added, even if not being used, removing the library compiling, then adding it solved the problem.
>mbed compile
>mbed remove mbed-STM32F103C8T6
>mbed compile
>mbed add
>cd .\mbed-STM32F103C8T6\
>mbed update
>cd ..
>mbed compile

Error Debug

And that explains the missing declaration of "STM_PIN_INPUT" that comes from "PinNames.h" file overridden by the library "mbed-STM32F103C8T6"

Solution add patching mbed-os to support the Blue pill

It is enough to copy paste the section for the 103C8

#elif defined(TARGET_STM32F103RB)
#ifndef INITIAL_SP
#define INITIAL_SP              (0x20005000UL)
#ifndef OS_TASKCNT
#define OS_TASKCNT              6
#define OS_MAINSTKSIZE          128
#ifndef OS_CLOCK
#define OS_CLOCK                72000000
#elif defined(TARGET_STM32F103C8)
#ifndef INITIAL_SP
#define INITIAL_SP              (0x20005000UL)
#ifndef OS_TASKCNT
#define OS_TASKCNT              6
#define OS_MAINSTKSIZE          128
#ifndef OS_CLOCK
#define OS_CLOCK                72000000
#if defined(TARGET_MCU_NRF51822) || defined(TARGET_MCU_NRF52832) || defined (TARGET_STM32F334R8) ||\
    defined(TARGET_STM32F070RB) || defined(TARGET_STM32F072RB) || \
    defined(TARGET_STM32F302R8) || defined(TARGET_STM32F303K8) || defined (TARGET_STM32F334C8) ||\
    defined(TARGET_STM32F103RB) || defined(TARGET_STM32F103C8)
mbed remove mbed-os
mbed add

All is not lost : reduce gcc compile size with libg_nano


A dirty hack was to change the file "mbed-os\tools\profiles\develop.json"

    "GCC_ARM": {
       "ld": ["-Wl,--gc-sections", "-Wl,--wrap,main", "-Wl,--wrap,_malloc_r",
               "-Wl,--wrap,_free_r", "-Wl,--wrap,_realloc_r",
               "-Wl,--wrap,_calloc_r", "-Wl,--wrap,exit", "-Wl,--wrap,atexit",
or create another json file and pass it after the "mbed compile --profile" command.