2022-09-29 12:16 AM
I am trying to create a C# application within Visual Studio 2019 for using STM32CubeProgrammer API because I will need to modify an existing C# application to use it. At the moment I am having trouble connecting to the small board I am using:
int connectionResult = CubeProgrammerApi.Connect(cbUsbIndexes.SelectedItem.ToString());
CubeProgrammerApi.Disconnect();
With both of these routines I am getting 0xC0000005: Access violation executing location 0x0000000000000000 errors.
I do seem to have gotten the getDfuDeviceList working:
_deviceInfo = AddressOf(ref _dfuDeviceInfo);
_numberOfDfUDevices = CubeProgrammerApi.GetDfuDeviceList(ref _deviceInfo);
The DLL Imports I have defined are as follows:
[DllImport(DllPath, EntryPoint = "getDfuDeviceList", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
internal static extern int GetDfuDeviceList(ref IntPtr dfuDeviceInfo, int intPid = 0xdf11, int intVid = 0x0483);
[DllImport(DllPath, EntryPoint = "connectDfuBootloader", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
internal static extern int Connect(string usbIndex);
[DllImport(DllPath, EntryPoint = "disconnect", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
internal static extern void Disconnect();
[DllImport(DllPath, EntryPoint = "deleteInterfaceList", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
internal static extern void DeleteInterfaceList();