STM32F103 Getting Started (using Mbed.h)

Introduction: STM32F103 Getting Started (using Mbed.h)

Have STM32F103RBT6? Let's get Started.

In this tutorial we will be using free online mbed compiler to write and compile our code. Which means we dont need to install any software's. However, we do need to SignUp as mbed developer to get access to online compiler for free. We will be using mbed.h in all of our programmes (using mbed online compiler).

This Tutorial is divided into 3 easy steps:

1) Creating Developer account.

2) Blinking LED.

3) Understanding the Code

4) Compiling and Burning Code.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Creating Developer Account

Click here , to Open this link in new tab. []

Click Green "Login or signup" button in the top right corner.

If you already have signed up, then login. If not then signup by clicking on "Sign Up" button. Click on "No, I haven't created an account beore". A form will appear below these buttons. Fill in those fields and click on Signup button.

Now, come back to first page [] .

Step 2: Blinking LED

Now, that you have signed in to you mbed developer account Lets start writing code.

Click on "Platforms" button in top left corner. Scroll Down to search for "NUCLEO-F103RB". Click it.(or Click Here)

Here, you can find documentations related to NUCLEO-F103RB on this page, like Overview, Microcontrollerfeatures, Nucleo features, Nucleo pinout, Supported shields etc

Not just that, you can also find example programs to get started.

In example programs click on first "Nucleo_blink_led". Now click on "Import this Program" Button.

This will open your project in "Compiler". Enter a project name and proceed.

Now, Click on "main.cpp" to Open this file in the Compiler. That it! That the code you will need to blink LED.

Step 3: Understanding the Code

Lets try to understand this code: First line

#include "mbed.h"<br>

is just importing 'mbed.h'.

DigitalOut myled(LED1);

This line is declaring an object myled of type DigitalOut passing an argument LED1. This class is defined in mbed.h. What this line is actually doing is that its telling the controller that "'LED1 pin is as DigitalOutput Pin and I will call this pin as myled ". Note that, LED1 refrs to LED on our NUCLEO board and is defined in mbed.h.

After this the famous 'main()' function. Inside main we have a while(1) loop which means that code inside this loop will run forever, until powered off or reprogrammed.

After that

myled = 1;

yes, as obvious, this will turn our 'LED1' 'ON'. Next,


and yes, this will wait for 0.2 'SECONDS' (not miliseconds). and that was our code. :)

Step 4: Compiling and Burning Code

Now, Connect your STM32 Nucleo board to your computer. Nucleo will appear as a separate partition (Drive) in you 'My Computer'/'This PC'.

Now, Click on 'Compile' Button. (or press Ctrl + D). This will Compile your code, generate a .bin) binary file and download this file. A Save file dialog will appear (depends on your browser settings).

Now, if you want to flash this binary file onto your nucleo, just select your nucleo directory. This obviously (not only) will download .bin file to your Nucleo board but will also flash it.

Or you can just download it anywhere and drag and drop it onto 'Nucloe' directory icon in you My Computer/This PC whenever you want to flash this .bin file.

That it! Say Hi! to that Blinking LED on your STM32. :)

Be the First to Share


    • Backyard Contest

      Backyard Contest
    • Silly Hats Speed Challenge

      Silly Hats Speed Challenge
    • Arduino Contest 2020

      Arduino Contest 2020