Skip to main content

STM32F4 Discovery Tutorial 1 Using NETMF - Setting Up the Environment


STM32F4 Discovery

I received my STM32F4 Discovery board few days ago. During these days I am searching for a good compiler for the STM32 which is free or provide a better code sized free version. I am already working in .Net environment using C#, and I it is pretty good. In Google search I saw STM32F4 programming using  .Net, the below link.

We are using a .net port for STM32F4, it is .Net micro framework. 
I am using Visual Studio Ultimate 2010 (Compatibility of others is not known).
I hope you have an STM32F4 Discovery Board.
Necessary Tools
1.      STM32 ST-LINK Utility            Get It ->
2.      USB Micro and USB Mini cable.
3.      .NET MicroFramework SDK  Get It ->  
4.      Download these files (Evaluation purpose only driver)
                                                              i.      If you are not a member, join
Install all the softwares.
Step 1
            Connect Board to PC using Micro USB
The board will get power and power LED & COM LED will be on, if your board is fresh the demo program will run blinking LEDs.
The computer will look for drivers, ( I installed the drivers included in some software already, so i didn’t seen it)
Install STM32 ST-LINK Utility   you downloaded. The driver will be automatically installed.
Step 2
You need to Erase the program and Configs in the controller.
For these, open the STLink Utility from where you installed it.
            Let’s first erase chip.
From Target select Erase chip ------Target > Erase Chip click Select ALL apply
After doing these you need to erase sector
For these select erase sector from target
Target >Erase sector

After these you have to load bootloader to the Discovery board.
In the stm32f4 you will see some files: Open Tinybooter.hex in the STLink Utility
From Targets >Program
After it’s done,
Reset the board.

Step 3

After you have reset your board now plug-in the USB Micro USB and connect to PC(the other USB). Most of the smart phone cables should be Micro USB.  Once you connected the Micro USB, windows will start searching for driver and will fail. Now we got to install the driver we downloaded from the zip file. “STM32_WinUSB_drivers_(for_evaluation_purposes_only)  Folder. From device manager find the USB device then (May be its name is STM32F4 Test or unrecognized)
Double click on it, from DRIVER  tab  click update diver and browse it to the folder mentioned above and update it.

 Doing this you can see a device as shown in pic. Control Panel> Devices and printers

STM32F4 Discovery Programming

Step 4

Find the application Named MFDeploy.exe
Launch MFDeploy.exe (you should be able to find it in C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Tools\MFDeploy.exe) which you should have got when you installed the SDK. To make sure MFDeploy can see the board do as shown below.

If you see the Ping the everything is good till this point. Now download the other 2 .hex ER_Config.hex and ER_Flash.hex files extracted from stm32f4 file to the board using the MFDeploy as shown below one by one.   (the Combo-box, you need to change it to USB, the STM Discovey board will be shown in right of it.)

Reset the board.

Step 5
Open Visual C# Express/ Visual Studio  Select the project type as given below

Now we need to change the properties, so that the Visual Express/Studio will deploy to the hardware. So change the project properties as shown below



Add Reference  Right Click On MFTest in Solution Explorer>Add Reference> Select the following sown in the figure>OK



using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;

namespace MFtest
public class Program
public static void Main()

OutputPort led1 = new OutputPort(Microsoft.SPOT.Hardware.STM32.Pins.GPIO_PIN_D_15, false); //LED Pins of Discovery Board

OutputPort led2 = new OutputPort(Microsoft.SPOT.Hardware.STM32.Pins.GPIO_PIN_D_14, false);
OutputPort led3 = new OutputPort(Microsoft.SPOT.Hardware.STM32.Pins.GPIO_PIN_D_13, false);
OutputPort led4 = new OutputPort(Microsoft.SPOT.Hardware.STM32.Pins.GPIO_PIN_D_12, false);

while (true)


ADD files HardwareProvider.cs and CPU.cs to project (step is same as adding reference right click> select Add existing Item)  from the zip file downloaded including the drivers.

Start debugging your code will be written to your Discovery, you can see the status at the bottom. Reset your board.

You Are Successfully Done!!!!!!!!!

Download Full Project Files

STM32F4 Discovery Board


  1. Hello friends,
    Some files are uploaded in our facebook group. If you have any trouble in downloading the file please comment here. You need to be a member in the group to download the files.

  2. Discovery is great. I run couple of shields on this like: SD Card, RTC, GPS, GSM SIM900, LCD with keypad, OneWire => iButton Reader.

    It is unfortunate that there are no people who would like to be proud of their actions of this module. Forum on codeplex looks inactive. Oberon also says nothing. New version port on netfm 4.3 would be great.


  3. Hello Darek,
    Thanks for your comment and interest. I have done the Smart Home Project on Discovery. I wish to do it as open source, but i didnt found required resources. So i forced to do it using Mikroc. The support from Mikroe team and forum is great.

    I would like to transform the project to open source. It would be nice if you share some resources on this. If you have a facebook ID, join our group. You can find lot of Geeks there.

  4. Hello Vishal,
    Every thing went well except at the very end, It could not locate Microsoft.SPOT.Hardware.STM32
    It finds Microsoft.SPOT.Hardware -- I am somehow missing this driver, and looked at your tutorial 4 times but I don't see where you loaded it.
    Thank you for your help.
    Best regards,

  5. @Marvin Did you installed .Net Micro framework?


  7. Thank you Vishal,
    I will reload the .NET Framework and try again.
    Best regards,

  8. Thanks for your information. And the steps given for setting up the environment is really useful. In STM32 F4 series, there are five product lines and this results in the symbiosis of real time control capabilities of Micro controller unit. They are,

    Chennai final year projects

  9. It is a great work! But wouldn't it be better if ST-Link (mini USB) is used for .C# code transfer and debug so that micro usb is spare and can be used as USB device/host?
    Best Regards
    Pradeep Maskeri

  10. @maskeri
    USB can be used as per requirement after uploading code.

  11. Nice idea ! Can I do it using


Post a Comment

Popular posts from this blog

PIC 16F877A Microcontroller Based Electronic Lock 16x2LCD 4x3 Keypad

Circuit Diagram

Security is a prime concern in our day-today life. Everyone wants to be as much secure as possible. An access control for doors forms a vital link in a security chain. The microcontroller based digital lock for Doors is an access control system that allows only authorized persons to access a restricted area.
An electronic lock or digital lock is a device which has an electronic control assembly attached to it. They are provided with an access control system. This system allows the user to unlock the device with a password. The password is entered by making use of a keypad. The user can also set his password to ensure better protection. The major components include a Keypad, LCD and the controller PIC16F877A. This article describes the making of an electronic code lock using the 16F877A microcontroller.
The system is fully controlled by the 8 bit microcontroller 16F877A which has a 8Kbytes of ROM for the program memory. The password is stored in the EPROM so that we c…

PIC Serial Communication Tutorial (UART)

First, a quick history of RS232. What is RS232? It's just a name for a standard that has propagated from generation to generation of computers. The first computers had serial ports that used RS232, and even current computers have serial ports (or at least USB ports that act like RS232 ports). Back in the day, serial information needed to be passed from devices like printers, joysticks, scanners, etc to the computer. The simplest way to do this was to pass a series of 1s and 0s to the computer. Both the computer and the device agreed on a speed of information - 'bits per second'. A computer would pass image data to a printer at 9600 bits per second and the printer would listen for this stream of 1s and 0s expecting a new bit every 1/9600 = 104us (104 micro-seconds, 0.000104 seconds). As long as the computer output bits at the pre-determined speed, the printer could listen.
Zoom forward to today. Electronics have changed a bit. Before they were relatively high power, high …