How use STM32F4-Discovery devices in C# ?

Feb 24, 2013 at 4:57 PM
HI,
I have installed NETMF SDK and the porting kit adding to it the porting from Mountaineer
http://www.mountaineer.org/netmf-for-stm32/

I make my first working deploy on STM32F4-Discovery with C# importing in the project the file CPU.cs (from ...\MicroFrameworkPK_v4_2\DeviceCode\Targets\Native\STM32\ManagedCode\Hardware\CPU.cs)

Ok: 2 leds are blinking (look the code at the bottom)
but now I would use all other available devices: could you explain to me how to do this ?

In ...\MicroFrameworkPK_v4_2\DeviceCode\Targets\Native\STM32F4\DeviceCode I found a lot of code for (maybe) all the devices but it's in cpp language.
I have to import it in my c# project ?
I have to compile it ?
probably there is a precompiled assembly but I haven't found it ?

Thanks

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


namespace STM32F_Test
{
public class Program
{        
    public static void Main()
    {
        // create a thread handler
        Thread MyThreadHandler;
        // create a new thread object and assign to my handler
        MyThreadHandler = new Thread(MyThread);

        OutputPort gled = new OutputPort(Microsoft.SPOT.Hardware.STM32F4.Pins.GPIO_PIN_D_12, false);

        Debug.Print("Start Main");

        // start my new thread
        MyThreadHandler.Start();
        Debug.Print("Start Thread");

        while (true)
        {
            gled.Write(true);
            Thread.Sleep(50);

            gled.Write(false);
            Thread.Sleep(50);
        }
    }

    public static void MyThread()
    {
        OutputPort rled = new OutputPort(Microsoft.SPOT.Hardware.STM32F4.Pins.GPIO_PIN_D_13, false);

        while (true)
        {
            rled.Write(true);
            Thread.Sleep(200);
            rled.Write(false);
            Thread.Sleep(200);
        }
    }

}
}
Feb 24, 2013 at 5:31 PM
Edited Feb 24, 2013 at 5:32 PM
devices?
you mean the onboard peripherals?
i dont think you can use em, i havent really checked.

you can use adc,dac (it has 2 of em), pwm, spi (is buggy <1.6mhz or so), i2c (one channel, netmf doesent support more i2c ports atm), serial
Feb 24, 2013 at 7:39 PM
Exactly !!
How can use the peripherals that you listed ?

I'm watching inside Microsoft.SPOT.Hardware reference and I find see SPI, I2C, GPIO (InputPort and OutputPort), ADC (AnalogInput), DAC (AnalogOutput) and WatchDog
Furthermore I found others references like Microsoft.SPOT.Hardware.PWM, Microsoft.SPOT.Hardware.USB and Microsoft.SPOT.SerialPort

I have to add these references for using these peripherals ?
I have to modify CPU.cs adding the configuration about I2C, ADC, DAC ecc... ? Because inside CPU.cs I can see only references about COM, GPIO and SPI

Thanks
Feb 25, 2013 at 8:19 AM
Edited Feb 25, 2013 at 8:20 AM
i suggest buying anohter netmf board before playing with this. other boards are way more documented, and there are communities to help you getting started. (netduino or ghi)
Feb 25, 2013 at 3:11 PM
nobody else can you help me ?
Feb 28, 2013 at 8:42 AM
Common peripherials such as SPI, AnalogInput, AnalogOutput, PWM etc. are common to all solutions (boards).
Just add reference for specified assemblies, as you say.

How to use this peripherials:
http://www.ghielectronics.com/support/dotnet-micro-framework (see Tutorials tab)
http://www.tinyclr.com/codeshare

For STM32F4Discovery check blog: http://kodfilemon.blogspot.com.
It is not in English but maybe google translate will help.

API refrence:
http://msdn.microsoft.com/en-us/library/hh401281.aspx

For beginners how to start with. NET Micro Framework:
http://www.ghielectronics.com/support/dotnet-micro-framework (especially see free ebooks)