Category: Electronics

STM32F4 Discovery Board running .NET MicroFramework

Some months ago STMicroelectronics gave out free STM32F4 Discovery boards. I was one of those few lucky (actually almost everyone got it) to get a free board. Last semester I used the board for my class project (Real Time and Embedded Operating Systems) along with Keil. I also have a netduino board which is my favourite of all dev boards I have because I can use Visual Studio and C#. I know the limitations of managed code running on metal because of the CLR’s overhead. But my applications are not real-time signal processing. Last week I accidentally bumped into a site http://netmf4stm32.codeplex.com/ and was pleasantly surprised that .NET MicroFramework was ported (or in the process) for STM32 boards. So why not try it? Well, also this time I made sure I document the whole process of doing this along with screenshots. The source of this work is taken from the post http://netmf4stm32.codeplex.com/discussions/400293. Thanks LouisCPro and the members of http://netmf4stm32.codeplex.com/team/view. The whole thing took me less than 2 hours (including installing Visual C# Express 2010). Here we go…….

Make sure you  have the following

1) STM32F4 Discovery board

2) USB Micro and USB Mini cable (Yup, you need both)

3) STM32 ST-LINK Utility (to drop the bootloader to the discovery board. It also has the driver)      http://www.st.com/web/en/catalog/tools/PF258168

4) Download stm32f4discovery.zip and  STM32_WinUSB_drivers_(for_evaluation_purposes_only).zip from http://netmf4stm32.codeplex.com/

5) Visual C# Express or Visual Studio 2010 (not 2012 right now) http://www.microsoft.com/visualstudio/eng/downloads#d-2010-express

6) .NET MicroFramework SDK (this is for 4.2) http://netmf.codeplex.com/releases/view/91594

7) An LED (To test the hello blinky)

After you have installed everything (Yes, please install everything). Now connect the USB Micro cable

STM32F Connected with Micro USB
STM32F Connected with Micro USB

(I had a different firmware in there, that’s why its all lite up)

Once you plugged in the board it will start looking for driver. If you have installed the STM32 STLink utility, then it will automatically install the driver. If you missed it, please install it. Run the STM32 Utility (usually is located in C:Program Files (x86)STMicroelectronicsSTM32 ST-LINK UtilityST-LINK UtilitySTM32 ST-LINK Utility.exe for default installation).

STLink utility connecting to the board
STLink utility connecting to the board

After you are connected to the utility, erase everything on the STM32F4 (don’t worry, you won’t brick anything) by following the screenshots below (yes delete both Chip and Sector, one after the other)

Erase Chip
Erase Chip
Erase Sectors
Erase Sectors

Now the chip is clean. Remember point 4 on the top of the page where you were asked to download 2 zip files? extract them and have them handy (we will be using it). In the stm32f4discovery.zip you will see 3 files: Tinybooter.hex, ER_Flash.hex and ER_Config.hex.

Using the ST Link utility download Tinybooter.hex into the chip (Screenshot below)

Program Tinybooter.hex
Program Tinybooter.hex
Tinybooter.hex
Tinybooter.hex

After you have successfully downloaded press reset button on the board (or just remove the usb and plug it in again). After you have uploaded the Tinybooter.hex, the Mini USB will act only as a power supply for our project. After you have reset your board now plug-in the USB Micro USB (the other USB). I used my phone charger cable. Most of the smart phone cables should be Micro USB.

Micro and Mini USB Connected
Micro and Mini USB Connected

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 other zip file named “STM32_WinUSB_drivers_(for_evaluation_purposes_only).zip“. Follow the screen shots give below if you don’t know how.

Go to Devices and Printers from your Start menu and then

Right Click on STM 32 .NET
Right Click on STM 32 .NET Test
Properties -> Change Settings
Properties -> Change Settings
Search new driver
Search new driver
Ignore warning (as usual :D )
Ignore warning (as usual 😀 )
Now no error!
Now no error!

Now the MFDeploy should be able to see this board. MFDeploy is MicroFramework Deployer (duh). Using this software we’ll install the CLR on which our .net code will run. Alright, now launch MFDeploy.exe (you should be able to find it in C:Program Files (x86)Microsoft .NET Micro Frameworkv4.2ToolsMFDeploy.exe) which you should have got when you installed the SDK. To make sure MFDeploy can see the board do as shown below.

MFDeploy Ping
MFDeploy Ping

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 stm32f4discovery.zip file to the board using the MFDeploy as shown below

Click Browse to download two other hex
Click Browse to download two other hex
Install one by one (any order)
Install one by one (any order)

Reset the board.

Congratulations! You got a .NET Microframework board!

Now we need to test our board. So open your Visual C# Express/ Visual Studio. I am sure you should have installed the Microframework SDK. Select the project type as given below

Microframework Project
MicroFramework Project

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

Properties
Properties
To USB
To USB

Now we need to add hardware class so that we can run a program to blink and LED.

Add Reference
Add Reference
Microsoft.SPOT.Hardware
Microsoft.SPOT.Hardware

Here is  my test code

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

namespace STM32F_Test
{
    public class Program
    {
        public static void Main()
        {
            OutputPort led = new OutputPort(Cpu.Pin.GPIO_Pin1, false); //PA1 on discovery board

            while (true)
            {
                led.Write(true);
                Thread.Sleep(500);
                led.Write(false);
                Thread.Sleep(500);
            }
        }

    }
}

Oh, to know the pin map follow this file “C:MicroFrameworkPK_v4_2DeviceCodeTargetsNativeSTM32ManagedCodeHardwareCPU.cs” which you will find if you installed the porting kit (not included in the list above)

Here is the video

[youtube=http://www.youtube.com/watch?v=waKveMdQq1o]