Skip to content

Commit

Permalink
Merge pull request #83 from K-Society/experimental
Browse files Browse the repository at this point in the history
Experimental
  • Loading branch information
maniglia authored Nov 29, 2023
2 parents fb74800 + 7546121 commit 785c8ac
Show file tree
Hide file tree
Showing 12 changed files with 381 additions and 53 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -367,4 +367,5 @@ FodyWeavers.xsd
!/Programmer/x64/*
!/Programmer/x86/*

Visual Studio 2022/
Visual Studio 2022/
Visual Studio 2022Templates/
28 changes: 22 additions & 6 deletions KSociety.SharpCubeProgrammer.sln
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "KSociety.SharpCubeProgrammer", "src\01\KSociety.SharpCubeProgrammer\KSociety.SharpCubeProgrammer.csproj", "{3B3765AD-E869-4D7E-8274-F63380F177B7}"
ProjectSection(ProjectDependencies) = postProject
{52455EFE-41B6-4C8B-97C0-DB796FE725B5} = {52455EFE-41B6-4C8B-97C0-DB796FE725B5}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Programmer", "src\01\Programmer\Programmer.vcxproj", "{52455EFE-41B6-4C8B-97C0-DB796FE725B5}"
EndProject
Expand All @@ -28,6 +31,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ProgrammerConsoleApplicatio
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DummyLibrary", "src\01\Samples\DummyLibrary\DummyLibrary.csproj", "{5DD743B1-AB1B-4509-9930-2AEBF3541F98}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProgrammingLegacy", "src\01\Samples\ProgrammingLegacy\ProgrammingLegacy.csproj", "{3285B360-3124-4A10-8D51-BE29EBA68D33}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -48,6 +53,7 @@ Global
{3B3765AD-E869-4D7E-8274-F63380F177B7}.Release|x64.ActiveCfg = Release|x64
{3B3765AD-E869-4D7E-8274-F63380F177B7}.Release|x86.ActiveCfg = Release|x86
{52455EFE-41B6-4C8B-97C0-DB796FE725B5}.Debug|Any CPU.ActiveCfg = Debug|x64
{52455EFE-41B6-4C8B-97C0-DB796FE725B5}.Debug|Any CPU.Build.0 = Debug|x64
{52455EFE-41B6-4C8B-97C0-DB796FE725B5}.Debug|x64.ActiveCfg = Debug|x64
{52455EFE-41B6-4C8B-97C0-DB796FE725B5}.Debug|x64.Build.0 = Debug|x64
{52455EFE-41B6-4C8B-97C0-DB796FE725B5}.Debug|x86.ActiveCfg = Debug|Win32
Expand Down Expand Up @@ -83,13 +89,22 @@ Global
{8709E86A-F53A-4CED-B485-5D8A40FE9CCA}.Release|x86.ActiveCfg = Release|Win32
{5DD743B1-AB1B-4509-9930-2AEBF3541F98}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5DD743B1-AB1B-4509-9930-2AEBF3541F98}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5DD743B1-AB1B-4509-9930-2AEBF3541F98}.Debug|x64.ActiveCfg = Debug|Any CPU
{5DD743B1-AB1B-4509-9930-2AEBF3541F98}.Debug|x64.Build.0 = Debug|Any CPU
{5DD743B1-AB1B-4509-9930-2AEBF3541F98}.Debug|x86.ActiveCfg = Debug|Any CPU
{5DD743B1-AB1B-4509-9930-2AEBF3541F98}.Debug|x86.Build.0 = Debug|Any CPU
{5DD743B1-AB1B-4509-9930-2AEBF3541F98}.Debug|x64.ActiveCfg = Debug|x64
{5DD743B1-AB1B-4509-9930-2AEBF3541F98}.Debug|x64.Build.0 = Debug|x64
{5DD743B1-AB1B-4509-9930-2AEBF3541F98}.Debug|x86.ActiveCfg = Debug|x86
{5DD743B1-AB1B-4509-9930-2AEBF3541F98}.Debug|x86.Build.0 = Debug|x86
{5DD743B1-AB1B-4509-9930-2AEBF3541F98}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5DD743B1-AB1B-4509-9930-2AEBF3541F98}.Release|x64.ActiveCfg = Release|Any CPU
{5DD743B1-AB1B-4509-9930-2AEBF3541F98}.Release|x86.ActiveCfg = Release|Any CPU
{5DD743B1-AB1B-4509-9930-2AEBF3541F98}.Release|x64.ActiveCfg = Release|x64
{5DD743B1-AB1B-4509-9930-2AEBF3541F98}.Release|x86.ActiveCfg = Release|x86
{3285B360-3124-4A10-8D51-BE29EBA68D33}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3285B360-3124-4A10-8D51-BE29EBA68D33}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3285B360-3124-4A10-8D51-BE29EBA68D33}.Debug|x64.ActiveCfg = Debug|x64
{3285B360-3124-4A10-8D51-BE29EBA68D33}.Debug|x64.Build.0 = Debug|x64
{3285B360-3124-4A10-8D51-BE29EBA68D33}.Debug|x86.ActiveCfg = Debug|x86
{3285B360-3124-4A10-8D51-BE29EBA68D33}.Debug|x86.Build.0 = Debug|x86
{3285B360-3124-4A10-8D51-BE29EBA68D33}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3285B360-3124-4A10-8D51-BE29EBA68D33}.Release|x64.ActiveCfg = Release|x64
{3285B360-3124-4A10-8D51-BE29EBA68D33}.Release|x86.ActiveCfg = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -102,6 +117,7 @@ Global
{22183711-7C44-40E7-B3CE-2B2CECBDE80D} = {4EE1D5AC-4198-4753-A277-FA7F730B5184}
{8709E86A-F53A-4CED-B485-5D8A40FE9CCA} = {3D922D26-1A7F-4021-89BD-AF5DDCB99CDB}
{5DD743B1-AB1B-4509-9930-2AEBF3541F98} = {4EE1D5AC-4198-4753-A277-FA7F730B5184}
{3285B360-3124-4A10-8D51-BE29EBA68D33} = {4EE1D5AC-4198-4753-A277-FA7F730B5184}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {7D151E62-C748-4733-BFAC-CDAD83F0B9A8}
Expand Down
61 changes: 28 additions & 33 deletions src/01/KSociety.SharpCubeProgrammer/CubeProgrammerApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ private void RegisterStm32BootLoader()

private void WmiManagerOnStLinkPortChangeStatus(object sender, Wmi.StLink.StLinkPortChangeStatusEventArgs e)
{
this._logger?.LogTrace("CubeProgrammerApi WmiManagerOnStLinkPortChangeStatus: {0} - {1}", e.PortName, e.Status);
//this._logger?.LogTrace("CubeProgrammerApi WmiManagerOnStLinkPortChangeStatus: {0} - {1}", e.PortName, e.Status);
if (e.Status)
{
this.StLinkReady = true;
Expand All @@ -136,7 +136,7 @@ private void WmiManagerOnStLinkPortChangeStatus(object sender, Wmi.StLink.StLink

private void WmiManagerOnStLinkPortScanned(object sender, Wmi.StLink.StLinkPortScannedEventArgs e)
{
this._logger?.LogTrace("CubeProgrammerApi WmiManagerOnStLinkPortScanned: {0}", e.PortsList.Count);
//this._logger?.LogTrace("CubeProgrammerApi WmiManagerOnStLinkPortScanned: {0}", e.PortsList.Count);

if (e.PortsList.Any())
{
Expand All @@ -149,7 +149,7 @@ private void WmiManagerOnStLinkPortScanned(object sender, Wmi.StLink.StLinkPortS

private void WmiManagerOnStm32BootLoaderPortChangeStatus(object sender, Wmi.STM32.STM32BootLoaderPortChangeStatusEventArgs e)
{
this._logger?.LogTrace("CubeProgrammerApi WmiManagerOnStm32BootLoaderPortChangeStatus: {0} - {1}", e.PortName, e.Status);
//this._logger?.LogTrace("CubeProgrammerApi WmiManagerOnStm32BootLoaderPortChangeStatus: {0} - {1}", e.PortName, e.Status);
if (e.Status)
{
this.Stm32BootLoaderReady = true;
Expand All @@ -164,7 +164,7 @@ private void WmiManagerOnStm32BootLoaderPortChangeStatus(object sender, Wmi.STM3

private void WmiManagerOnStm32BootLoaderPortScanned(object sender, Wmi.STM32.STM32BootLoaderPortScannedEventArgs e)
{
this._logger?.LogTrace("CubeProgrammerApi WmiManagerOnStm32BootLoaderPortScanned: {0}", e.PortsList.Count);
//this._logger?.LogTrace("CubeProgrammerApi WmiManagerOnStm32BootLoaderPortScanned: {0}", e.PortsList.Count);

if (e.PortsList.Any())
{
Expand Down Expand Up @@ -340,9 +340,9 @@ public int GetDfuDeviceList(ref List<DfuDeviceInfo> dfuDeviceList)
{
var size = Marshal.SizeOf<DfuDeviceInfo>();

this._logger?.LogTrace("GetDfuDeviceList iPID: {0} iVID: {1}", 0xdf11, 0x0483);
//this._logger?.LogTrace("GetDfuDeviceList iPID: {0} iVID: {1}", 0xdf11, 0x0483);
numberOfItems = Native.ProgrammerApi.GetDfuDeviceList(ref listPtr, 0xdf11, 0x0483);
this._logger?.LogTrace("GetDfuDeviceList DFU devices found : {0}", numberOfItems);
//this._logger?.LogTrace("GetDfuDeviceList DFU devices found : {0}", numberOfItems);

//var listDereference = Marshal.PtrToStructure<IntPtr>(listPtr);
if (listPtr != IntPtr.Zero)
Expand All @@ -351,7 +351,7 @@ public int GetDfuDeviceList(ref List<DfuDeviceInfo> dfuDeviceList)
{
var currentItem = Marshal.PtrToStructure<DfuDeviceInfo>(listPtr + (i * size));

this._logger?.LogTrace("GetDfuDeviceList DfuDeviceInfo: {0} - {1}", i, currentItem.SerialNumber);
//this._logger?.LogTrace("GetDfuDeviceList DfuDeviceInfo: {0} - {1}", i, currentItem.SerialNumber);
dfuDeviceList.Add(currentItem);
}
}
Expand All @@ -371,7 +371,7 @@ public int GetDfuDeviceList(ref List<DfuDeviceInfo> dfuDeviceList)
/// <inheritdoc />
public CubeProgrammerError ConnectDfuBootloader(string usbIndex)
{
this._logger?.LogTrace("ConnectDfuBootloader: {0}", usbIndex);
//this._logger?.LogTrace("ConnectDfuBootloader: {0}", usbIndex);
var output = CubeProgrammerError.CubeprogrammerErrorOther;
try
{
Expand Down Expand Up @@ -427,8 +427,7 @@ public bool CheckDeviceConnection()
//Register();

var checkDeviceConnectionResult = Native.ProgrammerApi.CheckDeviceConnection();
this._logger?.LogTrace("CheckDeviceConnection. {0} ROW: {1}", checkDeviceConnectionResult ? "OK" : "KO",
checkDeviceConnectionResult);
//this._logger?.LogTrace("CheckDeviceConnection. {0} ROW: {1}", checkDeviceConnectionResult ? "OK" : "KO", checkDeviceConnectionResult);
return checkDeviceConnectionResult;
}

Expand All @@ -441,9 +440,7 @@ public bool CheckDeviceConnection()
try
{
generalInf = Marshal.PtrToStructure<GeneralInf>(pointer);
this._logger?.LogTrace("GetDeviceGeneralInf: Name: {0} Type: {1} CPU: {2}", generalInf.Value.Name,
generalInf.Value.Type,
generalInf.Value.Cpu);
//this._logger?.LogTrace("GetDeviceGeneralInf: Name: {0} Type: {1} CPU: {2}", generalInf.Value.Name, generalInf.Value.Type, generalInf.Value.Cpu);
}
catch (Exception ex)
{
Expand Down Expand Up @@ -538,7 +535,7 @@ public CubeProgrammerError DownloadFile(string inputFilePath, string address, ui
var filePathAdapted = String.IsNullOrEmpty(filePath) ? "" : filePath.Replace(@"\", "/");
var binPathAdapted = String.IsNullOrEmpty(binPath) ? "" : binPath.Replace(@"\", "/");

this._logger?.LogTrace("DownloadFile: {0} - {1}", filePathAdapted, binPathAdapted);
//this._logger?.LogTrace("DownloadFile: {0} - {1}", filePathAdapted, binPathAdapted);

try
{
Expand All @@ -551,8 +548,7 @@ public CubeProgrammerError DownloadFile(string inputFilePath, string address, ui
);
//_logger?.LogTrace("DownloadFile result: {0}", downloadFileResult);
output = this.CheckResult(downloadFileResult);
this._logger?.LogTrace("DownloadFile filePathAdapted: {0} binPathAdapted: {1} downloadFileResult: {2}",
filePathAdapted, binPathAdapted, output);
//this._logger?.LogTrace("DownloadFile filePathAdapted: {0} binPathAdapted: {1} downloadFileResult: {2}", filePathAdapted, binPathAdapted, output);
}
catch (Exception ex)
{
Expand All @@ -573,7 +569,7 @@ public CubeProgrammerError Execute(string address)
var executeResult = Native.ProgrammerApi.Execute(uintAddress);

output = this.CheckResult(executeResult);
this._logger?.LogTrace("Execute address: {0} result: {1}", address, output);
//this._logger?.LogTrace("Execute address: {0} result: {1}", address, output);
}
catch (Exception ex)
{
Expand All @@ -589,7 +585,7 @@ public CubeProgrammerError MassErase(string sFlashMemName = "")
var massEraseResult = Native.ProgrammerApi.MassErase(sFlashMemName);
var output = this.CheckResult(massEraseResult);

this._logger?.LogTrace("MassErase flash mem name: {0} result: {1}", sFlashMemName, output);
//this._logger?.LogTrace("MassErase flash mem name: {0} result: {1}", sFlashMemName, output);

return output;
}
Expand All @@ -600,7 +596,7 @@ public CubeProgrammerError SectorErase(uint[] sectors, uint sectorNbr, string sF
var sectorEraseResult = Native.ProgrammerApi.SectorErase(sectors, sectorNbr, sFlashMemName);
var output = this.CheckResult(sectorEraseResult);

this._logger?.LogTrace("SectorErase sectors: {0}, sectors number: {1}, flash mem name: {2}, result: {3}", sectors, sectorNbr, sFlashMemName, output);
//this._logger?.LogTrace("SectorErase sectors: {0}, sectors number: {1}, flash mem name: {2}, result: {3}", sectors, sectorNbr, sFlashMemName, output);

return output;
}
Expand Down Expand Up @@ -640,7 +636,7 @@ public void GetCancelPointer()
if (!String.IsNullOrEmpty(filePath))
{
var filePathAdapted = filePath.Replace(@"\", "/");
this._logger?.LogTrace("File Open: {0}", filePathAdapted);
//this._logger?.LogTrace("File Open: {0}", filePathAdapted);

var filePointer = Native.ProgrammerApi.FileOpen(filePathAdapted);

Expand Down Expand Up @@ -691,7 +687,7 @@ public void FreeFileData()
public CubeProgrammerError Verify(byte[] data, string address)
{
var uintAddress = this.HexConverterToUint(address);
this._logger?.LogTrace("Verify address: {0}", uintAddress);
//this._logger?.LogTrace("Verify address: {0}", uintAddress);

var gch = GCHandle.Alloc(data, GCHandleType.Pinned);

Expand Down Expand Up @@ -769,8 +765,7 @@ public CubeProgrammerError SaveMemoryToFile(string address, string size, string

output = this.CheckResult(saveMemoryToFileResult);

this._logger?.LogTrace("SaveMemoryToFile address: {0} size: {1} file name: {2} result: {3}", intAddress,
intSize, fileName, output);
//this._logger?.LogTrace("SaveMemoryToFile address: {0} size: {1} file name: {2} result: {3}", intAddress, intSize, fileName, output);
}
catch (Exception ex)
{
Expand All @@ -783,7 +778,7 @@ public CubeProgrammerError SaveMemoryToFile(string address, string size, string
/// <inheritdoc />
public CubeProgrammerError Disconnect()
{
this._logger?.LogTrace("Disconnect. ");
//this._logger?.LogTrace("Disconnect. ");
var result = Native.ProgrammerApi.Disconnect();

var output = this.CheckResult(result);
Expand All @@ -794,7 +789,7 @@ public CubeProgrammerError Disconnect()
/// <inheritdoc />
public void DeleteInterfaceList()
{
this._logger?.LogTrace(" DeleteInterfaceList. ");
//this._logger?.LogTrace(" DeleteInterfaceList. ");
Native.ProgrammerApi.DeleteInterfaceList();
}

Expand Down Expand Up @@ -862,7 +857,7 @@ public CubeProgrammerError SendOptionBytesCmd(string command)
/// <inheritdoc />
public PeripheralC? InitOptionBytesInterface()
{
this._logger?.LogTrace("InitOptionBytesInterface.");
//this._logger?.LogTrace("InitOptionBytesInterface.");
PeripheralC? peripheralC = null;

var pointer = Native.ProgrammerApi.InitOptionBytesInterface();
Expand All @@ -888,7 +883,7 @@ public CubeProgrammerError SendOptionBytesCmd(string command)
/// <inheritdoc />
public PeripheralC? FastRomInitOptionBytesInterface(ushort deviceId)
{
this._logger?.LogTrace("FastRomInitOptionBytesInterface.");
//this._logger?.LogTrace("FastRomInitOptionBytesInterface.");
PeripheralC? peripheralC = null;

var pointer = Native.ProgrammerApi.FastRomInitOptionBytesInterface(deviceId);
Expand Down Expand Up @@ -1153,7 +1148,7 @@ private CubeProgrammerError CheckResult(int result)

protected void OnStLinksFoundStatus()
{
this._logger?.LogTrace("OnStLinkFoundStatus");
//this._logger?.LogTrace("OnStLinkFoundStatus");
try
{
this.StLinksFoundStatus?.Invoke(this, new StLinkFoundEventArgs());
Expand All @@ -1166,7 +1161,7 @@ protected void OnStLinksFoundStatus()

protected void OnStLinkAdded()
{
this._logger?.LogTrace("OnStLinkAdded");
//this._logger?.LogTrace("OnStLinkAdded");
try
{
this.StLinkAdded?.Invoke(this, new StLinkAddedEventArgs());
Expand All @@ -1179,7 +1174,7 @@ protected void OnStLinkAdded()

protected void OnStLinkRemoved()
{
this._logger?.LogTrace("OnStLinkRemoved");
//this._logger?.LogTrace("OnStLinkRemoved");
try
{
this.StLinkRemoved?.Invoke(this, new StLinkRemovedEventArgs());
Expand All @@ -1192,7 +1187,7 @@ protected void OnStLinkRemoved()

protected void OnStm32BootLoadersFoundStatus()
{
this._logger?.LogTrace("OnStm32BootLoadersFoundStatus");
//this._logger?.LogTrace("OnStm32BootLoadersFoundStatus");
try
{
this.Stm32BootLoaderFoundStatus?.Invoke(this, new Stm32BootLoaderFoundEventArgs());
Expand All @@ -1205,7 +1200,7 @@ protected void OnStm32BootLoadersFoundStatus()

protected void OnStm32BootLoaderAdded()
{
this._logger?.LogTrace("OnStm32BootLoaderAdded");
//this._logger?.LogTrace("OnStm32BootLoaderAdded");
try
{
this.Stm32BootLoaderAdded?.Invoke(this, new Stm32BootLoaderAddedEventArgs());
Expand All @@ -1218,7 +1213,7 @@ protected void OnStm32BootLoaderAdded()

protected void OnStm32BootLoaderRemoved()
{
this._logger?.LogTrace("OnStm32BootLoaderRemoved");
//this._logger?.LogTrace("OnStm32BootLoaderRemoved");
try
{
this.Stm32BootLoaderRemoved?.Invoke(this, new Stm32BootLoaderRemovedEventArgs());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
</ItemGroup>

<ItemGroup>
<None Include="..\..\..\build\Programmer\bin\x64\$(Configuration)\*.dll" Pack="true" PackagePath="build\native\x64\Programmer" Visible="false" Link="dll\x64\%(FileName)%(Extension)" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="PreserveNewest">

</None>
<None Include="..\..\..\build\Programmer\bin\Win32\$(Configuration)\*.dll" Pack="true" PackagePath="build\native\x86\Programmer" Visible="false" Link="dll\x86\%(FileName)%(Extension)" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="PreserveNewest">

</None>
<None Include="..\..\..\Programmer\version" Pack="true" PackagePath="build\native\Programmer" Visible="false" Link="dll\version" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="PreserveNewest">

</None>
Expand All @@ -34,18 +40,12 @@
</None>
<None Include="..\..\..\Programmer\x64\STLinkUSBDriver.dll" Pack="true" PackagePath="build\native\x64" Visible="false" Link="dll\x64\STLinkUSBDriver.dll" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="PreserveNewest">

</None>
<None Include="..\..\..\build\Programmer\bin\x64\Release\*.dll" Pack="true" PackagePath="build\native\x64\Programmer" Visible="false" Link="dll\x64\%(FileName)%(Extension)" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="PreserveNewest">

</None>
<None Include="..\..\..\Programmer\x86\*.dll" Pack="true" PackagePath="build\native\x86\Programmer" Visible="false" Exclude="**\STLinkUSBDriver.dll" Link="dll\x86\%(FileName)%(Extension)" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="PreserveNewest">

</None>
<None Include="..\..\..\Programmer\x86\STLinkUSBDriver.dll" Pack="true" PackagePath="build\native\x86" Visible="false" Link="dll\x86\STLinkUSBDriver.dll" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="PreserveNewest">

</None>
<None Include="..\..\..\build\Programmer\bin\Win32\Release\*.dll" Pack="true" PackagePath="build\native\x86\Programmer" Visible="false" Link="dll\x86\%(FileName)%(Extension)" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="PreserveNewest">

</None>
<None Include="..\..\..\Data_Base\*.*" Pack="true" PackagePath="contentFiles\any\any\st\Data_Base" Visible="false" Link="st\Data_Base\%(FileName)%(Extension)" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="PreserveNewest">
<PackageCopyToOutput>true</PackageCopyToOutput>
Expand Down
Loading

0 comments on commit 785c8ac

Please sign in to comment.