Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experimental #138

Merged
merged 7 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 0 additions & 1 deletion KSociety.SharpCubeProgrammer.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 12 additions & 1 deletion src/01/KSociety.SharpCubeProgrammer/CubeProgrammerApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand All @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions src/01/KSociety.Test/KSociety.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="xunit" Version="2.7.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7">
<PackageReference Include="xunit" Version="2.8.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
34 changes: 30 additions & 4 deletions src/01/Programmer/dllmain.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,45 @@
// 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;

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() - 14;
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;
}

break;

case DLL_THREAD_ATTACH:
Expand All @@ -27,4 +54,3 @@ BOOL APIENTRY DllMain( HMODULE hModule,

return TRUE;
}

4 changes: 4 additions & 0 deletions src/01/Programmer/framework.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
// Windows Header Files
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#include <string>
#include <algorithm>
Original file line number Diff line number Diff line change
@@ -1,12 +1,50 @@
// ProgrammerConsoleApplication.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#include <iostream>
#include "../Programmer/Programmer.h"
#include <stdlib.h>
#include <algorithm>
//#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() - 32;
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;
Expand All @@ -32,47 +70,47 @@ 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();
continue;
}
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++)
Expand All @@ -88,10 +126,10 @@ int main()
}
}
}
}
}
}*/
//}

Disconnect();
//Disconnect();

return 1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,6 @@
<ItemGroup>
<ClCompile Include="ProgrammerConsoleApplication.cpp" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Programmer\Programmer.vcxproj">
<Project>{52455efe-41b6-4c8b-97c0-db796fe725b5}</Project>
<CopyLocalSatelliteAssemblies>false</CopyLocalSatelliteAssemblies>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
Expand Down