cancel
Showing results for 
Search instead for 
Did you mean: 

STVP fails to load \TOOLS.CNF

Maciej Godek
Associate II
Posted on April 26, 2017 at 13:58

Hi,

I've been trying to connect my application through ST-LINK according to the

http://www.st.com/content/ccc/resource/technical/document/user_manual/90/cb/42/ef/2e/53/46/75/CD00060186.pdf/files/CD00060186.pdf/jcr:content/translations/en.CD00060186.pdf

, but when I invoke

ESelectHard('ST-LINK', 'SWIM', FALSE)

it returns 0, and

CGetLastError

provides the following message:

File \TOOLS.CNF : No such file or directory

The file TOOLS.CNF is clearly present in the same directory as the .dll files that I successfully manage to load (eprcore60.dll, dbca60.dll, lef60.dll and file60.dll).

What is the policy of s

2 REPLIES 2
Maciej Godek
Associate II
Posted on April 26, 2017 at 14:02

I accidentally sent the incomplete question and can't find a way to edit it.

I wanted to ask, what is the policy of searching for the .cnf files in the file60.dll -- are the paths hard coded, or are they relative to the dll files, or can their path be set somehow?

I enclose the complete source code of my attempts below:

#include 'stdafx.h'

#include <windows.h>

#include <conio.h>

#ifndef MAX_PATH

#define MAX_PATH 260

#endif // MAX_PATH

using namespace std;

#define WARN(msg, ...) fprintf(stderr, msg '\n', ## __VA_ARGS__)

#define WWARN(wmsg, ...) fwprintf(stderr, wmsg L'\n', ## __VA_ARGS__)

typedef int(*EAllAccess_t)(DWORD dwAreaId);

typedef int(*EAreaAccess_t)(DWORD dwAreaId, long FirstAddr, long LastAddr);

int(*ESelectDevice)(const char *szDevice);

int (*ESelectHard)(const char *szCard, const char *szProtocol, BOOL bDemo);

int(*ESelectPort)(const char *szPort);

int(*ESetPreferences)(int iPreference, BOOL bState);

int(*ESetProtection)(const char *szProtectMode, BOOL bState);

int(*ECheckSum)(DWORD dwAreaId, long *FileCheckSum, long *MemoryCheckSum);

int (*EGetId)(const char *szName, DWORD *pdwId);

char *(*EGetImagePtr)(DWORD dwAreaId, long *MemSize);

int(*ECloseComm)();

char *(*CGetLastError)() = NULL;

char *LastErrorMessage()

{

    if (CGetLastError)

    {

        return CGetLastError();

    }

    return 'unknown error';

}

#define TRY(action) if(!(action)) { WARN(# action ' failed: %s', LastErrorMessage()); return; }

EAllAccess_t EBlankAll;

EAreaAccess_t EBlankArea;

EAllAccess_t EEraseAll;

EAreaAccess_t EEraseArea;

EAllAccess_t EProgAll;

EAreaAccess_t EProgArea;

//EAllAccess_t EReadAll;

EAreaAccess_t EReadArea;

EAllAccess_t EVerifyAll;

EAreaAccess_t EVerifyArea;

void LoadLibraries()

{

    HINSTANCE eprcore, dbca, lef, file;

    TRY(eprcore = LoadLibrary(L'eprcore60.dll'));

    TRY(dbca = LoadLibrary(L'dbca60.dll'));

    TRY(lef = LoadLibrary(L'lef60.dll'));

    TRY(file = LoadLibrary(L'file60.dll'));

    TRY(CGetLastError = (char *(*)()) GetProcAddress(dbca, 'CGetLastError'));

    TRY(ESelectPort = (int(*)(const char *))GetProcAddress(eprcore, 'ESelectPort'));

    //TRY(EReadAll = (EAllAccess_t)GetProcAddress(eprcore, 'EReadAll'));

    TRY(ESelectHard = (int(*)(const char *, const char *, BOOL)) GetProcAddress(eprcore, 'ESelectHard'));

    TRY(EReadArea = (EAreaAccess_t)GetProcAddress(eprcore, 'EReadArea'));

    TRY(EVerifyAll = (EAllAccess_t)GetProcAddress(eprcore, 'EVerifyAll'));

    TRY(EVerifyArea = (EAreaAccess_t)GetProcAddress(eprcore, 'EVerifyArea'));

    TRY(EProgAll = (EAllAccess_t)GetProcAddress(eprcore, 'EProgAll'));

    TRY(EProgArea = (EAreaAccess_t)GetProcAddress(eprcore, 'EProgArea'));

    TRY(EEraseAll = (EAllAccess_t)GetProcAddress(eprcore, 'EEraseAll'));

    TRY(EEraseArea = (EAreaAccess_t)GetProcAddress(eprcore, 'EEraseArea'));

    TRY(EBlankAll = (EAllAccess_t)GetProcAddress(eprcore, 'EBlankAll'));

    TRY(EBlankArea = (EAreaAccess_t)GetProcAddress(eprcore, 'EBlankArea'));

}

void ReadMemory()

{

    DWORD PROGRAM_MEMORY, DATA_MEMORY;

    TRY(ESelectHard('ST-LINK', 'SWIM', FALSE));

    TRY(ESelectDevice('STM8L15xC6'));

    TRY(ESelectPort('USB'));

    TRY(EGetId('PROGRAM MEMORY', &PROGRAM_MEMORY));

    TRY(EGetId('DATA MEMORY', &DATA_MEMORY));

    WARN('PROGRAM MEMORY = %d, DATA MEMORY = %d', PROGRAM_MEMORY, DATA_MEMORY);

}

int main()

{

    TCHAR pwd[MAX_PATH];

    _wgetcwd(pwd, MAX_PATH);

    WWARN(L'Current Working Directory: %s\n', pwd);

    SetDllDirectory(L'C:\\st_toolset\\stvp');

    LoadLibraries();

    ReadMemory();

    getchar();

    return 0;

}

Maciej Godek
Associate II
Posted on April 26, 2017 at 16:19

I managed to solve the problem by invoking the 'CSetWorkingDir' function. Sorry for the noise.