Getting Started With Stm32f103c8 With Mbed+STLink V2
by XavierJ4 in Circuits > Electronics
22877 Views, 59 Favorites, 0 Comments
Getting Started With Stm32f103c8 With Mbed+STLink V2


Stm32f103c8 aka blue pill is a cheap ARM cortex m3 based processor which u can easily get by less than 2$ from sites like Aliexpress.This instructable is an intro them ARM mbed platform.
Hardware required
STM32f03 (STM32f103c8 ,Will work with any stm32f103 series)
ST Link V2 -> Cheap programmer less than 2$
Getting Started


If you're like me and coming from Arduino and moving up to ARM and heard of the mbed platform, but when u visit the mbed website you realize that the website only directly supports mbed enabled development boards and our stm32f103c8 or blue pill is nowhere to be seen.:(.But don't worry the MCU is fully (Almost) compatible with another mbed enabled dev board called NUCLEO-F103RB.You will also require an app called stink utility which is used to program the MCU via the SWD debugging interface.
Software required
Mbed online compiler(web browser)
ST-link Utility->http://www.st.com/en/embedded-software/stsw-link004.html (Login Required)
Setting Up Mbed




Now to setup the online compiler we have to first make an account in mbed go to
Make an account and after the registration is complete you will automatically be taken to the online compiler
Now to add a dev board click on import a program upon which you will be asked to add a platform and will be directed to the mbed board's page (https://developer.mbed.org/platforms/)
Now click on STMicroelectronics on the target vendor, now you will see the NUCLEO-F103RB listed select and add to compiler
Upon adding to the compiler the compiler, you will be presented with a list of example programs.Great:)
Select Blinky LED Hello world (or any other program if you know what your doing)
Congratulations you have set up mbed compiler
Programing LED Blink

Now to be able to use mbed online compiler to write programs for youl need a library
https://developer.mbed.org/users/hudakz/code/mbed-...
Click on import into compiler to add to your mbed compiler
Now select the path to your program and select import
Now you can see the library files in your workspace
Select main.cpp and add the library by
adding
#include "stm32f103c8t6.h"
so the program should look like this
#include "stm32f103c8t6.h" //Make sure this comes first i have no idea why(someone smarter than me can tell me)
#include "mbed.h"
DigitalOut myled(LED1);
int main()
{
while(1)
{
myled = 1; // LED is OFF
wait(0.2); // 200 ms
myled = 0; // LED is ON
wait(1.0); // 1 sec
}
}
Then click compile and cross your fingers:)
This will download the binary file which we will upload to our MCU
Loading the Program to the MCU




Before you can load programs you need to install the stink drivers
go to http://www.st.com/en/embedded-software/stsw-link0...
Download and install the drivers
and in the device manager you will see that it shows up as
STMicroelectronics STLink Dongle
This means you have successfully installed the stlink drivers and are ready to go
Now wire the stm32 board with st link v2 in the following manner
Connect board and ST link in following manner.
STLINK------>STM32 Board
(Reset)-----------(R)
(3.3v)-------------(3.3v)
(SWCLK)--------(DCLK)
(SWDIO)---------(DIO)
(GND)-------------(GND)
Make sure to check the pinout of the board and the ST Link your using
Now open ST Link Utility i mentioned earlier
And select Target-Connect
It will show the data present in the MCU (in hexadecimal format) we are not going to do anything with that now
open the binary file file-open
Now select target-program
and select start
Now the program will be flashed and the led wil start blinking......:):D
If you have trouble connecting to the target make sure drivers
you can also try by connecting in"connect under reset" mode in setting and erasing the chip selecting erase chip while holding down the reset buttom in stm32 board
Refernces
https://developer.mbed.org/users/hudakz/code/STM32...
Check out the above link for more info
This is my first instructable and i would love to hear some constructive critsism from you guys in the comments below, I myself got into mbed platfrom quite recently and i will try to put more instructables taking this further like offline compiling ,STM32cube etc