API: STLink detected but cannot be connected to.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-05-02 6:56 AM - edited ‎2023-11-20 6:41 AM
I want to use the STM32CubeProgrammer C++ API to do high-speed real-time automated debugging (i.e. use it as an oscilloscope).
I used as a basis the Example_2 given in the API's documentation. The STLink is detected since I can get info from it which I confirmed with the CubeProgrammer. However, when I try to connect to it the connectStLink function returns the value -545 (see the screenshot). I have tried to change various parameters for the past two days with no effect, I am at a complete loss. Here is my very simple code:
Thank you for your help.
#include <DisplayManager.h>
#include <stdio.h>
#include <iostream>
#include <CubeProgrammer_API.h>
void initProgBar() {
std::cout << "initProgBar";
}
void MylogMessage(int msgType, const wchar_t* str) {}
void loadBar(int x, int n) {}
int main() {
debugConnectParameters *stLinkList;
debugConnectParameters debugParameters;
generalInf* genInfo;
displayCallBacks dc;
dc.initProgressBar = initProgBar;
dc.logMessage = MylogMessage;
dc.loadBar = loadBar;
setDisplayCallbacks(dc);
int getStlinkListNb = getStLinkList(&stLinkList, 0);
if (getStlinkListNb == 0)
{
logMessage(Error, "No STLINK available\n");
return 0;
}
else {
logMessage(Title, "\n-------- Connected ST-LINK Probes List --------");
for (int i = 0; i < getStlinkListNb; i++)
{
logMessage(Normal, "\nST-LINK Probe %d :\n", i);
logMessage(Info, " ST-LINK SN : %s \n", stLinkList[i].serialNumber);
logMessage(Info, " ST-LINK FW : %s \n", stLinkList[i].firmwareVersion);
}
logMessage(Title, "-----------------------------------------------\n\n");
}
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.connectionMode = HOTPLUG_MODE;
debugParameters.resetMode = SOFTWARE_RESET;
/* Target connect */
int connectStlinkFlag = connectStLink(debugParameters);
if (connectStlinkFlag != 0) {
logMessage(Error, "Establishing connection with the device failed. Return value: %d\n", connectStlinkFlag);
disconnect();
continue;
}
else {
logMessage(GreenInfo, "\n--- Device %d Connected --- \n", index);
}
/* Display device informations */
genInfo = getDeviceGeneralInf();
logMessage(Normal, "\nDevice name : %s ", genInfo->name);
logMessage(Normal, "\nDevice type : %s ", genInfo->type);
logMessage(Normal, "\nDevice CPU : %s \n", genInfo->cpu);
}
deleteInterfaceList();
return 1;
}
- Labels:
-
STM32CubeProgrammer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-05-03 8:02 AM
Perhaps function connectStLink(debugParameters) uses as parameter pointer instead value. Try pass address like this:
​connectStLink(&debugParameters)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-05-03 8:30 AM
I already tried but it gives me a compilation error. No surprise there the documentation clearly indicates what type the arguments must be.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-05-03 8:33 AM
OK. I saw it in other code. Have you link to documentation? What's mean 545?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-05-03 8:54 AM
The doc is provided in CubeProgrammer/api folder.
It says that the function should return 0 if it’s successful and something else if not.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-05-03 9:00 AM
I asked because now I work from phone:)​ Did you try use direct stLinkList[index] instead of local variable?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-05-04 1:20 AM
I tried, but no. Both variables are of the same type (debugConnectParameters) and I checked that the data are copied.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-03-05 8:22 AM
In my case, I was able to solve that problem by setting the path to the parent folder of the FlashLoader and ExternalLoader folders with the setLoadersPath() function before calling other API functions. Those folders are located at /api/lib by default. If that folder also is the working directory, which is the case in the Visual Studio examples, one can simply set the path to "./.".
const char* loaderPath = "./.";
/* Set device loaders path that contains FlashLoader and ExternalLoader folders */
setLoadersPath(loaderPath);
