Skip to main content
AMabi.1
Associate II
May 2, 2023
Question

API: STLink detected but cannot be connected to.

  • May 2, 2023
  • 1 reply
  • 2135 views

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;
}


_legacyfs_online_stmicro_images_0693W00000bjDGPQA2.png

This topic has been closed for replies.

1 reply

Senior III
May 3, 2023

Perhaps function connectStLink(debugParameters) uses as parameter pointer instead value. Try pass address like this:

​connectStLink(&debugParameters)

AMabi.1
AMabi.1Author
Associate II
May 3, 2023

I already tried but it gives me a compilation error. No surprise there the documentation clearly indicates what type the arguments must be.

Senior III
May 3, 2023

OK. I saw it in other code. Have you link to documentation? What's mean 545?