I am trying to do the same with a C# .net project but i have got a problem while calling the _fm_connect() method.
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Show posts Menu
[StructLayout(LayoutKind.Sequential)]
public struct Options
{
public int usingicp; // set to 1 if using icp
public int interfacetype; // interface being used (FM_INTERFACETYPE_xxx)
}
[DllImport("FlashMagicARM.dll", EntryPoint = "_fm_connect", CallingConvention=CallingConvention.StdCall, CharSet=CharSet.Auto, SetLastError=true)]
private unsafe static extern IntPtr _fm_connect(double osc, int port, long baudrate, int selecteddevice, int highspeed, int clocks, int halfduplex, int hwconfig, int hwt1, int hwt2, byte reserved1, long maxbaudrate, ref IntPtr options);
public unsafe static Results fm_connect(double osc, int port, long baudrate, int selecteddevice, int highspeed, int clocks, int halfduplex, int hwconfig, int hwt1, int hwt2, byte reserved1, long maxbaudrate, Options options)
{
// Initialize unmanged memory to hold the struct.
IntPtr ptr = Marshal.AllocCoTaskMem(Marshal.SizeOf(options));
Marshal.StructureToPtr(options, ptr, false);
Results Res = (Results)Marshal.PtrToStructure(_fm_connect(osc, port, baudrate, selecteddevice, highspeed, clocks, halfduplex, hwconfig, hwt1, hwt2, reserved1, maxbaudrate, ref ptr), typeof(Results));
Marshal.FreeCoTaskMem(ptr);
return Res;
}
FlashMagic.Options options = new FlashMagic.Options();
options.usingicp = 0;
options.interfacetype = (int)FlashMagic.InterfaceType.FM_INTERFACETYPE_NONE;
FlashMagic.Results r = FlashMagic.fm_connect(12.000, 1, 38400, (int)FlashMagic.Device.FM_LPC2129, 0, 0, 0, (int)FlashMagic.HardwareConfig.FM_HWBOOTEXEC, 200, 200, 0, 115200, options);
if (r.result != FlashMagic.Result.FM_OK)
{
MessageBox.Show(new string(r.details).TrimEnd('\0'));
}