diff --git a/.gitignore b/.gitignore
index 89f3131..92e7de6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -371,6 +371,7 @@ Visual Studio 2022/
Visual Studio 2022Templates/
Test/
src/01/Samples/Dojo/
+src/01/Samples/DFU/
src/01/KSociety.ProgrammerTerminal
KSociety.Dojo.sln
KSociety.ProgrammerTerminal.sln
\ No newline at end of file
diff --git a/KSociety.SharpCubeProgrammer.sln b/KSociety.SharpCubeProgrammer.sln
index 3d07d66..2cefc2f 100644
--- a/KSociety.SharpCubeProgrammer.sln
+++ b/KSociety.SharpCubeProgrammer.sln
@@ -82,7 +82,6 @@ Global
{8709E86A-F53A-4CED-B485-5D8A40FE9CCA}.Debug|Any CPU.ActiveCfg = Debug|x64
{8709E86A-F53A-4CED-B485-5D8A40FE9CCA}.Debug|Any CPU.Build.0 = Debug|x64
{8709E86A-F53A-4CED-B485-5D8A40FE9CCA}.Debug|x64.ActiveCfg = Debug|x64
- {8709E86A-F53A-4CED-B485-5D8A40FE9CCA}.Debug|x64.Build.0 = Debug|x64
{8709E86A-F53A-4CED-B485-5D8A40FE9CCA}.Debug|x86.ActiveCfg = Debug|Win32
{8709E86A-F53A-4CED-B485-5D8A40FE9CCA}.Debug|x86.Build.0 = Debug|Win32
{8709E86A-F53A-4CED-B485-5D8A40FE9CCA}.Release|Any CPU.ActiveCfg = Release|Win32
diff --git a/src/01/KSociety.SharpCubeProgrammer/CubeProgrammerApi.cs b/src/01/KSociety.SharpCubeProgrammer/CubeProgrammerApi.cs
index 9a3c874..66a13c9 100644
--- a/src/01/KSociety.SharpCubeProgrammer/CubeProgrammerApi.cs
+++ b/src/01/KSociety.SharpCubeProgrammer/CubeProgrammerApi.cs
@@ -7,6 +7,7 @@ namespace SharpCubeProgrammer
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
+ using System.Reflection;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
@@ -53,7 +54,9 @@ private void Init()
{
if (this._handle == null)
{
- this._handle = Native.Utility.LoadNativeLibrary(Environment.Is64BitProcess ? @".\dll\x64\STLinkUSBDriver.dll" : @".\dll\x86\STLinkUSBDriver.dll", IntPtr.Zero, 0);
+ var currentDirectory = GetAssemblyDirectory();
+
+ this._handle = Native.Utility.LoadNativeLibrary(Environment.Is64BitProcess ? currentDirectory + @".\dll\x64\STLinkUSBDriver.dll" : currentDirectory + @".\dll\x86\STLinkUSBDriver.dll", IntPtr.Zero, 0);
if (this._handle.IsInvalid)
{
@@ -71,6 +74,14 @@ private void Init()
}
}
+ private static string GetAssemblyDirectory()
+ {
+ var codeBase = Assembly.GetExecutingAssembly().Location;
+ var uri = new UriBuilder(codeBase);
+ var path = Uri.UnescapeDataString(uri.Path);
+ return Path.GetDirectoryName(path);
+ }
+
#region [ST-LINK]
//ST-LINK module groups debug ports JTAG/SWD functions together.
diff --git a/src/01/KSociety.Test/KSociety.Test.csproj b/src/01/KSociety.Test/KSociety.Test.csproj
index ad9b9c9..182b7cb 100644
--- a/src/01/KSociety.Test/KSociety.Test.csproj
+++ b/src/01/KSociety.Test/KSociety.Test.csproj
@@ -13,8 +13,8 @@
-
-
+
+
runtime; build; native; contentfiles; analyzers; buildtransitive
all
diff --git a/src/01/Programmer/Programmer.vcxproj b/src/01/Programmer/Programmer.vcxproj
index 6eab16b..a39e224 100644
--- a/src/01/Programmer/Programmer.vcxproj
+++ b/src/01/Programmer/Programmer.vcxproj
@@ -101,7 +101,7 @@
true
false
$(SolutionDir)Programmer\$(PlatformTarget);%(AdditionalLibraryDirectories)
- CubeProgrammer_API.lib;%(AdditionalDependencies)
+ vcruntimed.lib;ucrtd.lib;CubeProgrammer_API.lib;%(AdditionalDependencies)
@@ -149,13 +149,14 @@
MaxSpeed
%(AdditionalIncludeDirectories)
+ true
Windows
true
false
$(SolutionDir)Programmer\$(PlatformTarget);%(AdditionalLibraryDirectories)
- CubeProgrammer_API.lib;%(AdditionalDependencies)
+ vcruntimed.lib;ucrtd.lib;CubeProgrammer_API.lib;%(AdditionalDependencies)
@@ -225,4 +226,4 @@
-
+
\ No newline at end of file
diff --git a/src/01/Programmer/dllmain.cpp b/src/01/Programmer/dllmain.cpp
index 95ee15a..c83caea 100644
--- a/src/01/Programmer/dllmain.cpp
+++ b/src/01/Programmer/dllmain.cpp
@@ -1,18 +1,47 @@
// dllmain.cpp : Defines the entry point for the DLL application.
#include "pch.h"
-const char* loaderPath = "./st/Programmer";
+const wchar_t* loaderPath = L"st\\Programmer";
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
+ UNREFERENCED_PARAMETER(lpReserved);
+
+ WCHAR dllName[MAX_PATH + 1];
+ DWORD size = 0;
+ int result = 0;
+
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
- /* Set device loaders path that contains FlashLoader and ExternalLoader folders*/
- SetLoadersPath(loaderPath);
+
+ size = GetModuleFileNameW(hModule, dllName, MAX_PATH);
+ if (size > 0)
+ {
+ std::wstring dllNameStr(dllName);
+ std::size_t pos = dllNameStr.size() - 22;
+ dllNameStr = dllNameStr.substr(0, pos);
+ dllNameStr += loaderPath;
+ std::replace(dllNameStr.begin(), dllNameStr.end(), '\\', '/');
+ const wchar_t* input = dllNameStr.c_str();
+
+ // Count required buffer size (plus one for null-terminator).
+ size_t bufferSize = (wcslen(input) + 1) * sizeof(wchar_t);
+ char* buffer = new char[bufferSize];
+
+ size_t convertedSize;
+ wcstombs_s(&convertedSize, buffer, bufferSize, input, bufferSize);
+
+ // Set device loaders path that contains FlashLoader and ExternalLoader folders.
+ SetLoadersPath(buffer);
+
+ delete[] buffer;
+
+ result = 1;
+ }
break;
case DLL_THREAD_ATTACH:
@@ -25,6 +54,10 @@ BOOL APIENTRY DllMain( HMODULE hModule,
break;
}
- return TRUE;
-}
+ if (result == 1)
+ {
+ return TRUE;
+ }
+ return FALSE;
+}
diff --git a/src/01/Programmer/pch.h b/src/01/Programmer/pch.h
index 2bf0f91..442b719 100644
--- a/src/01/Programmer/pch.h
+++ b/src/01/Programmer/pch.h
@@ -10,5 +10,9 @@
// add headers that you want to pre-compile here
#include "framework.h"
#include "Programmer.h"
+#include
+#include
+#include
+#include
#endif //PCH_H
diff --git a/src/01/ProgrammerConsoleApplication/ProgrammerConsoleApplication.cpp b/src/01/ProgrammerConsoleApplication/ProgrammerConsoleApplication.cpp
index 0de6f03..0a890b1 100644
--- a/src/01/ProgrammerConsoleApplication/ProgrammerConsoleApplication.cpp
+++ b/src/01/ProgrammerConsoleApplication/ProgrammerConsoleApplication.cpp
@@ -1,12 +1,50 @@
// ProgrammerConsoleApplication.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
+#include
+#include
+#include
#include
-#include "../Programmer/Programmer.h"
+#include
+#include
+//#include "../Programmer/Programmer.h"
+
+const wchar_t* wide = L"zyxw\\..\\..\\pippo";
int main()
{
- std::cout << "Hello World!\n";
+ WCHAR dllName[MAX_PATH + 1];
+ DWORD size = GetModuleFileNameW(NULL, dllName, MAX_PATH);
+
+ //std::wstring s(dllName);
+
+ //s += std::wstring(ws2);
+
+ std::wstring s(dllName);
+ std::size_t pos = s.size() - 40;
+ s = s.substr(0, pos);
+ s += wide;
+
+ std::replace(s.begin(), s.end(), '\\', '/');
+ const wchar_t* input = s.c_str();
+
+ // Count required buffer size (plus one for null-terminator).
+ size_t size1 = (wcslen(input) + 1) * sizeof(wchar_t);
+ char* buffer = new char[size1];
+
+ #ifdef __STDC_LIB_EXT1__
+ // wcstombs_s is only guaranteed to be available if __STDC_LIB_EXT1__ is defined
+ size_t convertedSize;
+ std::wcstombs_s(&convertedSize, buffer, size, input, size);
+ #else
+ //std::wcstombs(buffer, input, size1);
+ #endif
+
+ size_t convertedSize;
+ wcstombs_s(&convertedSize, buffer, size1, input, size1);
+ delete[] buffer;
+ ;
+ /*std::cout << "Hello World!\n";
debugConnectParameters* stLinkList;
debugConnectParameters debugParameters;
generalInf* genInfo;
@@ -32,21 +70,21 @@ int main()
}
std::cout << "-----------------------------------------------\n\n";
- }
+ }*/
- for (int index = 0; index < getStlinkListNb; index++) {
+ //for (int index = 0; index < getStlinkListNb; index++) {
//logMessage(Title, "\n--------------------- ");
//logMessage(Title, "\n ST-LINK Probe : %d ", index);
//logMessage(Title, "\n--------------------- \n\n");
- debugParameters = stLinkList[index];
+ /*debugParameters = stLinkList[index];
debugParameters.connectionMode = UNDER_RESET_MODE;
- debugParameters.shared = 0;
+ debugParameters.shared = 0;*/
//debugParameters.speed = 1;
/* Target connect */
- int connectStlinkFlag = ConnectStLink(debugParameters);
+ /*int connectStlinkFlag = ConnectStLink(debugParameters);
if (connectStlinkFlag != 0) {
std::cout << "Establishing connection with the device failed: " << connectStlinkFlag << " \n" << std::endl;
Disconnect();
@@ -54,25 +92,25 @@ int main()
}
else {
std::cout << "\n--- Device Connected --- \n" ;
- }
+ }*/
/* Display device informations */
- genInfo = GetDeviceGeneralInf();
+ /*genInfo = GetDeviceGeneralInf();
std::cout << "\nDevice name: " << genInfo->name << std::endl;
std::cout << "\nDevice type: " << genInfo->type << std::endl;
- std::cout << "\nDevice CPU : " << genInfo->cpu << std::endl;
+ std::cout << "\nDevice CPU : " << genInfo->cpu << std::endl;*/
/* Read Option bytes from target device memory */
- peripheral_C* ob;
+ /*peripheral_C* ob;
ob = InitOptionBytesInterface();
if (ob == 0)
{
Disconnect();
continue;
- }
+ }*/
/* Display option bytes */
- for (unsigned int i = 0; i < ob->banksNbr; i++)
+ /*for (unsigned int i = 0; i < ob->banksNbr; i++)
{
std::cout << "\nOPTION BYTES BANK: " << i << std::endl;
for (unsigned int j = 0; j < ob->banks[i]->categoriesNbr; j++)
@@ -88,10 +126,10 @@ int main()
}
}
}
- }
- }
+ }*/
+ //}
- Disconnect();
+ //Disconnect();
return 1;
}
diff --git a/src/01/ProgrammerConsoleApplication/ProgrammerConsoleApplication.vcxproj b/src/01/ProgrammerConsoleApplication/ProgrammerConsoleApplication.vcxproj
index d2de37c..fa1954a 100644
--- a/src/01/ProgrammerConsoleApplication/ProgrammerConsoleApplication.vcxproj
+++ b/src/01/ProgrammerConsoleApplication/ProgrammerConsoleApplication.vcxproj
@@ -132,12 +132,6 @@
-
-
- {52455efe-41b6-4c8b-97c0-db796fe725b5}
- false
-
-
diff --git a/src/01/Samples/QuickStart/Program.cs b/src/01/Samples/QuickStart/Program.cs
index 60546ac..63209c0 100644
--- a/src/01/Samples/QuickStart/Program.cs
+++ b/src/01/Samples/QuickStart/Program.cs
@@ -106,7 +106,7 @@ private static void Main(string[] args)
Console.WriteLine("Press a button to exit.");
Console.ReadLine();
}
-
+
private static void ReceiveMessage(int messageType, [MarshalAs(UnmanagedType.LPWStr)] string message)
{
message = Regex.Replace(message, "(?